AudioBufferList contents in remoteIO audio unit playback callback

跟風遠走 提交于 2019-12-10 19:11:05

问题


I'd like to "intercept" audio data on its way to the iOS device's speaker. I believe this can be done using remoteIO audio units and callbacks. In the playbackCallback below does ioData actually contain any audio data?

static OSStatus playbackCallback(void *inRefCon, 
                                 AudioUnitRenderActionFlags *ioActionFlags, 
                                 const AudioTimeStamp *inTimeStamp, 
                                 UInt32 inBusNumber, 
                                 UInt32 inNumberFrames, 
                                 AudioBufferList *ioData) { ... } 

I'm confused because logging info about ioData seems to imply it contains audio data...

// if (ioData->mNumberBuffers > 0)
AudioBuffer buffer = ioData->mBuffers[0];
NSLog(@"buffer.mNumberChannels: %ld", buffer.mNumberChannels); // prints 2
NSLog(@"buffer.mDataByteSize  : %ld", buffer.mDataByteSize); // prints 4096

However creating a CMSampleBufferRef from the contents of ioData and writing it to a CoreAudioFile using an AVAssetWriter yields a silent file. The length of the output file seems fine (a few seconds) but opening the file in Audacity for example shows a flatline.

After reading numerous SO posts and experimenting with lots of remoteIO audio unit sample code I'm starting to wonder if ioData above contains pre-sized but empty buffers that should be populated in the playbackCallback.


回答1:


The ioData buffers in a playCallback are where the callback should put the audio samples you want to play. The buffers do not contain other audio intercepted on its way to the speaker.



来源:https://stackoverflow.com/questions/8145353/audiobufferlist-contents-in-remoteio-audio-unit-playback-callback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!