ruopus
A pure-Rust implementation of the Opus audio codec (RFC 6716): decoder and encoder, with no C and no FFI.
Pure Rust. unsafe only in a few SIMD kernels, every one checked under
Miri. Runs on stable Rust
The decoder passes the official Opus conformance vectors, and the encoder produces standard Opus that libopus and ffmpeg decode.
Python bindings are available on PyPI.
Overview
ruopus is a from-scratch Rust implementation of Opus. It links no
libopus, needs no C toolchain, and exposes plain &[u8]/&[i16]/&[f32]
interfaces, so it embeds under any audio stack.
- Pure Rust, no FFI. Builds on
wasm32. The decoder isno_std+alloc(build withdefault-features = false, features = ["libm"]); the encoder currently needsstd. unsafeis denied by default. The only exceptions are a fewstd::archSIMD hot loops, each carrying a// SAFETY:note (docs/unsafe.md) and checked for undefined behaviour by Miri on both the SSE2 and AVX2 paths (tools/miri.sh). Noportable_simd, no inline asm.- Zero required dependencies. The default build adds one optional FFT crate for
faster decoding;
default-features = falseis fully dependency-free.
Use
[]
= "0.1"
use ;
// Decode Opus packets to interleaved f32 PCM.
let mut dec = new; // channels
let pcm = dec.decode_packet?;
// Encode 48 kHz PCM (one 20 ms frame is 960 samples per channel, interleaved).
let mut enc = new;
enc.set_bitrate;
let packet = enc.encode_auto?;
// Whole Ogg Opus files.
let = decode_ogg_opus?;
let ogg = encode_ogg_opus;
Python
Install from PyPI:
The bindings wrap OpusDecoder and OpusEncoder with NumPy interop — decoded
PCM is returned as a (frames, channels) float32 array; the encoder accepts the
same shape or a flat interleaved array.
# Decode
=
= # ndarray (frames, 2), float32
# Encode
=
= # 20 ms at 48 kHz
= # bytes
Performance
Measured against libopus 1.6.1 (SIMD-enabled C) on identical data, one core,
pinned to a single performance core: cargo bench --bench vs_libopus --features std. Figures are x realtime; "ratio" is ruopus divided by libopus.
Decode
| Mode | ruopus | libopus | ratio |
|---|---|---|---|
| SILK wideband 16 kb/s | 2095x | 1171x | 1.79x |
| hybrid fullband 32 kb/s | 1199x | 850x | 1.41x |
| CELT fullband 64 kb/s | 1389x | 1566x | 0.89x |
Speech decode (SILK, hybrid) is faster than SIMD libopus. CELT trails on the MDCT, where libopus's SIMD wins.
Encode (matched complexity)
| Mode | ruopus | libopus | ratio |
|---|---|---|---|
| SILK wideband 16 kb/s | 734x | 740x | 0.99x |
| hybrid fullband 32 kb/s | 560x | 562x | 1.00x |
| CELT fullband 64 kb/s | 1088x | 1092x | 1.00x |
At matched complexity, encode is at parity with libopus across all modes. Against libopus at its default complexity it runs 1.6 to 3.2x faster (it does not yet spend cycles on delayed-decision NSQ or warped noise shaping).
Conformance
Passes the official Opus conformance criterion: all twelve
RFC 8251 test vectors score 99.2 to 100%
on opus_compare, with per-packet final ranges bit-exact. Fetch the vectors with
tools/fetch-testvectors.sh (about 121 MB, not committed); the conformance
tests skip cleanly without them.
License
MIT, see LICENSE. The Opus format is royalty-free; see the Opus IPR statements.