forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 00a6ca0f62175febd968d99add3b5cebe7e0e9a9Filtered to crates/ec-alac/tests/encode.rsClear filter

2026-08-20

fix(alac-enc): wrap predictor residuals to chan_bits the way the decoder doesAhmet Kaan Gümüş · 70bf744
fix(alac-enc): wrap predictor residuals to chan_bits the way the decoder does

A residual of two in-range samples can need one bit more than the samples
(24-bit ramp wrap-around, full-scale alternating at 16 coded bits after a
byte shift); the Golomb escape carries only chan_bits of it, so the value
truncated on the wire and the decoder's clamp() reconstructed the wrong
sample, or lost sync entirely. analyze() now wraps every residual to
chan_bits before zigzag and before the sign-adapt step, matching
decode.rs predict(). Guard AlacEncoder::new to the 16/24-bit depths
actually tested; add ramp/alternating/fuzz round-trip tests.
fix(alac): read a Golomb escape's raw value past the 32-bit prefix peek; drop the mode-1 emission knobAhmet Kaan Gümüş · b8b47ce
fix(alac): read a Golomb escape's raw value past the 32-bit prefix peek; drop the mode-1 emission knob

The adaptive-Golomb escape (9 ones + a raw maxbits value) was decoded from
a single 32-bit peek, so any element whose coded width is 24 or more bits
(24-bit unshifted mono = 24, stereo = 25) lost the raw value's low bit(s)
and desynced the rest of the channel. A smooth 24-bit tone is the first
content whose opening residuals are large enough to escape at that width;
random data goes out as a whole-frame raw escape and 16-bit-derived
24-bit audio codes 16 bits after bytes_shifted, so neither ever hit it.

The encoder's mode-1 (double-difference) path and its EC_ALAC_MODE1 env
knob are gone: no real-world decoder accepts prediction type 1, so a knob
producing such files was a trap. The decoder keeps reading mode 1.
EC_ALAC_NO_SHIFT becomes a hidden AlacEncoder::set_byte_shift setter.
feat(alac-enc): implement bytes_shifted split and mode-1 double-differenceAhmet Kaan Gümüş · d92d8b1
feat(alac-enc): implement bytes_shifted split and mode-1 double-difference

Two documented corner-cuts closed: 24-bit bytes_shifted (0/1, cost-chosen
per element via the existing CostSink) and the mode-1 double-difference
predictor pass (per-channel cost-chosen against mode 0).

Mode 1 is real but gated off by default (EC_ALAC_MODE1 env knob): writing
it broke this crate's own ffmpeg-oracle test with "unknown prediction
type: 1" — real-world ALAC decoders reject any prediction type but 0, even
though this crate's own decode.rs (independently written from the format
description) parses and reconstructs it correctly. Kept selectable for a
dedicated test and any stream known never to cross a third-party decoder.

Also discovered (not fixed, out of scope): a pre-existing bug corrupts
correlated 24-bit content's round trip independent of this change
(reproduces with bytes_shifted forced off too) — logged to the ledger.
feat(alac-enc): mono/stereo ALAC encoder (cookie/escape frames + adaptive-Golomb LPC compression)Ahmet Kaan Gümüş · 98a0f6f
feat(alac-enc): mono/stereo ALAC encoder (cookie/escape frames + adaptive-Golomb LPC compression)

Mirrors decode.rs's element walk and Rice/predictor state machine exactly
(same constants, same mean/zero-run adaptation) so encode_frame's output
decodes bit-exact through the existing AlacDecoder. Per-element it picks
the smaller of raw escape vs compressed, and for stereo the smaller of
direct L/R vs a mix_bits=1/mix_res=1 mid-side transform, searching filter
orders {0,4,8,12,16,31} with an always-zero-seeded sign-adapting predictor
(no Levinson-Durbin design step needed since decode's adaptation is
itself the filter).

Corner-cuts (documented in encode.rs): bytes_shifted always 0 (no 24-bit
low-byte split — correctness unaffected, only 24-bit ratio); predictor
mode always 0 (skips the mode!=0 double-difference-pass variant).