dignifiedquire/sonora

A pure Rust implementation of WebRTC audio processing, providing echo cancellation, noise suppression, and automatic gain control.

77

stars

221

commits

Rust

primary language

Aug 22, 2026

updated

README

Sonora

CI C++ Validation Coverage BSD-3-Clause licensed Rust Version

Pure Rust implementation of WebRTC audio processing, providing echo cancellation, noise suppression, and automatic gain control.

Ported from the WebRTC Native Code (M145) audio processing module.

Crates

CrateDescriptionCrates.ioDocumentation
sonoraFull audio processing pipelinecrates.iodocs.rs
sonora-ffiC API (FFI) for integration with C/C++ projectscrates.iodocs.rs
sonora-aec3Echo Canceller 3 (AEC3)crates.iodocs.rs
sonora-agc2Automatic Gain Control with RNN VADcrates.iodocs.rs
sonora-nsNoise Suppressioncrates.iodocs.rs
sonora-common-audioAudio DSP primitives (resamplers, filters)crates.iodocs.rs
sonora-simdSIMD operations (SSE2, AVX2, NEON)crates.iodocs.rs
sonora-fftFFT implementations (Ooura, PFFFT)crates.iodocs.rs

Features

  • Echo Cancellation (AEC3) -- adaptive filter-based echo canceller with delay estimation
  • Noise Suppression -- Wiener filter-based noise reduction with voice activity detection
  • Automatic Gain Control (AGC2) -- RNN VAD-based gain controller with limiter
  • High-Pass Filter -- DC offset removal
  • C API -- cbindgen-generated C header for FFI integration (via sonora-ffi)

Quick Start

Run the minimal echo cancellation demo:

cargo run -p sonora --example simple

More examples in crates/sonora/examples/:

ExampleDescriptionCommand
simpleSynthetic AEC round-tripcargo run -p sonora --example simple
karaokeMic loopback with echo cancellationcargo run -p sonora --features examples --example karaoke
recordingRecord & process to WAVcargo run -p sonora --features examples --example recording -- --duration 5 --ns --agc

The karaoke and recording examples require the examples feature which pulls in cpal, hound, and other audio I/O dependencies. These examples are based on the tonarino/webrtc-audio-processing examples, ported from PortAudio to cpal.

Supported Platforms

PlatformArchitectureSIMD BackendCI Status
Linux (Ubuntu)x86_64SSE2, AVX2Build, test, clippy, fmt, docs
macOSARM64 (Apple Silicon)NEONBuild, test
Windowsx86_64SSE2, AVX2Build, test
Androidaarch64, armv7, x86_64, i686NEON / SSE2Build, test (via cross)
iOSaarch64NEONBuild, test (via simulator)

Runtime feature detection is used for AVX2 on x86_64. SSE2 is assumed available on all x86_64 targets. NEON is used on AArch64. A scalar fallback is provided for all other architectures.

C++ Integration

The C++ reference test suite (WebRTC M145, 2400+ tests) is validated on Ubuntu x86_64 with the Rust backend linked via the sonora-sys FFI bridge.

Benchmarks

Full pipeline processing a 10 ms frame with AEC3 + noise suppression + AGC2 enabled. Measured on Apple M4 Max (NEON backend), Rust 1.85, -C target-cpu=native:

BenchmarkRustC++Ratio
16 kHz mono4.2 us4.0 us1.07x
48 kHz mono13.3 us10.8 us1.24x

See BENCHMARKS.md for per-component comparisons, profiling breakdown, and instructions for reproducing.

Development

This project uses cargo-make for task automation.

cargo install cargo-make

Quick start

cargo make ci              # Format, lint, test, docs
cargo make bench           # Rust pipeline benchmarks
cargo make check           # Type-check all crates (including excluded)
cargo make clippy          # Lint all crates (including excluded)

C++ comparison (optional)

cargo make setup           # Install system deps + build C++ library
cargo make cpp-bench       # Run Rust vs C++ comparison benchmarks
cargo make cpp-test        # Run comparison tests
cargo make cpp-validate    # Run 2400+ C++ test suite with Rust backend

See Makefile.toml for the full list of tasks.

Minimum Supported Rust Version

The minimum supported Rust version is 1.91.

  • tonarino/webrtc-audio-processing -- Rust bindings to the C++ WebRTC AudioProcessing module. Sonora's examples are based on theirs. If you need the battle-tested C++ implementation with a Rust wrapper, use tonarino; if you want a pure-Rust solution with no C++ dependency, use sonora.
  • pulseaudio-wap -- The original extracted C++ code

History

  1. Google's libwebrtc -- The original AudioProcessing module is developed as part of the WebRTC Native Code project at Google.

  2. PulseAudio's webrtc-audio-processing -- Arun Raghavan and contributors extracted the AudioProcessing module into a standalone library with a Meson build system, making it usable outside of the full WebRTC stack. This packaging is used by PulseAudio, PipeWire, and other Linux audio projects.

  3. M145 upgrade and test expansion -- The C++ codebase was updated to WebRTC M145 (branch-heads/7632), the full upstream test suite (2400+ tests) was ported, and the build was upgraded to C++20. (AI assisted)

  4. Sonora:Rust port -- The C++ implementation was ported to pure Rust, producing this set of crates. The port includes the full SIMD (SSE2, AVX2, NEON) optimizations and the FFTs, as well as a C API for FFI integration. The full C++ test suite passes against this Rust version. (AI assisted)

License

All crates in this repository are licensed under BSD-3-Clause.

Contributors

dignifiedquire

209 commits

dependabot[bot]

11 commits

ford-prefect

1 commits

