forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 1f91edd86ff5fbef5cdf0587e29ece28126eac62Filtered to crates/ec-opus/src/encoder.rsClear filter

2026-09-12

docs(ec-opus): document all public SilkDecIndices/SilkFrameDiag fields, fixing 21 missing_docs warnings reaching edith's zero-warning build; also de-link private items in doc comments so cargo doc is warning-freeAhmet Kaan Gümüş · b423eae
docs(ec-opus): document all public SilkDecIndices/SilkFrameDiag fields, fixing 21 missing_docs warnings reaching edith's zero-warning build; also de-link private items in doc comments so cargo doc is warning-free

2026-09-06

feat(opus): wire the analysis's leakage boost and detected bandwidth, both offAhmet Kaan Gümüş · 7e58ade
feat(opus): wire the analysis's leakage boost and detected bandwidth, both off

Two more consumers of the ported tonality analysis, each behind its own
switch and each defaulting off until the 12-row library gate keeps it:

- EC_OPUS_LEAK: celt_encoder.c:1226-1230, the per-band leak_boost added
  to the dynalloc follower in 1/64 dB units.
- EC_OPUS_BW_DETECT: opus_encoder.c:1278-1305 maps analysis.bandwidth to
  an Opus bandwidth, :1652-1674 raises it to a rate-dependent floor and
  lets it lower (never raise) the automatic bandwidth.

The prefilter's max_pitch_ratio (celt_encoder.c:1494) has no consumer --
this encoder has no pitch prefilter -- and the spread/tapset hysteresis
is inside an #if 0 in libopus, so neither is wired.
perf(opus): run the tonality analysis once per API frame, and only when readAhmet Kaan Gümüş · 54d9580
perf(opus): run the tonality analysis once per API frame, and only when read

libopus's opus_encode_native runs run_analysis() on the API frame before
the SILK/CELT mode decision, so the estimator belongs to Encoder, not to
the CELT layer: hoisted, its result threaded into celt.encode at both
call sites, state now advancing on SILK frames too.

It also cost ~25% of the encoder while every one of its bitstream
consumers ships off, so it now runs only when something reads it -- any
consumer switch, EC_OPUS_ANALYSIS=1, or the new Encoder::set_analysis.
5.1 384k goes 100x -> 123x realtime, mono 96k 433x -> 557x; the
music_prob oracle test is unchanged against libopus (hein .161/.155/
-.0875/.568, reell .991/.362/-.1680/.701, reelo .976/.312/-.1332/.735).
test(opus): the oracle Ogg carries the encoder's pre-skip, and the combined aligned arm's rowAhmet Kaan Gümüş · 1387bbe
test(opus): the oracle Ogg carries the encoder's pre-skip, and the combined aligned arm's row

oracle_decode wrote a 120-sample pre-skip whatever the stream's delay was, so
comparing it sample-for-sample against our own decode at the advertised offset
was 192 samples out under the alignment (hybrid_fb_roundtrip: oracle corr
0.028).  It takes the pre-skip from the caller now; the hybrid site passes the
encoder's look_ahead, and all seven rewritten lag tests pass with
EC_OPUS_ALIGN=1 as well as with the default.

r7 (two-pass coarse energy + tf boost k=1.25 on the aligned tree) is the best
combined arm and still leaves the same seven rows worse; its row is in the
table at set_libopus_input_alignment.
feat(opus): EC_OPUS_ALIGN=1 turns the libopus input alignment on process-wideAhmet Kaan Gümüş · 28054d0
feat(opus): EC_OPUS_ALIGN=1 turns the libopus input alignment on process-wide

The knob is otherwise API-only, so the gate could not sweep it; this is how
the rows recorded at set_libopus_input_alignment were produced.
feat(opus): the libopus input alignment ships behind a knob, off, with its gate tablesAhmet Kaan Gümüş · 02f91a2
feat(opus): the libopus input alignment ships behind a knob, off, with its gate tables

set_libopus_input_alignment(true) feeds the CELT layer the input delayed by
delay_compensation = Fs/250 and runs libopus's 3 Hz dc_reject on every frame
first; look_ahead and the hybrid SILK delay follow it (120 -> 312).  The
alignment is exact: on the reell attack frame all eight low bands land within
.0006 of libopus (unaligned: .06-.21 apart).

It defaults OFF because the 12-row library gate rejects it and the constants
fitted on the misaligned spectrum do not explain the loss: delay only is 7
better / 5 worse, delay+dc_reject 5/7, and two-pass coarse energy, the
continuous 1.3 alloc_trim and tf boost k=1.25/1.5 each leave the SAME seven
rows worse (nik@64/96, her@96, dl8a@64/96, hein@64/96).  Tables at the setter,
rows in lanes/opus-opusx2-r{1..5}.sweep.txt.

A conformance test drives the knob end to end: with it on the round trip
correlates at the advertised 312 and worse at 120.
feat(opus): libopus dc_reject on the API input, and lag-dependent tests read look_aheadAhmet Kaan Gümüş · 0151578
feat(opus): libopus dc_reject on the API input, and lag-dependent tests read look_ahead

The CELT input delay is back (revert of the revert): the analysis window now
sits where libopus's does.  On top of it, opus_encoder.c's dc_reject -- a 3 Hz
one-pole (coef = 6.3*cutoff/Fs, y = x - m, m = coef*x + (1-coef)*m, state per
channel across frames) -- runs once on the API input before both layers, the
way libopus filters into pcm_buf that silk_Encode and celt_encode_with_ec both
read.  libopus takes hp_cutoff instead for VOIP; not ported.

The seven tests that compared at a hardcoded 120-sample lag now read the
encoder's advertised look_ahead for the frame size they used, so they follow
the layer's real delay: delayed_corr takes it as an argument, the Ogg pre-skip
and the duration expectation come from look_ahead, and the hybrid lag window
is centred on it.  MultistreamEncoder grew look_ahead for the 5.1 file.

Sweep knobs for the re-tune on the aligned spectrum: EC_OPUS_TWO_PASS,
EC_OPUS_TRIM13 (the continuous 1.3 alloc_trim form).
Revert "revert(opus): drop the Fs/250 CELT input delay, keep the EC_OPUS_X_DEBUG bisect"Ahmet Kaan Gümüş · b1e155b
Revert "revert(opus): drop the Fs/250 CELT input delay, keep the EC_OPUS_X_DEBUG bisect"

This reverts commit 901c6ac3a87baf445fcdc07171b4cd49cf19ef93.

2026-08-27

fix(opus): 12 kHz input caps bandwidth at Medium, not NarrowAhmet Kaan Gümüş · 6efce81
fix(opus): 12 kHz input caps bandwidth at Medium, not Narrow

opus_encode_native's input-rate ceiling has four tiers (<=24k SWB,
<=16k WB, <=12k MB, <=8k NB); our match folded 12 kHz into the Narrow
arm, coding 12 kHz VoIP a band narrower than the reference would.

The opus-rs shim's slower-rates test surfaced it, stale in the other
direction: it still expected CELT's 120-sample overlap at every rate,
but since the libopus threshold port 16 kHz and below dispatch to SILK
at 32 kbps, whose resampler look-ahead is what the encoder reports.
Both expectations now follow the dispatch.

2026-08-23

feat(opus-silkq/r3): libopus reservoir decay + gain-step bound in SILK rate loopAhmet Kaan Gümüş · 18042b3
feat(opus-silkq/r3): libopus reservoir decay + gain-step bound in SILK rate loop

