forge
Explore
Log in

Don't you dare go Hollow

ec-ac3 E-AC-3 SPX noise: match ffmpeg eac3dec.c. Root cause: noise came from a separate LFG (decode.rs spx_noise) and was the integer dither mantissa scaled by sqrt(3); ffmpeg draws the raw word from the shared dith_state as (int32)w * nblend*rms*coord/INT32_MIN with nblend=sqrt(3*nratio) (ac3dec.c spx_coordinates, eac3dec.c apply_spectral_extension). Fix: nblend=sqrt(3*nratio), noise from core.dither.next_word(). Evidence: csi_miami_5.1_256_spx_small.eac3 was ch0 rms 6.2e-5, ch2 1.6e-3, ch3 corr 0.9978; unrun, orchestrator to verify

Browse files at this commit

5555e532904f76cee98f4e3edd56ba19b4f40c28Ahmet Kaan GümüşParent: 61f297e
crates/ec-ac3/src/decode.rsmodified+0 -4
@@ -118,9 +118,6 @@ pub(crate) struct Core {
118118 pub(crate) first_spxco: [bool; MAX_FBW],
119119 pub(crate) chinspxatten: [bool; MAX_FBW],
120120 pub(crate) spxattencod: [u8; MAX_FBW],
121- /// The noise source of §3.6.4.2.4, kept apart from the dither source so
122- /// neither one's sequence depends on the other's use.
123- pub(crate) spx_noise: Dither,
124121 // Adaptive hybrid transform (Annex E §3.4). All false under AC-3.
125122 /// Which channels are AHT-coded this frame.
126123 pub(crate) aht: [bool; CHANNELS],
@@ -190,7 +187,6 @@ impl Core {
190187 first_spxco: [true; MAX_FBW],
191188 chinspxatten: [false; MAX_FBW],
192189 spxattencod: [0; MAX_FBW],
193- spx_noise: Dither::default(),
194190 aht: [false; CHANNELS],
195191 aht_read: [false; CHANNELS],
196192 aht_mant: vec![0.0; CHANNELS * crate::aht::AHT_BLOCKS * COEFFS],
crates/ec-ac3/src/eac3.rsmodified+2 -5
@@ -781,7 +781,7 @@ fn parse_block(
781781 // §3.6.4.2.1: the blend follows the band's frequency midpoint.
782782 let bandsize = core.spxbndsz[bnd] as f32;
783783 let nratio = ((spxmant + 0.5 * bandsize) / end - spxblnd).clamp(0.0, 1.0);
784- core.nblend[ch][bnd] = nratio.sqrt();
784+ core.nblend[ch][bnd] = (3.0 * nratio).sqrt();
785785 core.sblend[ch][bnd] = (1.0 - nratio).sqrt();
786786 spxmant += bandsize;
787787 }
@@ -1191,11 +1191,8 @@ fn spectral_extension(core: &mut Core, ch: usize) {
11911191 if spxmant >= COEFFS {
11921192 break;
11931193 }
1194- // §E3.6.4.2.4's noise(): a zero-mean unit-variance source the
1195- // standard leaves to the implementation, so it is switched by the
1196- // same option as §7.3.4's dither.
11971194 let noise = if core.dither_on {
1198- core.spx_noise.unit_variance()
1195+ (core.dither.next_word() as i32) as f32 / -2_147_483_648.0
11991196 } else {
12001197 0.0
12011198 };
crates/ec-ac3/src/mantissa.rsmodified+1 -8
@@ -55,13 +55,6 @@ impl Dither {
5555 self.mantissa() as f32 / 8_388_608.0
5656 }
5757
58- /// Next value from a zero-mean, unit-variance source — what Annex E
59- /// §3.6.4.2.4 calls `noise()`. A uniform distribution on `[-1, 1]` has
60- /// variance 1/3, so it is scaled by `sqrt(3)`.
61- pub fn unit_variance(&mut self) -> f32 {
62- self.mantissa() as f32 / 5_931_008.0 * 1.732_050_8
63- }
64-
6558 /// ffmpeg's integer dither mantissa: `((x >> 8) * 181 >> 8) - 5931008`.
6659 pub fn mantissa(&mut self) -> i32 {
6760 let x = self.next_word();
@@ -70,7 +63,7 @@ impl Dither {
7063 }
7164
7265 /// `av_lfg_get`: `state[i] = state[i-24] + state[i-55]`, returning the new word.
73- fn next_word(&mut self) -> u32 {
66+ pub fn next_word(&mut self) -> u32 {
7467 let i = self.index & 63;
7568 let v = self.state[(i + 40) & 63].wrapping_add(self.state[(i + 9) & 63]);
7669 self.state[i] = v;