LiveKit C++ SDK
Real-time audio/video SDK for C++
Loading...
Searching...
No Matches
livekit::AudioProcessingModule Class Reference

WebRTC Audio Processing Module (APM) for real-time audio enhancement. More...

#include <audio_processing_module.h>

Classes

struct  Options
 Configuration options for the Audio Processing Module. More...
 

Public Member Functions

 AudioProcessingModule ()
 Create a new Audio Processing Module with default options (all disabled).
 
 AudioProcessingModule (const Options &options)
 Create a new Audio Processing Module with the specified options.
 
 AudioProcessingModule (const AudioProcessingModule &)=delete
 
AudioProcessingModuleoperator= (const AudioProcessingModule &)=delete
 
 AudioProcessingModule (AudioProcessingModule &&) noexcept=default
 
AudioProcessingModuleoperator= (AudioProcessingModule &&) noexcept=default
 
void processStream (AudioFrame &frame)
 Process the forward (near-end/microphone) audio stream.
 
void processReverseStream (AudioFrame &frame)
 Process the reverse (far-end/speaker) audio stream.
 
void setStreamDelayMs (int delay_ms)
 Set the estimated delay between the reverse and forward streams.
 

Detailed Description

WebRTC Audio Processing Module (APM) for real-time audio enhancement.

AudioProcessingModule exposes WebRTC's built-in audio processing capabilities including echo cancellation, noise suppression, automatic gain control, and high-pass filtering.

This class is designed for scenarios where you need explicit control over audio processing, separate from the built-in processing in AudioSource.

Typical usage pattern for echo cancellation:

  1. Create an APM with desired features enabled
  2. Call processReverseStream() with speaker/playback audio (reference signal)
  3. Call processStream() with microphone audio (near-end signal)
  4. The processed microphone audio will have echo removed

Note: Audio frames must be exactly 10ms in duration.

Constructor & Destructor Documentation

◆ AudioProcessingModule() [1/2]

livekit::AudioProcessingModule::AudioProcessingModule ( )

Create a new Audio Processing Module with default options (all disabled).

Exceptions
std::runtime_errorif the APM could not be created.

◆ AudioProcessingModule() [2/2]

livekit::AudioProcessingModule::AudioProcessingModule ( const Options options)
explicit

Create a new Audio Processing Module with the specified options.

Parameters
optionsConfiguration for which processing features to enable.
Exceptions
std::runtime_errorif the APM could not be created.

Member Function Documentation

◆ processReverseStream()

void livekit::AudioProcessingModule::processReverseStream ( AudioFrame frame)

Process the reverse (far-end/speaker) audio stream.

This method provides the reference signal for echo cancellation. Call this with the audio that is being played through the speakers, so the APM can learn the acoustic characteristics and remove the echo from the microphone signal.

The audio data is modified in-place.

Parameters
frameThe audio frame to process (modified in-place).
Exceptions
std::runtime_errorif processing fails.
Note
The frame must contain exactly 10ms of audio.

◆ processStream()

void livekit::AudioProcessingModule::processStream ( AudioFrame frame)

Process the forward (near-end/microphone) audio stream.

This method processes audio captured from the local microphone. It applies the enabled processing features (noise suppression, gain control, etc.) and removes echo based on the reference signal provided via processReverseStream().

The audio data is modified in-place.

Parameters
frameThe audio frame to process (modified in-place).
Exceptions
std::runtime_errorif processing fails.
Note
The frame must contain exactly 10ms of audio.

◆ setStreamDelayMs()

void livekit::AudioProcessingModule::setStreamDelayMs ( int  delay_ms)

Set the estimated delay between the reverse and forward streams.

This must be called if and only if echo processing is enabled.

Sets the delay in ms between processReverseStream() receiving a far-end frame and processStream() receiving a near-end frame containing the corresponding echo. On the client-side this can be expressed as:

delay = (t_render - t_analyze) + (t_process - t_capture)

where:

  • t_analyze is the time a frame is passed to processReverseStream() and t_render is the time the first sample of the same frame is rendered by the audio hardware.
  • t_capture is the time the first sample of a frame is captured by the audio hardware and t_process is the time the same frame is passed to processStream().
Parameters
delay_msDelay in milliseconds.
Exceptions
std::runtime_errorif setting the delay fails.

The documentation for this class was generated from the following file: