forge
Explore
Log in

Don't you dare go Hollow

Commits

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

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