2
votes

I want to use AVAudioRecorder to record a sound, and AVAudioPlayer to play it back, at a different pitch.

I've tried changing the rate property of the audio player, which plays the sound faster or slower, but doesn't change the pitch. Is there another way to accomplish this? Can I, for example, record at 22kHz and playback at 44kHz? I tried changing the player's audio settings but they're read-only. Am I missing something simple?

I've looked at different sound libraries, but I would just like a simple hack if there is one.

Thanks!

2

2 Answers

0
votes

Audio Tap Processor is an sample code from Apple that seems change the frequencies. Try the sample app and if it helps you, you could take pieces of code to put together your app.

0
votes

you can use dirac-2 from dsp dimension for pitch shifting on the iphone. quote: -

"DIRAC2 is available as both a commercial object library offering unlimited sample rates and phase locked multichannel support and as a free single channel, 44.1/48kHz LE version."

otherwise for AVAudioPlayer

using setEnableRate: and setRate: will only work with iOS 5.0 and above. so i use respondsToSelector: to test on the device whether or not the device will accept the request:

_noticeAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Rooster-mono" ofType:@"wav"]]
                                                      error:nil];;
if ([_noticeAudio respondsToSelector:@selector(setEnableRate:)])
    _noticeAudio.enableRate = YES;
if ([_noticeAudio respondsToSelector:@selector(setRate:)])
    _noticeAudio.rate = 2.0;