Commits
Commits on
c249957b5d2fe8a52bfb5f7294d2cb269ecb9d64Filtered to crates/ec-truehd/src/encode.rsClear filter2026-08-28
test(truehd): replace the noise gate's arbitrary <=100% target with a format-derived framing floorAhmet Kaan Gümüş · b0c2924
test(truehd): replace the noise gate's arbitrary <=100% target with a format-derived framing floor The r3 restart/major-sync/params-elision rewrite (1b70839) passed all 3 ffmpeg oracle tests unmodified (tests/oracle.rs: ffmpeg_decodes_our_ encoder_bit_exact, externally_encoded_mlp_round_trips_bit_exact, first_60_seconds_of_a_real_7_1_remux_are_bit_exact) -- mlpdec.c accepts a stream that only restarts/majorsyncs on access unit 0 and elides unchanged decoding params on every later one, so no encoder-side fix was needed this round. compression_ratio_gates' noise arm still can't hit <=100% for genuinely incompressible content (100.9% measured, r3's ledger dead-end): this format's own per-AU container framing (AU header + substream directory entry + segment alignment, one-time major sync + restart header on AU 0) is a real, non-negotiable floor above raw PCM size, not a missed optimization. The gate now asserts against that floor computed from the literal field widths encode_access_unit writes (PER_AU_FRAMING_ FLOOR=8B/AU + FIRST_AU_EXTRA=51B one-time + 8B named rounding slack), not an arbitrary percentage fitted to the observed byte count.
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
wip(truehd): FIR LPC + codebook-2 residuals, debug artifacts still in — not a done stateAhmet Kaan Gümüş · 8073482Browse files
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).