1

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?

4

3 に答える 3

0

ドキュメンテーションを誤解しているかもしれません (悪名高い「希望は永遠に湧き出る」効果のため)。AVAudioTimePitchAlgorithmSpectral は、単に「レートを変更してもピッチを維持する場合、これが音楽の場合は非常にうまく機能する」ことを意味します。レートを変更しながらピッチを維持するための 2 つのアルゴリズムがあります。1 つは音声用、もう 1 つは音楽用です。これは「音楽を使う」という意味です。「レートを変えずにピッチを変える」という意味ではありません。AFAICT 組み込みの Cocoa touch フレームワークでは、そのような機能は提供されません。

于 2014-05-28T00:32:21.387 に答える
0

AVPlayer の場合:

プレーヤー アイテムに audioTimePitchAlgorithm を設定し、プレーヤー レートを調整します。

player.playerItem.audioTimePitchAlgorithm = AVAudioTimePitchAlgorithmSpectral;

プレーヤーのレートを変更すると、オーディオのピッチが調整されるようになりました。

これは AVAssetExportSession でも機能するはずです

オーディオを新しいデュレーションにスケーリングすると、オーディオは元のピッチを保持します。

myAVAssetExportSession.audioTimePitchAlgorithm = AVAudioTimePitchAlgorithmSpectral; // (AVAssetExportSession's default algorithm)
于 2015-08-04T16:16:59.467 に答える