具有AudioUnitRender的AudioUnit inputCallback-> audioBufferList.mBuffers [0] .mDataByteSize!= inNumberFrames之间不匹配 [英] AudioUnit inputCallback with AudioUnitRender -> mismatch between audioBufferList.mBuffers[0].mDataByteSize != inNumberFrames

查看:509
本文介绍了具有AudioUnitRender的AudioUnit inputCallback-> audioBufferList.mBuffers [0] .mDataByteSize!= inNumberFrames之间不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用AudioUnits输入回调来处理传入缓冲区.音频单元的设置主要来自

We are using the AudioUnits input callback to process the incoming buffer. The audio unit setup is taken mostly from

https://github.com/robovm/apple-ios-samples/blob/master/aurioTouch/Classes/AudioController.mm

我在音频回调中添加了一些健全性检查.看起来像这样

I have added some sanity check in the audio callback. It looks like this

/// 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));语句失败,因为缓冲区不一样.

Now sometimes the statement assert(callbackData.audioBufferList.mBuffers[0].mDataByteSize == inNumberFrames * sizeof(float)); fails as the buffers are not the same.

有人对此现象有解释吗?

推荐答案

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

This is normal behavior on iOS. An iOS Audio Unit callback can change the number of frames provided in the buffer size, to be different from the original buffer size. This can happen when the OS state changes, or when the audio hardware state changes, or when the hardware format available doesn't exactly match your audio format request.

因此,必须编写所有音频单元回调,以处理来自请求值或上一个回调值的可变数量的inNumberFrames.

So all Audio Unit callbacks must be written to handle a variable number of inNumberFrames from the requested value, or the previous callback value.

这篇关于具有AudioUnitRender的AudioUnit inputCallback-> audioBufferList.mBuffers [0] .mDataByteSize!= inNumberFrames之间不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