forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on cbbd6e2ef6acafb00aeb55e460423f024126f90fFiltered to crates/ec-opus/src/range.rsClear filter

2026-08-14

feat(opus): CELT encoder — mono/stereo/multistream, all rates, CBR+CVBRAhmet Kaan Gümüş · 52ead44
feat(opus): CELT encoder — mono/stereo/multistream, all rates, CBR+CVBR

Throughput-first CELT-only Opus encoder (RFC 6716 Section 5, coding path
mirrored symbol-for-symbol from the normative Appendix A; analysis replaced
by fast deterministic heuristics: no pitch prefilter, tf_res fixed, spread
fixed NORMAL, single-pass coarse energy):

- range.rs: full RFC 5.1 range encoder (fixed-size frames, shrink, raw-bit
  tail), tell()/tell_frac()/range-state exact against the decoder per symbol
- celt_enc.rs: forward MDCT as the exact adjoint of the decoder's inverse,
  transient/trim/dynalloc/stereo analyses, encode-side allocation, PVQ
  search (wide f32x8 lanes) + V(N,K) enumeration, Laplace coarse energy
- encoder.rs: TOC framing (configs 28..31), CBR and constrained-VBR, plain
  and self-delimited (App B) packets
- multistream_enc.rs: RFC 7845 family-1 surround (5.1 helper), per-stream
  self-delimited framing, coupled streams weighed 2:1 in the rate split
- shims/opus-rs: the opus-rs 0.1.26 surface edith consumes, mono fixed and
  no rate ceiling; root-cause doc for the incumbent's ~165 kbps cliff in
  lib.rs

Proof in tests/conformance.rs (same binary): per-packet range-state parity
encoder vs vector-verified decoder at 32..510 kbps x {mono,stereo} x all
frame sizes x CVBR; libopus (ffmpeg) decodes the whole rate table at worst
corr 0.9565 (32k stereo) to 1.0000; 5.1 order-preserved >=0.9978; reference
opus_demo 0.9995 at 256k stereo; Ogg-Opus duration exact; zero-alloc steady
state; speed floors (measured ~150-580x realtime per config).
feat(opus): SILK layer, hybrid frames and packet redundancyAhmet Kaan Gümüş · ece2a35
feat(opus): SILK layer, hybrid frames and packet redundancy

Full RFC 6716 Section 4.2 decode in exact integer arithmetic: header and LBRR
flags, gains, NLSF stage-1/stage-2 dequantisation with Laroia weighting,
stabilisation and interpolation, LSF-to-LPC conversion with prediction-gain
limiting, pitch lags and LTP filters, shell-coded excitation with LSBs and
signs, LTP and LPC synthesis, stereo unmixing, and the output resampler for
8/12/16 kHz internal rates. The Opus layer now joins the two layers: SILK-only,
hybrid (SILK below 8 kHz plus CELT above), and the redundancy frames that carry
a mode switch across a packet boundary.

Check: all twelve RFC 6716 vectors, decoded at 48 kHz stereo, match the
reference range coder state on every one of 18075 packets, and score 96.96 to
100.00 % on the opus_compare metric (0 is the passing threshold). The three
SILK-only vectors are sample-for-sample identical to the reference output.
Unit checks cover the fixed-point helpers, gain dequantisation monotonicity and
LSF stabilisation.
feat(opus): CELT layer decoder and the single-stream decoderAhmet Kaan Gümüş · a882b8b
feat(opus): CELT layer decoder and the single-stream decoder

Full RFC 6716 Section 4.3 decode: coarse/fine/final energy with the Laplace
model, the implicit bit allocation (caps, dynalloc boosts, trim, interpolation,
skip), PVQ shapes with spreading, folding and splits, time-frequency changes,
anti-collapse, denormalisation, inverse MDCT with overlap-add, post-filter and
de-emphasis. All frame sizes 2.5-20 ms, all bandwidths NB..FB, mono and stereo.

The MDCT sizes are 15*2^k, so the N/4 FFT runs a 15-point stage over ec-dsp's
power-of-two transform rather than anything O(N^2).

Checks (tests/conformance.rs, one binary for the whole suite): the three
CELT-only RFC 6716 vectors decode with the reference range-coder state on
every packet -- 2147/2147, 4186/4186, 553/553 -- and score 99.8/99.6/99.7 %
on the opus_compare metric, reimplemented in Rust from the criterion in
Section 6 and cross-checked against the C tool (99.871 vs its 99.9 %, same
internal error 0.000315). Unit checks cover the IMDCT (overlap-add
reconstruction at every size), the 15*2^k FFT against a direct transform,
and the PVQ combinatorics.
feat(opus): range decoder and packet framingAhmet Kaan Gümüş · b05a16e
feat(opus): range decoder and packet framing

RFC 6716 Section 4.1 range decoder (exact u32 arithmetic, raw bits from the
frame end, ec_tell/ec_tell_frac) and Section 3 + Appendix B framing: TOC,
codes 0-3, padding, and the self-delimiting variant multistream needs.

Checks: symbol round-trip against a test-only range encoder written from
Section 5.1, tell/tell_frac agreement, and a malformed-input sweep that must
never panic.