AVAudioEngine
can give you pitch, rate, pan and volume control:
self.engine = [[AVAudioEngine alloc] init];
NSError *error;
AVAudioPlayerNode *playerNode = [[AVAudioPlayerNode alloc] init];
AVAudioMixerNode *mixer = [[AVAudioMixerNode alloc] init];
AVAudioUnitVarispeed *varispeed = [[AVAudioUnitVarispeed alloc] init];
[self.engine attachNode:playerNode];
[self.engine attachNode:varispeed];
[self.engine attachNode:mixer];
[self.engine connect:playerNode to:varispeed format:nil];
[self.engine connect:varispeed to:mixer format:nil];
[self.engine connect:mixer to:self.engine.mainMixerNode format:nil];
BOOL result = [self.engine startAndReturnError: &error];
assert(result);
AVAudioFile *audioFile = [[AVAudioFile alloc] initForReading:url error:&error];
assert(audioFile);
// rate & pitch (fused), pan and volume controls
varispeed.rate = 0.5; // half pitch & rate
mixer.pan = -1; // left speaker
mixer.volume = 0.5; // half volume
[playerNode scheduleFile:audioFile atTime:nil completionHandler:nil];
[playerNode play];
If you want separate rate & pitch control, replace the AVAudioUnitVarispeed
node with an AVAudioUnitTimePitch
node.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…