gpt4 book ai didi

ios - AudioUnit inputCallback with AudioUnitRender -> audioBufferList.mBuffers[0].mDataByteSize != inNumberFrames 之间不匹配

转载 作者:行者123 更新时间:2023-11-28 23:28:16 24 4
gpt4 key购买 nike

我们正在使用 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)); 会失败,因为缓冲区不相同。

有人对这种现象有解释吗?

最佳答案

这是 iOS 上的正常行为。 iOS 音频单元回调可以更改缓冲区大小中提供的帧数,使其与原始缓冲区大小不同。当操作系统状态发生变化时,或者当音频硬件状态发生变化时,或者当可用的硬件格式与您的音频格式请求不完全匹配时,就会发生这种情况。

因此必须编写所有音频单元回调以处理来自请求值或先前回调值的可变数量的 inNumberFrames。

关于ios - AudioUnit inputCallback with AudioUnitRender -> audioBufferList.mBuffers[0].mDataByteSize != inNumberFrames 之间不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57852372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com