opus-rs 0.1.1

Rust implementation of Opus codec
Documentation

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 opus_rs::{OpusEncoder, OpusDecoder, Application};

// Encode
let mut encoder = OpusEncoder::new(16000, 1, Application::Voip).unwrap();
encoder.bitrate_bps = 16000;
encoder.use_cbr = true;

let input = vec![0.0f32; 320]; // 20ms frame at 16kHz
let mut output = vec![0u8; 256];
let bytes = encoder.encode(&input, 320, &mut output).unwrap();

// Decode
let mut decoder = OpusDecoder::new(16000, 1).unwrap();
let mut pcm = vec![0.0f32; 320];
let samples = decoder.decode(&output[..bytes], 320, &mut pcm).unwrap();

Testing

cargo test

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
cargo run --example wav_test

# Compare with C libopus (requires opusic-sys)
cargo run --example wav_test_c

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