My app includes an audio player that uses AVAudio to play audio files from the iPod music library. I'd like to add a pitch-shifting feature to the player, and the pitch-shifting libraries I've looked at would require writing a new player using a different audio framework.
I'm currently using an AVAudioMix to change the volume in my player, and I noticed that one of the audio input parameters is audioTimePitchAlgorithm, with a constant AVAudioTimePitchAlgorithmSpectral that looks like what I need. The documentation says it supports a variable rate from 1/32 to 32. But I can't figure out how to set that rate.
Here's the code I have so far (based on this SO answer) with an indication of the missing piece:
AVPlayer *player = self.audioPlayer;
NSArray *audioTracks = [player.currentItem.asset tracksWithMediaType:AVMediaTypeAudio];
NSMutableArray *allAudioParams = [NSMutableArray array];
for (AVAssetTrack *track in audioTracks) {
AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters];
audioInputParams.audioTimePitchAlgorithm = AVAudioTimePitchAlgorithmSpectral;
audioInputParams.audioTimePitchRate = 0.5; <-- NEED SOMETHING LIKE THIS
audioInputParams.trackID = [track trackID];
[allAudioParams addObject:audioInputParams];
}
AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
[audioMix setInputParameters:allAudioParams];
[player.currentItem setAudioMix:audioMix];
I've searched Google, the dev forums, the AVFoundation Programming Guide and the framework header files but found nothing more about this. Does anyone know how this is supposed to work?