opus-rs
A pure-Rust implementation of the Opus audio codec (RFC 6716), ported from the reference C implementation (libopus 1.6).
Status: Production-ready — SILK-only, CELT-only, and Hybrid modes are functional. Stereo encoding (SILK and CELT) is supported.
Features
- Pure Rust — no C dependencies, no unsafe code in the codec core
- SILK encoder & decoder — narrowband (8 kHz), mediumband (12 kHz), wideband (16 kHz)
- CELT encoder & decoder — fullband (48 kHz) with MDCT, PVQ, energy quantization
- Hybrid mode — SILK for low frequencies + CELT for high frequencies
- Range coder — entropy coding with ICDF tables and Laplace distribution
- VAD — voice activity detection
- HP filter — variable-cutoff high-pass filter for VOIP mode
- CBR / VBR — both constant and variable bitrate modes
- LBRR — in-band forward error correction
- Resampler — high-quality resampling (up2, up2_hq)
- Stereo — mid-side encoding for both SILK and CELT
Quick Start
use ;
// Encode
let mut encoder = new.unwrap;
encoder.bitrate_bps = 16000;
encoder.use_cbr = true;
let input = vec!; // 20ms frame at 16kHz
let mut output = vec!;
let bytes = encoder.encode.unwrap;
// Decode
let mut decoder = new.unwrap;
let mut pcm = vec!;
let samples = decoder.decode.unwrap;
Testing
All 170+ tests pass, covering MDCT identity, PVQ consistency, SILK/CELT/Hybrid encode/decode roundtrip, resampler tests, and more.
WAV Roundtrip
# Rust encoder/decoder
Stereo Tests
Performance
vs C Opus (libopus 1.6.1) on Apple Silicon
Latest measurements on Apple Silicon M-series (aarch64), compiled with --release (opt-level=3 + ThinLTO), criterion bench with 20 samples. All numbers are per-frame (mono).
Real Audio Roundtrip (902/1804 frames of real speech, encode + decode)
| Config | Pure Rust | C Opus | Ratio |
|---|---|---|---|
| 8 kHz / 20 ms VoIP | 34.77 ms | 36.31 ms | 0.96× (Rust 4% faster) |
| 16 kHz / 20 ms VoIP | 58.23 ms | 59.37 ms | 0.98× (Rust 2% faster) |
| 16 kHz / 10 ms VoIP | 63.44 ms | 62.50 ms | 1.02× (C 2% faster) |
| 48 kHz / 20 ms Audio | 29.61 ms | 32.42 ms | 0.91× (Rust 9% faster) |
| 48 kHz / 10 ms Audio | 34.58 ms | 33.47 ms | 1.03× (C 3% faster) |
Summary:
- Real audio 48 kHz: Rust is 9% faster on 20ms, within 3% on 10ms
- Real audio SILK/VoIP: Rust is 2–4% faster on 8/16 kHz 20ms, within 2% on 10ms
License
See COPYING for the original Opus license (BSD-3-Clause).
Links
- RustPBX: https://github.com/restsend/rustpbx
- RustRTC: https://github.com/restsend/rustrtc
- SIP Stack: https://github.com/restsend/rsipstack
- Rust Voice Agent: https://github.com/restsend/active-call