forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 8a26b91be66df7bc0b035b31bc4bfd7e2da3b786Filtered to crates/ec-vorbis/src/encode.rsClear filter

2026-08-21

2026-08-20

perf(vorbis-enc): quality per bit on real music — finer residue classes, co-mask cap, point stereo, drum-only transient detectorAhmet Kaan Gümüş · 9203ba6
perf(vorbis-enc): quality per bit on real music — finer residue classes, co-mask cap, point stereo, drum-only transient detector

Three 30 s tracks at 128 kbps, correlation with the source: 0.9812/0.9745/0.9911
(9ac19d6) -> 0.9711/0.9663/0.9984 (f1fa335, block switching firing ~1/s on music
with 16 short blocks each) -> 0.9955/0.9936/1.0000 now, at 131/131/109 kbps.
At the reference encoder's own size (109/116/92 kbps): 0.9906/0.9901/0.9999
vs its 0.9970/0.9960/0.9986.

- residue: nine classes one octave of range apart (+-1 ... +-64, +-127), 16
  coefficients per long partition, books from measured per-class statistics
  (mean |v| ~ range/6): 0.977 -> 0.988 on the two rock tracks alone
- floor: 12 long points instead of 20 (16/20/32/44 each worse on music)
- co-mask cap: nothing under loudest-50 dB in a long block is coded;
  corner-cut named in the code, upgrade is a Bark-domain spread
- point stereo above 4 kHz while the rate loop is starving (headroom under
  the range); lossless pair coding otherwise
- transient detector: jump measured against the loudest of the four ticks
  before, -60 dBFS absolute floor; music now fires 16-32 short blocks per 30 s
- short blocks quantised with at least 42 dB headroom whatever the loop's
  state, and no co-mask cap: fixes the 6 ch / 96 kHz onset leak (peak 0.0106
  -> 0.0062 at 36 dB, under 0.005 at 42) that the sweep now covers
  (onset sweep: 44.1k 1/2 ch, 48k 1/2/6 ch, 96k 6 ch)

Known failing: quiet_content_reaches_the_target_within_25pct — the quiet
fixture codes at corr 0.9999 and 74 kbps at every target; with the cheaper
residue and 12-point floor nothing codable is left inside the 36 dB range,
so the loop cannot spend up to 128/192 kbps on it.
fix(vorbis-enc): 42 dB residue range in short blocks, with a clamp-guarded floor refit; onset test sweeps phase, hop offset and per-channel contentAhmet Kaan Gümüş · a554dfa
fix(vorbis-enc): 42 dB residue range in short blocks, with a clamp-guarded floor refit; onset test sweeps phase, hop offset and per-channel content

An onset inside a short block leaked up to 0.0113 peak (1.6x the 0.01*amp bar)
because the block's step was the 36 dB pair range. The full 42 dB could not be
used: the floor is set per X point from its region's peak and drawn as straight
lines, so a peak at a region's edge sits further under the curve than the range
states and clamps at 127 — catastrophically (0.11 peak) on some phases. Now any
block whose quantised values exceed the range lifts the floor points around the
clamping bins and refits, so short blocks run at 42 dB and long blocks keep 36.

Worst gap peak over the 40-case sweep: 0.0113 -> 0.0053; worst RMS 0.000245
-> 0.000140. Fixture 46492 -> 46493 bytes, 60 s stereo unchanged.
fix(vorbis-enc): let rate-loop headroom past the residue range lower the ATH bound, so quiet/sparse content reaches the targetAhmet Kaan Gümüş · 14b96be
fix(vorbis-enc): let rate-loop headroom past the residue range lower the ATH bound, so quiet/sparse content reaches the target

The widest residue book states +-127 and a coupled angle is a difference of
two magnitudes, so a pair's step cannot usefully go past 36 dB under the
peak. On sparse or quiet content the floor sits on the absolute threshold
almost everywhere, those partitions code as class 0 at any step, and the
loop pegged at 36 dB with ~44 kbps against a 128 kbps target. Headroom now
clamps at 84 dB; the part past 36 dB lowers the threshold bound instead of
the step, which gives the loop bins under the old threshold to spend on.
Decoder and stream syntax untouched.
fix(vorbis-enc): cap the ATH at -80 dBFS so an onset inside a short block is not coded against a -10 dB floorAhmet Kaan Gümüş · 9b7e0e0
fix(vorbis-enc): cap the ATH at -80 dBFS so an onset inside a short block is not coded against a -10 dB floor

