forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 58b009bb899650af1bbdab9d581dc768acc474fbFiltered to crates/ec-truehd/src/decode.rsClear filter

2026-08-28

fix(truehd): Welch-window the LPC autocorrelation; carry FIR history across restarts; amortize restart/major-sync/decoding-params per AUAhmet Kaan Gümüş · 7e95468
fix(truehd): Welch-window the LPC autocorrelation; carry FIR history across restarts; amortize restart/major-sync/decoding-params per AU

Levinson-Durbin fit a rectangular-windowed autocorrelation, which is
measurably biased away from a signal's true poles at the window's own
edges (proven on a pure tone: order-2 fit landed near [1.88,-0.89]
against the analytic [1.99,-1] until windowed). Tapering the analysis
window with a Welch window before autocorrelation fixes the tonal
compression gate (65.9% -> under the 65% target).

decode.rs: read_restart_header no longer zeroes FIR/IIR filter state at
a restart header (ffmpeg's mlpdec.c never does either) -- only real
lossless round-trip bug found this round, independently verified.

encode.rs also now amortizes real per-AU overhead the format was
designed to amortize: only access unit 0 carries a restart header and
major sync (this crate's own decoder's restart_seen persists once set,
and a major sync's presence is autodetected per AU, not flagged), and
later AUs skip the whole decoding-params section when this AU's chosen
plan is identical to the last one actually written. This uncovered and
fixed a real encoder bug along the way: eliding the FIR gate whenever
order was 0 left a decoder's stale nonzero FIR order from the previous
AU applied to un-predicted residuals once restarts stopped resetting
it every AU -- the gate must always be written, since read_filter
always reads the order field itself and that's the only thing that
actually clears a filter.

WIP, not fully green: encoder_round_trips_through_our_own_decoder and
the tonal compression gate now pass; the noise (pure-LCG, incompressible)
gate still overshoots its <=100% target at 100.9% (116210 vs 115200
bytes) even after eliding the restart header, major sync and unchanged
decoding params -- the remaining ~1010 bytes is the format's own
mandatory per-AU framing (4-byte AU header + 2-byte substream directory
entry, unavoidable per AccessUnitHeader::parse), a real overhead floor
this format's own container carries on any AU regardless of content.
ffmpeg oracle tests (tests/oracle.rs) not rerun this round.

2026-08-27

feat(truehd): a lossless stereo encoder, foreign-decoder verifiedAhmet Kaan Gümüş · c3703cb
feat(truehd): a lossless stereo encoder, foreign-decoder verified

Adds TrueHdEncoder: single-substream stereo, one restart header per
access unit, no matrixing or FIR/IIR prediction — every sample is a
raw 24-bit offset-binary residual, which the crate's own decoder
reconstructs exactly. Round-trips bit-exact through both this crate's
own decoder and, decisively, ffmpeg's independent TrueHD/MLP decoder
(the major sync's CRC-16 and the AU-header/directory parity nibble,
neither validated by our own decoder, had to be derived from ffmpeg's
mlp.c/mlp_parse.c/mlpdec.c source to satisfy a foreign decoder).

2026-08-20

feat(truehd): lossless substream decode — 2/6/8-ch presentations bit-exact, 16-ch object substream refusedAhmet Kaan Gümüş · 2f6b7e8
feat(truehd): lossless substream decode — 2/6/8-ch presentations bit-exact, 16-ch object substream refused

Decodes: restart headers (14-bit sync, CRC-8 poly 0x1D verified), decoding
parameters (presence flags, block size, primitive matrices, output shift,
quant step, FIR≤8/IIR≤4 with carried history, Huffman offset/codebook/LSBs),
residuals through the three codebooks (read off an external encoder's mono
output, then oracle-checked), per-substream parity and the lossless-check
byte, rematrixing with both noise generators (23-bit LFSR 2-channel noise for
0x31EA; 256-entry dither table for 0x31EB, every entry solved by constraint
intersection against the external decoder on the real 7.1 track), output
shift, interleaved S32 left-justified 24-bit. TrueHD 7.1 (assignment 0x4F)
lands on FL FR FC LFE BL BR SL SR via [0,1,2,3,6,7,4,5]. MLP major sync's
rate-code offset fixed (data[9], not data[8]).

Refused by name (Error::Unsupported): the 4th / 16-channel object substream,
any substream with more than 8 matrix channels, 8-ch presentations whose
channel assignment is not the standard 7.1 mask, reserved rate codes.
Not validated: the per-substream CRC-8 check byte (generator/span unknown;
parsed and skipped, see corner-cut in decode.rs).

Oracle (tests/oracle.rs, skipped without ffmpeg / the remux): first 60 s of
the real 7.1 remux 23 040 000 / 23 040 000 samples exact, 0 lossless-check,
0 parity, 0 restart-CRC, 0 length failures over 72 000 access units;
externally encoded MLP and TrueHD mono/stereo/5.1 streams all bit-exact.