changing the frequency of a soundfile in android

血红的双手。 提交于 2019-12-02 08:27:17

问题


I try to change the frequency of a single soundfile. I managed to do that in android with the SoundPool thing. But the result sounds really bad. So I stepped about the Fourier Transformation - but I am not sure if this is what I am looking for.

I want to load a single file and change the frequency of that file every time that file is played. So I can create melodies out of one tone. Is that possible with android/java?


This is the way I managed to do it. With "bad" I mean it sounds out of tune.

If I want to play the next frequency of the note in the file I must multiply it by 2^(1/12). But since it's just a float, I guess it's not precise enough to get the "real" frequency of the next note.

Is there a "simple" way to achieve that goal?


回答1:


The simplest way with the SoundPool is to adjust the rate on your call to play():

play(aSoundId, leftVolume, rightVolume, 1, 0, rate);

The rate can vary from .5f to 2.0f, though the extremes typically don't sound great, so you may want to set an acceptable range (e.g., .4f) and a minimum rate (e.g., .85f). Then you can have a variable to control where you are within that range (e.g., a float that ranges between .0f and 1.0f):

float rate = RATE_RANGE * pitch + MINIMUM_RATE;


来源:https://stackoverflow.com/questions/3737636/changing-the-frequency-of-a-soundfile-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!