ユーザーに状態の変化を示すために、オーディオ ファイルのピッチを複数回シフトしようとしています。Objective-Cでこれを行う方法がわかりませんでした
それについて議論する質問についてこの記事を見つけましたが、それは迅速なものでした。また、このライブラリで音声ファイルを読み込む方法もわかりませんでした。
このコードを試してみましたが、実行するたびに 3 ~ 4 行目でエラーが発生しました。もう1つは、私がこれに慣れていないため、このライブラリでmp3ファイルをロードする方法がわかりませんでした。誰でも助けてもらえますか?
//This is the file I need to shift its pitch
NSString *path = [NSString stringWithFormat:@"%@/Beep5.mp3", [[NSBundle mainBundle] resourcePath]];
NSURL *soundUrl = [NSURL fileURLWithPath:path];
AVAudioFile *file=[[AVAudioFile alloc] initForReading:soundUrl error:nil];
AVAudioFormat *format=file.processingFormat;
AVAudioFrameCount capacity= (AVAudioFrameCount)file.length;
AVAudioPCMBuffer *buffer=[[AVAudioPCMBuffer alloc] initWithPCMFormat:format frameCapacity:capacity];
[file readIntoBuffer:buffer error:nil];
[playerNode scheduleBuffer:buffer completionHandler:nil];
AVAudioEngine *engine;
AVAudioPlayerNode *playerNode;
//get the error in one of the following two LOC
engine = [[AVAudioPlayerNode alloc] init];
[engine attachNode: playerNode];
AVAudioMixerNode *mixer = engine.mainMixerNode;
AVAudioUnitTimePitch *auTimePitch;
auTimePitch.pitch=1200.0;// In cents. The default value is 1.0. The range of values is -2400 to 2400
auTimePitch.rate = 2.0; //The default value is 1.0. The range of supported values is 1/32 to 32.0.
[engine attachNode: auTimePitch];
[engine connect:playerNode to:auTimePitch format:[mixer outputFormatForBus:0]];
[engine connect:playerNode to:mixer format:[mixer outputFormatForBus:0]];
playerNode.play;