The pre-echo the verifier measured (gap RMS 0.002261 at 44.1k, peak 0.073)
lived entirely in the one short block whose window straddles the onset, not
in the long->short transition block: the block plan already puts the onset
mid short-run. Its DC bin and every bin above ~17 kHz were quantised against
the absolute-threshold floor, whose own curve sits at -13 / -10 dBFS there,
so a 0.1-amplitude step coefficient took a 0.2-0.3 quantiser step and its
error spread over the whole 256-sample window at -38 dB. Capping the ATH at
-80 dBFS gives gap RMS 0.000059 / peak 0.0028 (reference encoder on the same
input: 0.000120 / 0.0057).

Also gate a steady long block on its lookahead hop being buffered: with
chunked input the plan was committed before the detector could see the
transient it is supposed to make room for.

Test now places the onset off the block grid (0.9137 s) as well as on it,
measures the whole [0, onset) gap plus its peak, mono and stereo, 44.1k/48k,
our decoder and the reference oracle.
feat(vorbis-enc): real block switching — short blocks eliminate pre-echo at silence→onsetAhmet Kaan Gümüş · 63f547a
feat(vorbis-enc): real block switching — short blocks eliminate pre-echo at silence→onset

Two modes now: 2048-sample long blocks (steady state) and 256-sample short
blocks, with their own floor1 X-grids and residue partition sizing but
sharing the encoder's designed codebooks. A per-hop energy-tick transient
detector (an onset after digital silence is the degenerate, always-firing
case of the general jump-past-predecessor check) swaps a pair of would-be
long blocks for long-with-short-right-window, a run of short blocks over the
transient, and long-with-short-left-window resuming steady state — a run
sized to land the transient safely inside short-block coverage rather than
in a transition block's own flat (unwindowed) span, which is what silently
reintroduced the leak the first cut of this fix produced.

Granule advance across a switch is exactly N long hops, so it never moves
the steady-state grid; a stationary signal still never leaves long-block
mode (tested). New oracle test onset_after_silence_has_no_pre_echo measures
gap RMS immediately before the onset at 44.1/48 kHz through both our own
decoder and the reference oracle: 0.0064 -> 0.0 (both rates, both decoders).
fix(vorbis): flush() delivers the terminal block's un-overlapped tailAhmet Kaan Gümüş · 750facc
fix(vorbis): flush() delivers the terminal block's un-overlapped tail

VorbisDecoder::flush() set drained=true and returned without emitting
self.lap, the accumulator holding the last decoded block's samples past
the final centre that had not yet been overlap-added into an output
frame. Per Vorbis I §1.3.2 those samples, up to the stream's final
granule position, are valid output the decoder must deliver — dropping
them left every decode exactly one hop (1024 samples at typical rates)
short of the encoded length at true EOS.

flush() now emits any non-empty self.lap as one final Frame::Audio,
permuted through the same to_ec channel map decode_audio uses, before
marking drained.

Also converts encode.rs's debug_tail_granule_44100_mono from a
panic-driven probe into a real assertion (packets==45, last
granule==44100), and adds oracle.rs::flush_delivers_the_terminal_hop,
a decoder-trait (send_packet/receive_frame/flush) round trip over a
sample count that is deliberately not a multiple of the hop, checking
exact output length and tail correlation against the source.

2026-08-14

feat(vorbis): Vorbis I decoder and encoderAhmet Kaan Gümüş · c0023ff
feat(vorbis): Vorbis I decoder and encoder

Decode is the whole format: codebooks with the entry-order codeword rule
(not sorted-canonical - a Laplacian book assigns differently and every
packet desynchronises silently), floor 0 and floor 1, residues 0/1/2,
square-polar coupling, every blocksize and the four long-window shapes.
Encode writes its own codebooks and a setup header per channel layout,
centres the first block on input sample 0 so no caller pre-roll is needed,
and states the input's own sample count as the last granule.