MacOS echo cancellation (AUVoiceProcessing) trouble with device gain/volume

Hi community

I'm developing an application for MacOS and i need to capture the mic audio stream. Currently using CoreAudio in Swift i'm able to capture the audio stream using IO Procs and have applied the AUVoiceProcessing for prevent echo from speaker device. I was able to connect the audio unit and perform the echo cancellation.

The problem that i'm getting is that when i'm using AUVoiceProcessing the gain of the two devices get reduced and that affects the volume of the two devices (microphone and speaker).

I have tried to disable the AGC using the property kAUVoiceIOProperty_VoiceProcessingEnableAGCbut the results are the same.

There is any option to disable the gain reduction or there is a better approach to get the echo cancellation working?

A slight gain change is expected when enabling voice processing. From the documentation on setVoiceProcessingEnabled(_:):

Voice processing requires both input and output nodes to be in the voice processing mode. Enabling this mode on either of the IO nodes automatically enables it on the other IO node.

When using Core Audio's AudioDeviceIOProc, audio processing must occur in a real-time safe context to ensure glitch-free performance. Don't allocate memory, perform file I/O, take locks, or interact with the Swift or Objective-C runtimes when rendering audio.

If you are using Swift, consider using AVAudioEngine and installing a tap on the engine's input node instead.

I'm trying to solve a similar problem.

AVAudioEngine works just fine on MacOS 14+ with new audio ducking API. However, it is not clear what to do with macOS 13.

I would really appreciate it if you could share a snippet of code on how you achieved echo cancellation.

Hey guys, any updates on the VoiceProcessingUnit ducking issue?

MacOS echo cancellation (AUVoiceProcessing) trouble with device gain/volume
 
 
Q