Pitch Shifting is not working on my code

Hi, I'm trying to make simple Pitch Shifting demo using TheAmazingAudioEngine.
i just came from http://forum.theamazingaudioengine.com/discussion/778/how-to-create-a-pitch-shifting-whammy-effect/p1

Here are my code parts to create AEAudioController and control Pitch Shifting.
1. AEAudioController
AEAudioController* audioController;
audioController = [[AEAudioController alloc] initWithAudioDescription:AEAudioStreamBasicDescriptionNonInterleavedFloatStereo inputEnabled:YES];
audioController.preferredBufferDuration = 0.005;
audioController.useMeasurementMode = YES;
[audioController start:NULL];

  1. Play sound
  • (IBAction)actionPlayer:(id)sender{

    filePath = [[NSBundle mainBundle] pathForResource:@heart ofType:@wav];
    if (isPlaying) {
    [audioController removeChannels:@[self.player]];
    self.player = nil;
    [self.imgPlayer setImage:[UIImage imageNamed:@play.png]];
    isPlaying = NO;
    }else{
    NSURL* fileUrl = [NSURL fileURLWithPath:filePath];
    NSError* error = nil;
    self.player = [[AEAudioFilePlayer alloc] initWithURL:fileUrl error:&error];
    if (!self.player) {
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@alert message:@Couldn't open playback preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alert animated:YES completion:nil];
    return;
    }
    self.player.removeUponFinish = YES;
    __weak ViewController* weakSelf = self;
    self.player.completionBlock = ^{
    ViewController* strongSelf = weakSelf;
    [strongSelf.imgPlayer setImage:[UIImage imageNamed:@pause.png]];
    weakSelf.player = nil;
    };
    [audioController addChannels:@[self.player]];
    isPlaying = YES;
    }
    }

  1. Pitch Shifting Mode

- (IBAction)actionPitchSlide:(id)sender{
UISlider* slider = (UISlider*)sender;
float pitchValue = slider.value;
if (pitchValue >= self.pichSlider.maximumValue) {
pitchValue = self.pichSlider.maximumValue;
}
if (pitchValue <= self.pichSlider.minimumValue) {
pitchValue = self.pichSlider.minimumValue;
}
currentPitchValue = pitchValue;
[self.lblPitchValue setText:[NSString stringWithFormat:@%.1f cents,pitchValue]];

AEAudioUnitFilter* pitchFilter = [[AEAudioUnitFilter alloc] initWithComponentDescription:AEAudioComponentDescriptionMake(kAudioUnitManufacturer_Apple, kAudioUnitType_Effect, kAudioUnitSubType_NewTimePitch) preInitializeBlock:nil];
[pitchFilter setupWithAudioController:audioController];
OSStatus status = AudioUnitSetParameter(pitchFilter.audioUnit, kNewTimePitchParam_Pitch, kAudioUnitScope_Global, 0, pitchValue, 0);
if (status == noErr) {
    NSArray* array = audioController.channels;
    id channel = audioController.channels[0];
    [audioController addFilter:pitchFilter];
}

}

Currently I'm using Xcode7.1. Above code is not changing pitch. And it's taking several errors like memory.
There are the log for that:
2016-01-19 13:31:47.776 PitchShift[12942:811774] TAAE: Setting audio session category to AVAudioSessionCategoryPlayAndRecord
2016-01-19 13:31:47.778 PitchShift[12942:811774] TAAE: Audio session initialized (input available, audio route '') HW samplerate: 44100
2016-01-19 13:31:47.790 PitchShift[12942:811774] TAAE: Input status updated (2 channel, non-interleaved)
2016-01-19 13:31:47.831 PitchShift[12942:811774] TAAE: Engine setup
2016-01-19 13:31:47.831 PitchShift[12942:811774] TAAE: Buffer duration 0.0029, 128 frames (requested 0.005s, 221 frames)
2016-01-19 13:31:47.832 PitchShift[12942:811774] TAAE: Starting Engine
2016-01-19 13:32:13.576 PitchShift[12942:811940] TAAE: Warning: render took too long (0.001728s, 59.53% of budget). Expect glitches.
2016-01-19 13:32:14.344 PitchShift[12942:811774] TAAE: Warning: Maximum number of callbacks reached
2016-01-19 13:32:14.366 PitchShift[12942:811774] TAAE: Warning: Maximum number of callbacks reached

2016-01-19 13:32:43.577 PitchShift[12942:811940] TAAE: Warning: render took too long (0.001742s, 60.02% of budget). Expect glitches.

So, i think currently Pitch Shifting engine is not working on my code.
Please help me how can i fix this issue.

Thanks

Alex Adam

Comments

  • Hi Michael
    Can you help me?

  • Hi Alex,

    Try removing this line: [pitchFilter setupWithAudioController:audioController]; and replacing it with this line: [audioController addFilter:pitchFilter]; You can also remove that if statement.

    Check out AENewPitchTimeFilter. It's just a wrapper for this Audio Unit, but it's a bit easier to work with.

Sign In or Register to comment.