我们正在使用 AudioUnits 输入回调来处理传入的缓冲区。音频单元设置主要取自
https://github.com/robovm/apple-ios-samples/blob/master/aurioTouch/Classes/AudioController.mm
我在音频回调中添加了一些健全性检查。看起来像这样
/// The audio input callback
static OSStatus audioInputCallback(void __unused *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 __unused inBusNumber,
UInt32 inNumberFrames,
AudioBufferList __unused *ioData)
{
OSStatus err = noErr;
if(!*callbackData.audioChainIsBeingReconstructed)
{
// we are calling AudioUnitRender on the input bus of AURemoteIO
// this will store the audio data captured by the microphone in cd.audioBufferList
err = AudioUnitRender(callbackData.audioUnit, ioActionFlags, inTimeStamp, kInputBus, inNumberFrames, &callbackData.audioBufferList);
// check if the sample count is set correctly
assert(callbackData.audioBufferList.mBuffers[0].mDataByteSize == inNumberFrames * sizeof(float));
// Assert that we only received one buffer
assert(callbackData.audioBufferList.mNumberBuffers == 1);
// Copy buffer
TPCircularBufferCopyAudioBufferList(callbackData.buffer, &callbackData.audioBufferList, inTimeStamp, kTPCircularBufferCopyAll, NULL);
}
return err;
}
现在有时语句会assert(callbackData.audioBufferList.mBuffers[0].mDataByteSize == inNumberFrames * sizeof(float));
失败,因为缓冲区不同。
有人对这种现象有解释吗?