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.
| Module | RFC 6716 | Contents |
|---|---|---|
range | §4.1, §5.1 | range decoder + encoder: symbols, binary/ICDF contexts, raw bits, uniform integers, tell/tell_frac |
packet | §3 | TOC byte, frame packing codes 0-3, padding, R1-R7 validation |
silk | §4.2 | SILK decoder and encoder |
celt | §4.3 | CELT decoder and encoder |
ogg | RFC 3533 + RFC 7845 | Ogg 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§
- Multistream
Decoder - A multistream Opus decoder.
- Opus
Decoder - The Opus decoder for one stream at 48 kHz output.
- Opus
Encoder - A pure-Rust Opus encoder at 48 kHz, producing CELT, SILK (mono/stereo) and
hybrid packets;
encode_autochooses the mode. - Silk
Encoder - A SILK encoder for one mono stream.
- Silk
Stereo Encoder - A SILK encoder for one stereo stream (mid/side coding).
Enums§
- Application
- Coding application / latency profile (
OPUS_SET_APPLICATION). - Encode
Error - Errors returned by the
OpusEncoderencode methods. - OggDecode
Error - 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
OpusHeadoutput 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/OpusTagsheaders followed by the audio page stream, fullband and 20 ms per packet viaOpusEncoder::encode_auto.channelsis 1 or 2;bitrateis the target in bits/s. The final partial frame is zero-padded. This is the symmetric counterpart todecode_ogg_opus- together they let the codec read and write standard.opusfiles.