forge
Explore
Log in

Don't you dare go Hollow

ec-ac3 AHT zero-bit bins: match ffmpeg eac3dec.c. Root cause: a zero-bap AHT bin wrote six dither values straight into the blocks, while ffmpeg draws six raw LFG words (av_lfg_get & 0x7fffff) - 0x400000 per bin and then runs idct6 on every bin (line 284, after the if/else), and its dither is the raw word, not the AC-3 mantissa formula. Fix: Dither::value is the raw word scaled by 2^-23, zero bins fill pre with it and go through idct6 like VQ/GAQ bins. Evidence: ffmpeg n8.0 eac3dec.c lines 239-241 and 284; unrun (cargo check only), orchestrator to verify csi_miami_5.1_256_spx_small.eac3 ch3 LFE

Browse files at this commit

244c6bdf8764f439a11fcb29fa8c6057287bb199Ahmet Kaan GümüşParent: 5555e53
crates/ec-ac3/src/aht.rsmodified+3 -10
@@ -107,10 +107,10 @@ pub(crate) fn read_channel(
107107 let mut next_gain = 0usize;
108108 for bin in start..end {
109109 let h = hebap[bin];
110- let mut zero_bits = false;
111110 if h == 0 {
112- pre = [0.0; AHT_BLOCKS];
113- zero_bits = true;
111+ for slot in &mut pre {
112+ *slot = if dither_on { dither.value() } else { 0.0 };
113+ }
114114 } else if h <= 7 {
115115 let index = r.read_bits(VQ_BITS[h as usize])? as usize;
116116 let table = vq_table(h);
@@ -131,13 +131,6 @@ pub(crate) fn read_channel(
131131 }
132132 }
133133
134- if zero_bits {
135- // A zero-bit AHT bin is the same silence AC-3 fills with dither.
136- for blk in 0..AHT_BLOCKS {
137- out[blk * COEFFS + bin] = if dither_on { dither.value() } else { 0.0 };
138- }
139- continue;
140- }
141134 // §3.4.5: invert the six-point DCT across blocks.
142135 for (blk, slot) in idct6(&pre).into_iter().enumerate() {
143136 out[blk * COEFFS + bin] = slot;
crates/ec-ac3/src/mantissa.rsmodified+4 -2
@@ -50,9 +50,11 @@ impl Default for Dither {
5050 }
5151
5252 impl Dither {
53- /// Next dither value, uniform in ±0.707 (ffmpeg's mantissa scaled by 2^-23).
53+ /// Next AHT zero-bit dither, uniform in ±0.5: ffmpeg's raw word
54+ /// `(w & 0x7fffff) - 0x400000` scaled by 2^-23.
5455 pub fn value(&mut self) -> f32 {
55- self.mantissa() as f32 / 8_388_608.0
56+ let x = self.next_word() & 0x7f_ffff;
57+ (x as i32 - 0x40_0000) as f32 / 8_388_608.0
5658 }
5759
5860 /// ffmpeg's integer dither mantissa: `((x >> 8) * 181 >> 8) - 5931008`.