2017-01-24 57 views
0

當耳機插入iOS設備時,我想直接向揚聲器播放錄製的音頻。AudioUnitRender出錯kAudioUnitErr_CannotDoInCurrentContext(-10863)

我所做的是在AURenderCallback func中調用AudioUnitRender,以便將音頻數據寫入AudioBuffer結構。

如果「IO緩衝區持續時間」未設置或設置爲0.020秒,則可以正常工作。如果「IO的緩存時間」是通過調用setPreferredIOBufferDuration設置爲一個很小的值(0.005等),AudioUnitRender()會返回一個錯誤:

kAudioUnitErr_CannotDoInCurrentContext (-10863).

任何一個可以幫助找出原因,以及如何解決它嗎?謝謝

回答

0

緩衝區已​​滿,因此請等到後續渲染過程或使用較大的緩衝區。

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

+1

問題已通過設置相同的採樣率與其它工作AudioUnit解決。當有多個AudioUnit同時工作時,似乎很難解釋這一點。無論如何,您提供的信息對於瞭解此錯誤代碼的原因非常有幫助。謝謝! – bjzhao