Debt-only bit reservoir decayed over 500 ms, gain search bounded to
+-9 steps around an EMA-carried operating point, 5 kbps target floor,
mid-heavy stereo split. Hybrid CELT min bytes 8 -> 3 (16k packets no
longer expand). Speech gate: 12k .8081 -> .8526, 16k .8606 -> .8646 at
+3.3% rate (was +12.9%), 24k .9036 -> .9146, 32k .9210 -> .9391.
Stereo-SILK 16k synthetic floor .35 -> .33 (regression named in test).
feat(opus-mode/r1): libopus VoIP/Audio mode and bandwidth thresholdsAhmet Kaan Gümüş · bb2f32f
feat(opus-mode/r1): libopus VoIP/Audio mode and bandwidth thresholds

Mode/bandwidth selection ported from opus_encoder.c (mode_thresholds blended
by voice_est, voice/music bandwidth tables, SILK>WB -> hybrid, 40/60 ms cap).
Speech gate rows are now all-auto with a MODE GATE; 4/4 rows pick the same
mode as ffmpeg libopus on real speech (lanes/opus-mode-r1.sweep.txt).

2026-08-21

2026-08-20

fix(opus-enc): look_ahead uses the same mono/20ms predicate dispatch doesAhmet Kaan Gümüş · cbcbe53
fix(opus-enc): look_ahead uses the same mono/20ms predicate dispatch does

look_ahead() consulted only wants_silk() (bitrate/application), not the
frame-size-and-channel check silk_choice()/hybrid_choice() apply before
encode_toc_and_payload actually picks a layer. A Voip/low-bitrate encoder
fed frame sizes other than 20 ms coded CELT but reported SILK's shorter
delay, throwing off the Ogg pre-skip by the difference. look_ahead now
takes the frame size and runs it through silk_choice, matching dispatch
exactly.

Also gives zero_stuff_mono a reusable Encoder-owned scratch buffer instead
of a Vec allocated per SILK/Hybrid frame — the zero-alloc steady-state
claim previously only held on the CELT path.
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): route Encoder's target bitrate into SILK's rate controlAhmet Kaan Gümüş · c54a10c
feat(opus-silk): route Encoder's target bitrate into SILK's rate control

Merge opus-nsq (NSQ + SilkEncoder::set_bitrate rate control) into
opus-silk. encoder.rs::encode_toc_and_payload now calls
enc.set_bitrate(self.bitrate) every SILK frame, so the public
Encoder's set_bitrate reaches the reservoir-based rate loop instead
of leaving SILK to code at unit excitation RMS. The NB/<=10kbps>WB
threshold in wants_silk/silk_choice is unaffected.

CBR-exact vs VBR-± distinction: SILK isn't budgeted against a byte
cap yet (documented at encode_toc_and_payload's doc comment, D2b) --
only the existing reservoir scheme (soft-tracks the target, same as
VBR) is wired; the Encoder's vbr flag doesn't yet branch SILK's mode.

oracle_decodes_our_packets_across_the_rate_table's SILK corner
(8/12/16 kbps) previously ran SILK unconstrained (set_bitrate was
never called from the Encoder path), so its 0.95 floor no longer
holds once the target is honestly rate-limited; lowered to 0.85,
matching the already-established floors in silk_rate_control_tracks_target.

Adds silk_packets_track_encoder_bitrate: drives the public Encoder
(Voip, mono, 8/12/16 kbps) and checks measured kbps within +-20%.

Fixes a merge fallout in oracle_decode (opus_head/write_ogg_opus
call sites diverged pre-skip signatures between the two branches).
feat(opus): SILK mode selection in EncoderAhmet Kaan Gümüş · 7f710e5
feat(opus): SILK mode selection in Encoder

Encoder dispatches SILK per frame (mono, 960-sample frames, Voip
application under 20 kbps) via set_mode/wants_silk/silk_choice, with a
click-measured look_ahead split per bandwidth (NB 58, WB 50 samples at
48 kHz) and a zero-alloc scratch buffer for the SILK payload so the
steady-state encode loop stays allocation-free.

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).