forge
Explore
Log in

Don't you dare go Hollow

Commits

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

2026-09-06

perf(opus): two-pass coarse energy ships off; err_ratio at 64k is an outlier-window statisticAhmet Kaan Gümüş · 48b35d9
perf(opus): two-pass coarse energy ships off; err_ratio at 64k is an outlier-window statistic

The 64k err_ratio gap is not band-energy fidelity. On every source whose
ratio is above 1 the per-band mean log-energy error is LOWER than libopus's
in nearly every one of the 15 compare bands; the ratio is carried by a
handful of 40 ms windows, which opus_compare raises to the 4th power twice.
The diagnostic now recomputes both sides' err with the worst k windows
dropped (same denominator):

  source     drop-0   drop-1   drop-8   drop-1%
  reell@64      2.697    1.025    0.992    0.918
  her@64      1.103    0.995    0.962    0.955
  reelo@64     1.510    1.563    1.217    1.036
  nik@64      0.708    0.843    0.959    0.939
  dl8a@64     0.552    0.540    0.586    0.957
  hein@64     0.853    0.634    0.491    0.864

reell and her are ONE window each (a silence -> attack transition where our
decode is orders of magnitude quieter than the source's -110 dBFS ramp while
libopus tracks it); reelo is the only source with a distributed gap, and its
worst windows are all transient frames.

The mechanism ported whole meanwhile is libopus's two-pass coarse energy
(quant_coarse_energy + quant_coarse_energy_impl badness, enc_start_state
rewind): it codes both the intra and the inter-predicted pass and keeps the
lower-badness one. Gated on the 12-row library gate it moved 6 rows better
and 4 worse (reelo@64 1.510->1.581, her@64 1.102->1.135, her@96 1.052->1.059,
nik@96 .982->.990 against dl8a .551/.374->.503/.346, hein .855/.528->
.771/.419, reelo@96 .940->.872, nik@64 .708->.703), corr within +.0001
everywhere, so under the KEEP rule (err_ratio not worse on any row) it ships
behind TWO_PASS_COARSE_ENERGY = false with the numbers at the decision site.

- range: EncSnapshot save/restore of the coder scalars plus the front bytes,
  so a trial pass can be rewound exactly.
- conformance: the spectral divergence diagnostic gains reelo/nik sources, a
  SWEEP_TAG output name and the drop-k err recomputation; the hop-energy
  instrument gains HOP_KBPS.
wip(opus): two-pass coarse energy ported from libopus; per-band diagnosis at 64kAhmet Kaan Gümüş · e4775f2
wip(opus): two-pass coarse energy ported from libopus; per-band diagnosis at 64k

- range: EncSnapshot save/restore of the coder scalars + front bytes, so a
  trial coarse-energy pass can be rewound (libopus enc_start_state).
- celt_enc: quant_coarse_energy_impl returns badness; quant_coarse_energy
  codes both intra and inter passes and keeps the lower-badness one.
- conformance: spectral divergence diag gains reelo/nik sources and a
  SWEEP_TAG output name; hop-energy instrument gains HOP_KBPS.

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.