AudioUnitRender 出现错误 kAudioUnitErr_CannotDoInCurrentContext (-10863)

AudioUnitRender got error kAudioUnitErr_CannotDoInCurrentContext (-10863)

我想在耳机插入 iOS 设备时直接向扬声器播放录制的音频。

我所做的是在 AURenderCallback 函数中调用 AudioUnitRender,以便将音频数据写入 AudioBuffer 结构。

如果不设置"IO buffer duration"或设置为0.020秒,效果很好。如果通过调用 setPreferredIOBufferDuration 将 "IO buffer duration" 设置为较小的值(0.005 等),AudioUnitRender() 将 return 出错:

kAudioUnitErr_CannotDoInCurrentContext (-10863).

任何人都可以帮助找出原因以及如何解决它吗?谢谢

缓冲区已满,请等到后续渲染通道或使用更大的缓冲区。

AudioToolbox、AudioUnit 和 AUGraph 使用了相同的错误代码,但仅针对 AUGraph 进行了记录。

To avoid spinning or waiting in the render thread (a bad idea!), many of the calls to AUGraph can return: kAUGraphErr_CannotDoInCurrentContext. This result is only generated when you call an AUGraph API from its render callback. It means that the lock that it required was held at that time, by another thread. If you see this result code, you can generally attempt the action again - typically the NEXT render cycle (so in the mean time the lock can be cleared), or you can delegate that call to another thread in your app. You should not spin or put-to-sleep the render thread.

https://developer.apple.com/reference/audiotoolbox/kaugrapherr_cannotdoincurrentcontext

只是想补充一点,更改输出范围采样率以匹配我使用的 OSx kAudioUnitSubType_HALOutput 音频单元的输入的输入范围采样率为我修复了这个错误