Skip to main content

Crate ruopus

Crate ruopus 

Source
Expand description

A pure-Rust implementation of the Opus audio codec (RFC 6716).

No FFI. unsafe is confined to a few documented SIMD kernels, all checked under Miri. The decoder, the range coder and the packet layer build for no_std + alloc (enable the libm feature); the encoder currently requires std.

ModuleRFC 6716Contents
range§4.1, §5.1range decoder + encoder: symbols, binary/ICDF contexts, raw bits, uniform integers, tell/tell_frac
packet§3TOC byte, frame packing codes 0-3, padding, R1-R7 validation
silk§4.2SILK decoder and encoder
celt§4.3CELT decoder and encoder
oggRFC 3533 + RFC 7845Ogg pages, packet reassembly, OpusHead/OpusTags, granule/pre-skip timing, stream reader/writer

The decoder passes the official RFC 8251 conformance vectors; the encoder produces standard Opus that libopus and ffmpeg decode.

§Bit-exactness

Every arithmetic operation in the entropy coder follows the RFC text exactly; the encoder is verified against the decoder symbol-for-symbol (their rng states must agree after every operation - see RFC 6716 §5.1). All multi-byte values, state update rules, and rounding behaviours are documented at their definition with the RFC section they implement.

Re-exports§

pub use packet::Bandwidth;
pub use packet::FrameSize;
pub use packet::Mode;
pub use packet::Packet;
pub use packet::PacketError;
pub use packet::Toc;
pub use range::RangeDecoder;
pub use range::RangeEncoder;
pub use range::RangeEncoderError;

Modules§

celt
The CELT layer (RFC 6716 §4.3) - under construction.
ogg
The Ogg container (RFC 3533) and the Ogg encapsulation of Opus (RFC 7845).
packet
Opus packet framing (RFC 6716 §3).
range
The Opus range coder (RFC 6716 §4.1 and §5.1).
silk
The SILK decoder (RFC 6716 §4.2).

Structs§

MultistreamDecoder
A multistream Opus decoder.
OpusDecoder
The Opus decoder for one stream at 48 kHz output.
OpusEncoder
A pure-Rust Opus encoder at 48 kHz, producing CELT, SILK (mono/stereo) and hybrid packets; encode_auto chooses the mode.
SilkEncoder
A SILK encoder for one mono stream.
SilkStereoEncoder
A SILK encoder for one stereo stream (mid/side coding).

Enums§

Application
Coding application / latency profile (OPUS_SET_APPLICATION).
EncodeError
Errors returned by the OpusEncoder encode methods.
OggDecodeError
Errors from decode_ogg_opus.
Signal
Signal-content hint for the automatic mode decision (OPUS_SET_SIGNAL).

Functions§

decode_ogg_opus
Decodes an in-memory Ogg Opus file end to end (RFC 7845 §4): pre-skip removal, end trimming from the final granule position, and the OpusHead output gain. Returns interleaved 48 kHz f32 and the parsed header.
encode_ogg_opus
Encodes interleaved 48 kHz f32 PCM into a complete Ogg Opus file (RFC 7845): the OpusHead/OpusTags headers followed by the audio page stream, fullband and 20 ms per packet via OpusEncoder::encode_auto. channels is 1 or 2; bitrate is the target in bits/s. The final partial frame is zero-padded. This is the symmetric counterpart to decode_ogg_opus - together they let the codec read and write standard .opus files.