Skip to main content

Module aec

Module aec 

Source
Expand description

Acoustic echo cancellation: keep the speaker out of the microphone.

Without this, anyone on a laptop without a headset sends the rest of the call back to itself. Processor accepts interleaved playback and microphone PCM from any audio stack. With both capture and playback, Control also wires a playback::Engine directly to capture::Config:

use moq_audio::{aec, Layout};

let mut processor = aec::Processor::new(
    aec::Config::default(),
    aec::Stream::new(48_000, Layout::Stereo),
    aec::Stream::new(48_000, Layout::Mono),
)?;
processor.process_render(&[0.0; 960])?;
let mut microphone = [0.0; 480];
processor.process_capture(&mut microphone)?;

One device control owns one adaptive filter and one playback reference. Its clones can toggle that filter, but only one live microphone can attach to it. A second capture fails explicitly until the first releases its attachment.

With the built-in devices, the work happens in the microphone callback, on 10 ms frames, which adds up to 10 ms of latency to the capture path. Both the echo reference and the microphone are processed there, in that order, which is the ordering the echo model needs.

Structsยง

Config
Echo cancellation settings.
Control
Controls echo cancellation between one playback::Engine and microphone.
Processor
Device-independent acoustic echo processor for interleaved f32 PCM.
Stats
Echo-cancellation measurements, with None for unavailable estimates.
Stream
Format of one interleaved PCM stream processed by echo cancellation.