How to set pitch of an audio file or recorded audio file in iphone sdk?

3 Solutions Collect From Internet About “How to set pitch of an audio file or recorded audio file in iphone sdk?”

The naive approach is to play it using a different sampling rate as compared to the sampling rate used to record the file. For example, if the file was recorded with Fs=44100Hz, then playing it with Fs=22050Hz, will give you half the original pitch.

Of course this naive approach involves changing the duration of the file, and other sound-related artifacts. If you need something less naive, you will have to implement a pitch-shifting algorithm yourself, and that’s a huge topic — I suggest you start by searching pitch shift in google.

You can use the soundtouch open source project to change pitch

Here is the link :

Once you add soundtouch to your project, you have to give the input sound file path, output sound file path and pitch change as the input.

Since it takes more time to process your sound its better to modify soundtouch so that when you record the voice, directly give the data for processing. It will make your application better.


Real-time Pitch Shifting on the iPhone

Create pitch changing code?

you can play sound with changed pitch using AVAudioEngine, AVAudioPlayerNode.The sample tested code is given bellow .

@interface ViewController (){

    AVAudioEngine *engine;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self playAudio];


    engine = [[AVAudioEngine alloc] init];
    NSString* path=[[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp3"];
    NSURL *soundUrl = [NSURL fileURLWithPath:path];
    AVAudioFile* File = [[AVAudioFile alloc] initForReading: soundUrl error: nil];
    AVAudioPlayerNode* node = [AVAudioPlayerNode new];

    [node stop];
    [engine stop];
    [engine reset];
    [engine attachNode: node];
    AVAudioUnitTimePitch* changeAudioUnitTime = [AVAudioUnitTimePitch new];

    //change this rate variable to play fast or slow .         
    changeAudioUnitTime.rate = 1;

    //change pitch variable to according your requirement.
    changeAudioUnitTime.pitch = 100;
    [engine attachNode: changeAudioUnitTime];
    [engine connect:node to: changeAudioUnitTime format: nil];
    [engine connect:changeAudioUnitTime to: engine.outputNode format:nil];
    [node scheduleFile:File atTime: nil completionHandler: nil];
    [engine startAndReturnError: nil];
    [node play];


Make sure path variable have valid file path

Note :: this code is tested on actual device and working fine in my project.don’t forget to add CoreAudio.framework , AVFoundation.framework.