Echo Cancellation
Overview
AEC stands for Acoustic Echo Cancellation. It reduces the speaker signal bleed into the microphone signal. Popular AEC use-cases are telephony/VOIP and karaoke.
Superpowered AEC has unique characteristics:
- Audio quality is not reduced or limited, therefore it's well suited for musical applications.
- Very low latency: just 32 audio samples (example: less than 0.7 milliseconds at 48000 Hz).
It's independent from the built-in hardware, operating system or web browser specific echo canceler, therefore the sound is identical across all and latency is significantly reduced.
Implementation example
AEC expects an input signal and an other signal that should be "removed" from it. The process()
method should be called on every loop of the audio processing block.
class SuperpoweredAECProcessor extends SuperpoweredWebAudio.AudioWorkletProcessor {// Called when the AudioWorklet is ready to start processing audioonReady() {this.aec = new this.Superpowered.AEC();this.monoMicrophoneSignal = new this.Superpowered.Float32Buffer(4096);this.monoSpeakerSignal = new this.Superpowered.Float32Buffer(4096);this.cleanMicrophoneSignal = new this.Superpowered.Float32Buffer(4096);}// Runs before the node is destroyed.// Clean up memory and objects here (such as free allocated linear memory or destruct Superpowered objects).onDestruct() {this.aec.destruct();this.monoMicrophoneSignal.free();this.monoSpeakerSignal.free();this.cleanMicrophoneSignal.free();}// This is the process loop which is passed pointers to buffers// from the WebAudio API (inputBuffer and outputBuffer), with the buffersize (128 samples when running as a native AudioWorklet)processAudio(inputBuffer, outputBuffer, buffersize) {... // some code to produce an output for the speaker, placed into outputBuffer// convert the speaker signal and the microphone signal to monothis.Superpowered.StereoToMono(outputBuffer.pointer, this.monoSpeakerSignal.pointer, 1, 1, 1, 1, buffersize);this.Superpowered.StereoToMono(inputBuffer.pointer, this.monoMicrophoneSignal.pointer, 1, 1, 1, 1, buffersize);// remove the speaker signal from the microphone signalthis.aec.process(this.monoSpeakerSignal.pointer, this.monoMicrophoneSignal.pointer, this.cleanMicrophoneSignal, buffersize);... // do something with the cleaned microphone signal, such as record to disk}}
#include "SuperpoweredAEC.h"#include "SuperpoweredSimple.h"void initialize() {aec = new Superpowered::AEC();monoMicrophoneSignal = malloc(sizeof(float) * 4096);monoSpeakerSignal = malloc(sizeof(float) * 4096);cleanMicrophoneSignal = malloc(sizeof(float) * 4096);}void processAudio(float *interleavedInput, float *interleavedOutput, unsigned int numberOfFrames, unsigned int samplerate) {... // some code to produce an output for the speaker, placed into outputBuffer// convert the speaker signal and the microphone signal to monoSuperpowered::StereoToMono(interleavedOutput, monoSpeakerSignal, 1, 1, 1, 1, numberOfFrames);Superpowered::StereoToMono(interleavedInput, monoMicrophoneSignal, 1, 1, 1, 1, numberOfFrames);// remove the speaker signal from the microphone signalaec->process(monoSpeakerSignal, monoMicrophoneSignal, cleanMicrophoneSignal, numberOfFrames);... // do something with the cleaned microphone signal, such as record to disk}
Properties
distance
PROPERTYType | Min | Max | Default | Superpowered.AEC.MicToSpeakerDistance_Handheld (Telephony, speaker to mic distance is very short (example: mobile phone). Superpowered.AEC.MicToSpeakerDistance_Close (Speaker to mic distance is short, very little room sound (example: studio). Superpowered.AEC.MicToSpeakerDistance_Room (Speaker to mic distance is moderate, the mic picks up some room sound (example: living room). Superpowered.AEC.MicToSpeakerDistance_Large (Speaker to mic distance is large, the mic picks up reverberation (example: large room, hall). | MicToSpeakerDistance_Handheld |
---|
distance
PROPERTYType | Min | Max | Default | Superpowered::AEC::MicToSpeakerDistance_Handheld (Telephony, speaker to mic distance is very short (example: mobile phone). Superpowered::AEC::MicToSpeakerDistance_Close (Speaker to mic distance is short, very little room sound (example: studio). Superpowered::AEC::MicToSpeakerDistance_Room (Speaker to mic distance is moderate, the mic picks up some room sound (example: living room). Superpowered::AEC::MicToSpeakerDistance_Large (Speaker to mic distance is large, the mic picks up reverberation (example: large room, hall). | MicToSpeakerDistance_Handheld |
---|
doubleTalkSensitivity
PROPERTYSensitivity for (double) talk detection.
Type | Min | Max | Default | Number | 0 (always adapt) | 1 | 0.5 |
---|
doubleTalkSensitivity
PROPERTYSensitivity for (double) talk detection.
Type | Min | Max | Default | float | 0 (always adapt) | 1 | 0.5 |
---|
qualityVsQuickAdapt
PROPERTYTrade-off between audio quality and how quickly AEC adapts to a changing environment (such as moving away from the microphone).
Type | Min | Max | Default | Number | 0.1 (high quality, slow adaptation) | 1 (lower quality, quick adaptation) | 0.5 |
---|
qualityVsQuickAdapt
PROPERTYTrade-off between audio quality and how quickly AEC adapts to a changing environment (such as moving away from the microphone).
Type | Min | Max | Default | float | 0.1 (high quality, slow adaptation) | 1 (lower quality, quick adaptation) | 0.5 |
---|
samplerate
PROPERTYInput/output sample rate.
Type | Min | Max | Default | Number | 48000 |
---|
samplerate
PROPERTYInput/output sample rate.
Type | Min | Max | Default | unsigned int | 48000 |
---|
Methods
constructor
METHODCreates an instance of the AEC class.ParametersNoneReturnsType Description Superpowered.AEC
The constructed instance. constructor
METHODCreates an instance of the AEC class.ParametersNoneReturnsType Description Superpowered::AEC
The constructed instance. destruct
METHODDestructor to free Linear Memory.ParametersNoneReturnsNoneprocess
METHODProcesses the audio. It's never blocking for real-time usage. Simplified explanation: output = mic - loudspeaker.ParametersReturnsName Type Description loudspeaker Number (pointer in Linear Memory)
32-bit mono audio, typically sent to the speaker/headset. AEC will remove this signal from the mic signal. VOIP: the "far" signal, audio incoming from the network. Karaoke: the backing track. mic Number (pointer in Linear Memory)
32-bit mono microphone input that should be cleaned (VOIP: "near" signal). output Number (pointer in Linear Memory)
32-bit mono output. The "cleaned" mic audio. numberOfFrames Number
Number of frames to process. Noneprocess
METHODProcesses the audio. It's never blocking for real-time usage. Simplified explanation: output = mic - loudspeaker.ParametersReturnsName Type Default Description loudspeaker float *
32-bit mono audio, typically sent to the speaker/headset. AEC will remove this signal from the mic signal. VOIP: the "far" signal, audio incoming from the network. Karaoke: the backing track. mic float *
32-bit mono microphone input that should be cleaned (VOIP: "near" signal). output float *
32-bit mono output. The "cleaned" mic audio. numberOfFrames unsigned int
Number of frames to process. None