开发者

changing the frequency of a soundfile in android

开发者 https://www.devze.com 2023-01-16 09:43 出处:网络
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.

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 n开发者_如何学JAVAext 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?


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号