Error/Crash on AVAudioInputNode.setVoiceProcessingEnabled

I'm getting an error/crash when I attempt to call AVAudioIONode.setVoiceProcessing(true) on an AVAudioInputNode object. It's a different error depending on what code I'm calling it on. In the Spoken Word demo, I call it after I set the AudioSession active and set categories:


let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(.record, mode: .measurement, options: .duckOthers)
try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
let inputNode = audioEngine.inputNode
try inputNode.setVoiceProcessingEnabled(true)


Which results in a crash/error:

AVAEInternal.h:76 required condition is false: [AVAEGraphNode.mm:823:CreateRecordingTap: (IsFormatSampleRateAndChannelCountValid(format))]

Elsewhere, in my own app, I get a non-crashing, different error that prints in the console seemingly every time the node's tap buffers:

AUBuffer.h:61:GetBufferList: EXCEPTION (-1) [mPtrState == kPtrsInvalid is false]: ""


Any ideas what these mean? If there some limitation of this function that has to do with buffer/sizes taps? The Using Voice Processing example calls this function with no errors, but I can't tell what that app is doing differently, apart from being more specific about file formats.

Replies

In case someone is still looking for this error: in my case it was happening on iOS 13.5 (but not under Catalyst) because I had two competing remote audio units initialized and running: RemoteIO and VoiceProcessingIO.

Interestingly, echo cancellation worked fine even when I sent my audio via RemoteIO and got mic input via VoiceProcessingIO. However this is the situation when you see repeated exception messages on iOS:

Code Block
AUBuffer.h:61:GetBufferList: EXCEPTION (-1) [mPtrState == kPtrsInvalid is false]: ""


The fix is to use the same instance of VoiceProcessingIO unit for both input and output. In this case though you will get lower quality mono sound on output regardless of what format specification was set on output bus (0).

This doesn't happen on Catalyst though, so may be a bug in iOS CoreAudio. Hope this helps someone.
Post not yet marked as solved Up vote reply of hmel Down vote reply of hmel