diff --git a/crates/ec-ac3/src/aht.rs b/crates/ec-ac3/src/aht.rs index 325e951a..6d11f16c 100644 --- a/crates/ec-ac3/src/aht.rs +++ b/crates/ec-ac3/src/aht.rs @@ -107,10 +107,10 @@ pub(crate) fn read_channel( let mut next_gain = 0usize; for bin in start..end { let h = hebap[bin]; - let mut zero_bits = false; if h == 0 { - pre = [0.0; AHT_BLOCKS]; - zero_bits = true; + for slot in &mut pre { + *slot = if dither_on { dither.value() } else { 0.0 }; + } } else if h <= 7 { let index = r.read_bits(VQ_BITS[h as usize])? as usize; let table = vq_table(h); @@ -131,13 +131,6 @@ pub(crate) fn read_channel( } } - if zero_bits { - // A zero-bit AHT bin is the same silence AC-3 fills with dither. - for blk in 0..AHT_BLOCKS { - out[blk * COEFFS + bin] = if dither_on { dither.value() } else { 0.0 }; - } - continue; - } // §3.4.5: invert the six-point DCT across blocks. for (blk, slot) in idct6(&pre).into_iter().enumerate() { out[blk * COEFFS + bin] = slot; diff --git a/crates/ec-ac3/src/mantissa.rs b/crates/ec-ac3/src/mantissa.rs index e71fc466..e9d14afe 100644 --- a/crates/ec-ac3/src/mantissa.rs +++ b/crates/ec-ac3/src/mantissa.rs @@ -50,9 +50,11 @@ impl Default for Dither { } impl Dither { - /// Next dither value, uniform in ±0.707 (ffmpeg's mantissa scaled by 2^-23). + /// Next AHT zero-bit dither, uniform in ±0.5: ffmpeg's raw word + /// `(w & 0x7fffff) - 0x400000` scaled by 2^-23. pub fn value(&mut self) -> f32 { - self.mantissa() as f32 / 8_388_608.0 + let x = self.next_word() & 0x7f_ffff; + (x as i32 - 0x40_0000) as f32 / 8_388_608.0 } /// ffmpeg's integer dither mantissa: `((x >> 8) * 181 >> 8) - 5931008`.