bjzhao
bjzhao

Reputation: 33

AudioUnitRender got error kAudioUnitErr_CannotDoInCurrentContext (-10863)

I want to play the recorded audio directly to speaker when headset is plugged in an iOS device.

What I did is calling AudioUnitRender in AURenderCallback func so that the audio data is writed to AudioBuffer structure.

It works well if the "IO buffer duration" is not set or set to 0.020seconds. If the "IO buffer duration" is set to a small value (0.005 etc.) by calling setPreferredIOBufferDuration, AudioUnitRender() will return an error:

kAudioUnitErr_CannotDoInCurrentContext (-10863).

Any one can help to figure out why and how to resolve it please? Thanks

Upvotes: 3

Views: 1689

Answers (3)

Beckon
Beckon

Reputation: 138

First of all, open micro(Audio input) of mac sandbox please !

Upvotes: 0

soundGuy33
soundGuy33

Reputation: 59

Just wanted to add that changing the output scope sample rate to match the input scope sample rate of the input to the OSx kAudioUnitSubType_HALOutput Audio Unit that I was using fixed this error for me

Upvotes: 6

drawnonward
drawnonward

Reputation: 53659

The buffer is full so wait until a subsequent render pass or use a larger buffer.

This same error code is used by AudioToolbox, AudioUnit and AUGraph but only documented for 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

Upvotes: 1

Related Questions