dignifiedquire/sonora

A pure Rust implementation of WebRTC audio processing, providing echo cancellation, noise suppression, and automatic gain control.

77

stars

221

commits

Rust

primary language

Aug 22, 2026

updated

README

Sonora

CI C++ Validation Coverage BSD-3-Clause licensed Rust Version

Pure Rust implementation of WebRTC audio processing, providing echo cancellation, noise suppression, and automatic gain control.

Ported from the WebRTC Native Code (M145) audio processing module.

Crates

CrateDescriptionCrates.ioDocumentation
sonoraFull audio processing pipelinecrates.iodocs.rs
sonora-ffiC API (FFI) for integration with C/C++ projectscrates.iodocs.rs
sonora-aec3Echo Canceller 3 (AEC3)crates.iodocs.rs
sonora-agc2Automatic Gain Control with RNN VADcrates.iodocs.rs
sonora-nsNoise Suppressioncrates.iodocs.rs
sonora-common-audioAudio DSP primitives (resamplers, filters)crates.iodocs.rs
sonora-simdSIMD operations (SSE2, AVX2, NEON)crates.iodocs.rs
sonora-fftFFT implementations (Ooura, PFFFT)crates.iodocs.rs

Features

  • Echo Cancellation (AEC3) -- adaptive filter-based echo canceller with delay estimation
  • Noise Suppression -- Wiener filter-based noise reduction with voice activity detection
  • Automatic Gain Control (AGC2) -- RNN VAD-based gain controller with limiter
  • High-Pass Filter -- DC offset removal
  • C API -- cbindgen-generated C header for FFI integration (via sonora-ffi)

Quick Start

Run the minimal echo cancellation demo:

cargo run -p sonora --example simple

More examples in crates/sonora/examples/:

ExampleDescriptionCommand
simpleSynthetic AEC round-tripcargo run -p sonora --example simple
karaokeMic loopback with echo cancellationcargo run -p sonora --features examples --example karaoke
recordingRecord & process to WAVcargo run -p sonora --features examples --example recording -- --duration 5 --ns --agc

The karaoke and recording examples require the examples feature which pulls in cpal, hound, and other audio I/O dependencies. These examples are based on the tonarino/webrtc-audio-processing examples, ported from PortAudio to cpal.

Supported Platforms

PlatformArchitectureSIMD BackendCI Status
Linux (Ubuntu)x86_64SSE2, AVX2Build, test, clippy, fmt, docs
macOSARM64 (Apple Silicon)NEONBuild, test
Windowsx86_64SSE2, AVX2Build, test
Androidaarch64, armv7, x86_64, i686NEON / SSE2Build, test (via cross)
iOSaarch64NEONBuild, test (via simulator)

Runtime feature detection is used for AVX2 on x86_64. SSE2 is assumed available on all x86_64 targets. NEON is used on AArch64. A scalar fallback is provided for all other architectures.

C++ Integration

The C++ reference test suite (WebRTC M145, 2400+ tests) is validated on Ubuntu x86_64 with the Rust backend linked via the sonora-sys FFI bridge.

Benchmarks

Full pipeline processing a 10 ms frame with AEC3 + noise suppression + AGC2 enabled. Measured on Apple M4 Max (NEON backend), Rust 1.85, -C target-cpu=native:

BenchmarkRustC++Ratio
16 kHz mono4.2 us4.0 us1.07x
48 kHz mono13.3 us10.8 us1.24x

See BENCHMARKS.md for per-component comparisons, profiling breakdown, and instructions for reproducing.

Development

This project uses cargo-make for task automation.

cargo install cargo-make

Quick start

cargo make ci              # Format, lint, test, docs
cargo make bench           # Rust pipeline benchmarks
cargo make check           # Type-check all crates (including excluded)
cargo make clippy          # Lint all crates (including excluded)

C++ comparison (optional)

cargo make setup           # Install system deps + build C++ library
cargo make cpp-bench       # Run Rust vs C++ comparison benchmarks
cargo make cpp-test        # Run comparison tests
cargo make cpp-validate    # Run 2400+ C++ test suite with Rust backend

See Makefile.toml for the full list of tasks.

Minimum Supported Rust Version

The minimum supported Rust version is 1.91.

  • tonarino/webrtc-audio-processing -- Rust bindings to the C++ WebRTC AudioProcessing module. Sonora's examples are based on theirs. If you need the battle-tested C++ implementation with a Rust wrapper, use tonarino; if you want a pure-Rust solution with no C++ dependency, use sonora.
  • pulseaudio-wap -- The original extracted C++ code

History

  1. Google's libwebrtc -- The original AudioProcessing module is developed as part of the WebRTC Native Code project at Google.

  2. PulseAudio's webrtc-audio-processing -- Arun Raghavan and contributors extracted the AudioProcessing module into a standalone library with a Meson build system, making it usable outside of the full WebRTC stack. This packaging is used by PulseAudio, PipeWire, and other Linux audio projects.

  3. M145 upgrade and test expansion -- The C++ codebase was updated to WebRTC M145 (branch-heads/7632), the full upstream test suite (2400+ tests) was ported, and the build was upgraded to C++20. (AI assisted)

  4. Sonora:Rust port -- The C++ implementation was ported to pure Rust, producing this set of crates. The port includes the full SIMD (SSE2, AVX2, NEON) optimizations and the FFTs, as well as a C API for FFI integration. The full C++ test suite passes against this Rust version. (AI assisted)

License

All crates in this repository are licensed under BSD-3-Clause.

Contributors

dignifiedquire

209 commits

dependabot[bot]

11 commits

ford-prefect

1 commits

Languages

Rust

97.7%