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 audio
onReady() {
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 mono
this.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 signal
this.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 mono
Superpowered::StereoToMono(interleavedOutput, monoSpeakerSignal, 1, 1, 1, 1, numberOfFrames);
Superpowered::StereoToMono(interleavedInput, monoMicrophoneSignal, 1, 1, 1, 1, numberOfFrames);
// remove the speaker signal from the microphone signal
aec->process(monoSpeakerSignal, monoMicrophoneSignal, cleanMicrophoneSignal, numberOfFrames);
... // do something with the cleaned microphone signal, such as record to disk
}

Properties

distance

PROPERTY
TypeMinMaxDefault
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

PROPERTY
TypeMinMaxDefault
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

PROPERTY
Sensitivity for (double) talk detection.
TypeMinMaxDefault
Number
0 (always adapt)10.5

doubleTalkSensitivity

PROPERTY
Sensitivity for (double) talk detection.
TypeMinMaxDefault
float
0 (always adapt)10.5

qualityVsQuickAdapt

PROPERTY
Trade-off between audio quality and how quickly AEC adapts to a changing environment (such as moving away from the microphone).
TypeMinMaxDefault
Number
0.1 (high quality, slow adaptation)1 (lower quality, quick adaptation)0.5

qualityVsQuickAdapt

PROPERTY
Trade-off between audio quality and how quickly AEC adapts to a changing environment (such as moving away from the microphone).
TypeMinMaxDefault
float
0.1 (high quality, slow adaptation)1 (lower quality, quick adaptation)0.5

samplerate

PROPERTY
Input/output sample rate.
TypeMinMaxDefault
Number
48000

samplerate

PROPERTY
Input/output sample rate.
TypeMinMaxDefault
unsigned int
48000

Methods

  • constructor

    METHOD
    Creates an instance of the AEC class.
    Parameters
    None
    Returns
    TypeDescription
    Superpowered.AECThe constructed instance.
  • constructor

    METHOD
    Creates an instance of the AEC class.
    Parameters
    None
    Returns
    TypeDescription
    Superpowered::AECThe constructed instance.
  • destruct

    METHOD
    Destructor to free Linear Memory.
    Parameters
    None
    Returns
    None
  • process

    METHOD
    Processes the audio. It's never blocking for real-time usage. Simplified explanation: output = mic - loudspeaker.
    Parameters
    NameTypeDescription
    loudspeakerNumber (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.
    micNumber (pointer in Linear Memory)32-bit mono microphone input that should be cleaned (VOIP: "near" signal).
    outputNumber (pointer in Linear Memory)32-bit mono output. The "cleaned" mic audio.
    numberOfFramesNumberNumber of frames to process.
    Returns
    None
  • process

    METHOD
    Processes the audio. It's never blocking for real-time usage. Simplified explanation: output = mic - loudspeaker.
    Parameters
    NameTypeDefaultDescription
    loudspeakerfloat *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.
    micfloat *32-bit mono microphone input that should be cleaned (VOIP: "near" signal).
    outputfloat *32-bit mono output. The "cleaned" mic audio.
    numberOfFramesunsigned intNumber of frames to process.
    Returns
    None
v1.0.6