diff --git a/crates/ec-ac3/src/decode.rs b/crates/ec-ac3/src/decode.rs index 4d7bf94e..1a2de760 100644 --- a/crates/ec-ac3/src/decode.rs +++ b/crates/ec-ac3/src/decode.rs @@ -118,9 +118,6 @@ pub(crate) struct Core { pub(crate) first_spxco: [bool; MAX_FBW], pub(crate) chinspxatten: [bool; MAX_FBW], pub(crate) spxattencod: [u8; MAX_FBW], - /// The noise source of §3.6.4.2.4, kept apart from the dither source so - /// neither one's sequence depends on the other's use. - pub(crate) spx_noise: Dither, // Adaptive hybrid transform (Annex E §3.4). All false under AC-3. /// Which channels are AHT-coded this frame. pub(crate) aht: [bool; CHANNELS], @@ -190,7 +187,6 @@ impl Core { first_spxco: [true; MAX_FBW], chinspxatten: [false; MAX_FBW], spxattencod: [0; MAX_FBW], - spx_noise: Dither::default(), aht: [false; CHANNELS], aht_read: [false; CHANNELS], aht_mant: vec![0.0; CHANNELS * crate::aht::AHT_BLOCKS * COEFFS], diff --git a/crates/ec-ac3/src/eac3.rs b/crates/ec-ac3/src/eac3.rs index 254e3870..d66712ed 100644 --- a/crates/ec-ac3/src/eac3.rs +++ b/crates/ec-ac3/src/eac3.rs @@ -781,7 +781,7 @@ fn parse_block( // §3.6.4.2.1: the blend follows the band's frequency midpoint. let bandsize = core.spxbndsz[bnd] as f32; let nratio = ((spxmant + 0.5 * bandsize) / end - spxblnd).clamp(0.0, 1.0); - core.nblend[ch][bnd] = nratio.sqrt(); + core.nblend[ch][bnd] = (3.0 * nratio).sqrt(); core.sblend[ch][bnd] = (1.0 - nratio).sqrt(); spxmant += bandsize; } @@ -1191,11 +1191,8 @@ fn spectral_extension(core: &mut Core, ch: usize) { if spxmant >= COEFFS { break; } - // §E3.6.4.2.4's noise(): a zero-mean unit-variance source the - // standard leaves to the implementation, so it is switched by the - // same option as §7.3.4's dither. let noise = if core.dither_on { - core.spx_noise.unit_variance() + (core.dither.next_word() as i32) as f32 / -2_147_483_648.0 } else { 0.0 }; diff --git a/crates/ec-ac3/src/mantissa.rs b/crates/ec-ac3/src/mantissa.rs index 99d2d472..e71fc466 100644 --- a/crates/ec-ac3/src/mantissa.rs +++ b/crates/ec-ac3/src/mantissa.rs @@ -55,13 +55,6 @@ impl Dither { self.mantissa() as f32 / 8_388_608.0 } - /// Next value from a zero-mean, unit-variance source — what Annex E - /// §3.6.4.2.4 calls `noise()`. A uniform distribution on `[-1, 1]` has - /// variance 1/3, so it is scaled by `sqrt(3)`. - pub fn unit_variance(&mut self) -> f32 { - self.mantissa() as f32 / 5_931_008.0 * 1.732_050_8 - } - /// ffmpeg's integer dither mantissa: `((x >> 8) * 181 >> 8) - 5931008`. pub fn mantissa(&mut self) -> i32 { let x = self.next_word(); @@ -70,7 +63,7 @@ impl Dither { } /// `av_lfg_get`: `state[i] = state[i-24] + state[i-55]`, returning the new word. - fn next_word(&mut self) -> u32 { + pub fn next_word(&mut self) -> u32 { let i = self.index & 63; let v = self.state[(i + 40) & 63].wrapping_add(self.state[(i + 9) & 63]); self.state[i] = v;