这是我的代码到目前为止,大多是从上面的链接复制.
在AVPlayer设置期间,我为音频处理分配回调函数:
MTAudioProcessingTapCallbacks callbacks;callbacks.version = kMTAudioProcessingTapCallbacksversion_0;callbacks.clIEntInfo = ( voID *)(self);callbacks.init = init;callbacks.prepare = prepare;callbacks.process = process;callbacks.unprepare = unprepare;callbacks.finalize = finalize;MTAudioProcessingTapRef tap;// The create function makes a copy of our callbacks structOsstatus err = MTAudioProcessingTapCreate(kcfAllocatorDefault,&callbacks,kMTAudioProcessingTapCreationFlag_PostEffects,&tap);if (err || !tap) { NSLog(@"Unable to create the Audio Processing Tap"); return;}assert(tap);// Assign the tap to the input parametersaudioinputParam.audioTapProcessor = tap;// Create a new AVAudioMix and assign it to our AVPlayerItemAVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];audioMix.inputParameters = @[audioinputParam];playerItem.audioMix = audioMix;
以下是音频处理功能(实际上是唯一需要处理的功能):
#pragma mark Audio ProcessingvoID init(MTAudioProcessingTapRef tap,voID *clIEntInfo,voID **tapStorageOut) { NSLog(@"Initialising the Audio Tap Processor"); *tapStorageOut = clIEntInfo;}voID finalize(MTAudioProcessingTapRef tap) { NSLog(@"Finalizing the Audio Tap Processor");}voID prepare(MTAudioProcessingTapRef tap,CMItemCount maxFrames,const AudioStreamBasicDescription *processingFormat) { NSLog(@"Preparing the Audio Tap Processor");}voID unprepare(MTAudioProcessingTapRef tap) { NSLog(@"Unpreparing the Audio Tap Processor");}voID process(MTAudioProcessingTapRef tap,CMItemCount numberFrames,MTAudioProcessingTapFlags flags,audiobufferlist *bufferListInOut,CMItemCount *numberFramesOut,MTAudioProcessingTapFlags *flagsOut) { Osstatus err = MTAudioProcessingTapGetSourceAudio(tap,numberFrames,bufferListInOut,flagsOut,NulL,numberFramesOut); if (err) NSLog(@"Error from GetSourceAudio: %ld",err); SIVSVIEwController* self = (SIVSVIEwController*) MTAudioProcessingTapGetStorage(tap); if (self.selectedChannel) { int channel = self.selectedChannel; if (channel == 0) { bufferListInOut->mBuffers[1].mData = bufferListInOut->mBuffers[0].mData; } else { bufferListInOut->mBuffers[0].mData = bufferListInOut->mBuffers[1].mData; } }}总结
以上是内存溢出为你收集整理的ios – AVPlayer播放单声道音频立体声 – >单声道全部内容,希望文章能够帮你解决ios – AVPlayer播放单声道音频立体声 – >单声道所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)