RemoteBuffer音频单元回放回调中的AudioBufferList内容 [英] AudioBufferList contents in remoteIO audio unit playback callback
问题描述
我想拦截"音频数据到iOS设备扬声器的途中.我相信可以使用remoteIO音频单元和回调来完成.在下面的playbackCallback中,ioData实际上包含任何音频数据吗?
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) { ... }
我很困惑,因为记录有关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
但是,根据ioData的内容创建CMSampleBufferRef并使用AVAssetWriter将其写入CoreAudioFile会产生静默文件.输出文件的长度似乎不错(几秒钟),但是以Audacity为例打开文件显示的是平线.
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.
在阅读了很多SO文章并尝试了许多remoteIO音频单元示例代码之后,我开始怀疑上面的ioData是否包含应在playbackCallback中填充的预先设置但空的缓冲区.
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.
推荐答案
playCallback中的ioData缓冲区是回调应在其中放置要播放的音频样本的位置.缓冲区不包含在通往扬声器的途中截获的其他音频.
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.
这篇关于RemoteBuffer音频单元回放回调中的AudioBufferList内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!