forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on e7d153e4d78c854ed7d7be6f28fa8f0abd1cf055Filtered to crates/ec-opus/src/lib.rsClear filter

2026-09-06

feat(opus): port libopus's tonality analysis (MDCT features + MLP music_prob), consumers behind switchesAhmet Kaan Gümüş · 2d08e3d
feat(opus): port libopus's tonality analysis (MDCT features + MLP music_prob), consumers behind switches

The analysis runs on the undelayed API frame exactly where opus_encode does;
alloc_trim's tonality_slope term and compute_vbr's tonality/activity terms are
wired but default off pending their gate rows. music_prob separates the gate's
speech source (hein 0.161) from its music sources (reell 0.991, reelo 0.976).

2026-08-23

fix(opus): code tf_res=is_transient so transient frames keep short blocksAhmet Kaan Gümüş · 5b61429
fix(opus): code tf_res=is_transient so transient frames keep short blocks

Raw tf_res=0 with tf_select=0 on a transient frame maps through TF_SELECT to
+LM, merging the short blocks back into one long block and smearing the attack
across the whole frame. The reference's no-analysis default codes
tf_res[i]=isTransient (no change). reell err_ratio 21x -> 1.6x at 64 k and
24x -> 3.3x at 96 k; 14-row library gate green, no corr regression.

Decoder diag gains tf_res/spread/anti_collapse; repro tests
celt_silence_then_attack_decodes_bounded, reell_startup_hop_energies and
celt_click_peak_offset; hybrid layer tolerance 2->3 and SILK-vs-CELT margin
.005 re-sized against the sharper transient reconstruction.

2026-08-21

2026-08-20

feat(opus-hybrid): mono 20 ms SWB/FB hybrid packets (SILK 16 kHz + CELT from band 17)Ahmet Kaan Gümüş · a6d0278
feat(opus-hybrid): mono 20 ms SWB/FB hybrid packets (SILK 16 kHz + CELT from band 17)

CeltEncoder::encode takes a start band and mirrors the decoder's start_band
paths (no silence flag mid-stream, no postfilter bit, zeroed x below start,
cleared energy history outside the coded span). SilkEncoder::encode_hybrid
writes the chosen frame into a shared range coder and replay() advances the
mirror from the finished payload. Encoder: Voip 20-40 kbps mono 20 ms ->
config 13/15, reference's SILK rate share, no-redundancy flag under the
decoder's exact presence rule, SILK input delayed 70 samples so both layers
land at CELT's 120 (click-measured LB +121 / HB +120). Decoder gains a
doc(hidden) per-layer mute for the tests.
feat(opus-silk): SILK payload writer, mono 20 ms NB/WB, decoder-mirrored stateAhmet Kaan Gümüş · 12e4d27
feat(opus-silk): SILK payload writer, mono 20 ms NB/WB, decoder-mirrored state

Writes every symbol in silk::decode()'s order (VAD/LBRR flags, frame type,
gains, NLSF stage 1/2 + interp, pitch lag/contour + LTP codebook + scale,
seed, rate level, shell-coded pulses with LSB escape, signs) and quantises
the excitation open-loop against the decoder's own reconstruction, with
the encoder replaying each packet through a SilkDecoder so its LTP history
is the real one. Unit test round-trips NB/WB through the decoder including
the LSB escape, range state equal.
feat(opus-silk): SILK encoder analysis front endAhmet Kaan Gümüş · 79db13a
feat(opus-silk): SILK encoder analysis front end

Adds silk_enc.rs: 48k->8/12/16k FIR decimator, simplified VAD, LPC
analysis with unit-circle P/Q NLSF conversion, NLSF VQ search against
the decoder codebooks, pitch estimation and gain quantisation. Decoder
helpers made pub(crate) for reuse; no decoder logic changes.

2026-08-14

feat(opus): multi-rate input, application-driven bandwidth, whole shim surfaceAhmet Kaan Gümüş · 339a2ea
feat(opus): multi-rate input, application-driven bandwidth, whole shim surface

Grafts onto the merged CELT encoder, all four bitstream-neutral at 48 kHz
fullband (the four regression cells re-encode byte for byte):

- encoder: input at 8, 12, 16, 24 or 48 kHz, zero-stuffed to CELT's native
  rate with the coded bandwidth capped at the input's own Nyquist, so the
  images the stuffing puts there are never coded; look_ahead() reports the
  delay in input samples (120 at 48 kHz, scaled).
- encoder: Application reaches the encoder instead of being discarded at the
  shim boundary — it biases the coded bandwidth (Voip one step narrower),
  which is the only thing a CELT-only encoder can honestly do with it, and
  the TOC now spans configs 16..31 rather than fullband alone.
- celt_enc: `end` is a parameter, so the caller bounds the coded bands.
- ogg: the RFC 7845 header builders (opus_head, opus_tags, default_mapping)
  move into the crate, where the encoder, a muxer and the tests share one
  definition; the conformance test's hand-rolled OpusHead is now that call,
  and MultistreamEncoder::surround reads the mapping table from it.
- shims/opus-rs: the rest of the incumbent's surface — OpusDecoder,
  MultistreamEncoder::surround, the Bandwidth enum, the vbr field,
  look_ahead(), final_range() and encode_i16() — so a caller needs no
  second crate for the decode half or for surround.

Proof: the shim's own tests round-trip every input rate through the decoder
with range-state parity per packet, hold the 8 kHz..48 kHz look-ahead, force
a wideband TOC and read it back, and encode 5.1; the ec-opus suite (RFC
vectors, libopus rate table, opus_demo, Ogg duration, zero-alloc) is
unchanged and green.
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).
test(opus): fuzz every mode with garbage payloads; document the PLC gapAhmet Kaan Gümüş · acb0d04
test(opus): fuzz every mode with garbage payloads; document the PLC gap

Every TOC configuration is fed random payloads and every prefix of real packets
is fed to the decoder: a malformed stream must return an error, never panic,
and the debug build's overflow checks make that a real test of the fixed-point
paths too. The crate docs now state what is deliberately absent -- packet loss
concealment, which a container-fed decoder never needs -- and why CELT cannot
use ec-dsp's power-of-two MDCT directly.
feat(opus): multistream decoding, 5.1 and 7.1Ahmet Kaan Gümüş · 8bd3b2b
feat(opus): multistream decoding, 5.1 and 7.1

MultistreamDecoder splits a packet into its elementary streams by the
self-delimiting framing of Appendix B and routes each stream's channels through
the mapping table, silent channels included. Constructor takes the layout the
container header carries (rate, streams, coupled, mapping), which is the shape
the product already calls.

The CELT N/4 FFT's 15-point stage is now radix-3 then radix-5 rather than a
direct 15x15 evaluation, which is where a third of multichannel decode time was
going: a real 7.1 film track went from 102x to 124x realtime.

Checks (all in tests/conformance.rs): the mono, stereo and 5.1 Ogg-Opus
fixtures decode to correlation 1.00000 per channel against libopus through
ffmpeg; the 5.1 fixture's per-channel tones land in the RFC 7845 family 1
(Vorbis) order the reference produces, each channel carrying its own tone;
decode speed is 430x realtime stereo (fixture and testvector01 music alike) and
236x realtime 5.1, against floors of 135x and 104x. The twelve RFC vectors are
unchanged. An env-driven sweep (EC_OPUS_FILES, #[ignore]) runs the same
comparison over real files.
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.