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.
| Crate | Description | Crates.io | Documentation |
|---|---|---|---|
sonora |
Full audio processing pipeline | ||
sonora-ffi |
C API (FFI) for integration with C/C++ projects | ||
sonora-aec3 |
Echo Canceller 3 (AEC3) | ||
sonora-agc2 |
Automatic Gain Control with RNN VAD | ||
sonora-ns |
Noise Suppression | ||
sonora-common-audio |
Audio DSP primitives (resamplers, filters) | ||
sonora-simd |
SIMD operations (SSE2, AVX2, NEON) | ||
sonora-fft |
FFT implementations (Ooura, PFFFT) |
- 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)
Run the minimal echo cancellation demo:
cargo run -p sonora --example simpleMore examples in crates/sonora/examples/:
| Example | Description | Command |
|---|---|---|
simple |
Synthetic AEC round-trip | cargo run -p sonora --example simple |
karaoke |
Mic loopback with echo cancellation | cargo run -p sonora --features examples --example karaoke |
recording |
Record & process to WAV | cargo 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.
| Platform | Architecture | SIMD Backend | CI Status |
|---|---|---|---|
| Linux (Ubuntu) | x86_64 | SSE2, AVX2 | Build, test, clippy, fmt, docs |
| macOS | ARM64 (Apple Silicon) | NEON | Build, test |
| Windows | x86_64 | SSE2, AVX2 | Build, test |
| Android | aarch64, armv7, x86_64, i686 | NEON / SSE2 | Build, test (via cross) |
| iOS | aarch64 | NEON | Build, 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.
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.
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:
| Benchmark | Rust | C++ | Ratio |
|---|---|---|---|
| 16 kHz mono | 4.2 us | 4.0 us | 1.07x |
| 48 kHz mono | 13.3 us | 10.8 us | 1.24x |
See BENCHMARKS.md for per-component comparisons, profiling breakdown, and instructions for reproducing.
This project uses cargo-make for task automation.
cargo install cargo-makecargo 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)
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.
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
-
Google's libwebrtc -- The original AudioProcessing module is developed as part of the WebRTC Native Code project at Google.
-
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.
-
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)
-
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)
All crates in this repository are licensed under BSD-3-Clause.