opus-rs
A pure-Rust implementation of the Opus audio codec (RFC 6716), ported from the reference C implementation (libopus 1.6).
Status: Work in progress — SILK-only and CELT-only modes are functional. Hybrid mode is not yet implemented.
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
- 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
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 84 tests pass, covering MDCT identity, PVQ consistency, SILK encode/decode roundtrip, CELT loopback, bitstream comparison with C reference, and more.
WAV Roundtrip
# Rust encoder/decoder
# Compare with C libopus (requires opusic-sys)
Roadmap
- SILK-only encode & decode (NB/MB/WB)
- CELT-only encode & decode (FB)
- Range coder (entropy coding)
- Rate control loop (CBR/VBR)
- VAD & DTX framework
- HP variable cutoff filter
- SILK bitstream bit-exact match with C reference
- NLSF interpolation for multi-frame packets
- High-quality resampler (up2, up2_hq) for decoder
- Hybrid mode (SILK + CELT)
- LBRR (forward error correction)
- Stereo encoding (mid-side)
License
This project is a clean-room Rust port of the Opus reference implementation. See COPYING for the original Opus license (BSD-3-Clause).
Links
- Repository: https://github.com/restsend/opus-rs
- Opus specification: RFC 6716
- Reference C implementation: https://opus-codec.org/