From 6432e088c0dc1d9bc768d2bc01f6010bfcb54baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 14 Aug 2026 12:52:31 +0300 Subject: [PATCH] fix(ac3): switch the spectral extension noise with the dither option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit §E3.6.4.2.4's noise() is a zero-mean unit-variance source the standard leaves to the implementation, exactly like §7.3.4's dither: two conformant decoders differ by it and by nothing else. It now follows the same option, so a comparison against another decoder can isolate what the standard does specify, and the default still generates both. On the Dolby Digital Plus track that uses spectral extension this is the whole remaining difference: 0.9988 per-channel correlation with both decoders' noise in, 0.9994 with it out. --- crates/ec-ac3/src/decoder.rs | 15 +++++++++------ crates/ec-ac3/src/lib.rs | 16 ++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/crates/ec-ac3/src/decoder.rs b/crates/ec-ac3/src/decoder.rs index 804e333a..7847681f 100644 --- a/crates/ec-ac3/src/decoder.rs +++ b/crates/ec-ac3/src/decoder.rs @@ -38,13 +38,16 @@ pub struct Options { pub drc_scale: f32, /// Channel folding, off by default. pub downmix: Downmix, - /// Substitute pseudo-random noise for zero-bit mantissas (§7.3.4), which - /// is what the standard asks a decoder to do and what this defaults to. + /// Generate the pseudo-random noise the format asks for: dither in place + /// of zero-bit mantissas (§7.3.4) and the blend that fills the spectral + /// extension band (§E3.6.4.2.4). On by default, because both are what the + /// standard asks a decoder to do. /// - /// The sequence itself is implementation-defined ("any reasonably random - /// sequence"), so two conformant decoders differ by exactly this noise; - /// turning it off is how a comparison against another decoder isolates - /// everything else. + /// Neither sequence is specified — §7.3.4 says "any reasonably random + /// sequence" and §E3.6.4.2.4 just names a zero-mean unit-variance source — + /// so two conformant decoders differ by exactly this noise and nothing + /// else. Turning it off is how a comparison against another decoder + /// isolates everything that *is* specified. pub dither: bool, } diff --git a/crates/ec-ac3/src/lib.rs b/crates/ec-ac3/src/lib.rs index dc3cfe8e..981ff3d3 100644 --- a/crates/ec-ac3/src/lib.rs +++ b/crates/ec-ac3/src/lib.rs @@ -24,19 +24,19 @@ //! it down or off. //! - **Dialogue normalisation is surfaced, never applied.** §7.6 puts //! `dialnorm` in the volume control, which is not in this crate. -//! - **Dither is on by default** (§7.3.4) but its sequence is -//! implementation-defined, so two conformant decoders differ by exactly that -//! noise; [`Options::dither`] turns it off when a comparison needs to +//! - **The noise this format asks for is on by default**: dither for zero-bit +//! mantissas (§7.3.4) and the spectral extension blend (§E3.6.4.2.4). Neither +//! sequence is specified, so two conformant decoders differ by exactly that +//! noise; [`Options::dither`] turns both off when a comparison needs to //! isolate everything else. //! //! Annex E coverage: the adaptive hybrid transform (with its vector and //! gain-adaptive quantizers) and spectral extension are decoded; enhanced //! coupling and dependent substreams above 5.1 are refused by name rather than -//! decoded wrongly. On a real Dolby Digital Plus stream that uses AHT and -//! spectral extension the output tracks ffmpeg's to a per-channel correlation -//! of 0.994 rather than the 0.9999 the rest of the format reaches — the -//! remaining difference is in the AHT quantizer detail and the two decoders' -//! independent noise sources. +//! decoded wrongly. On a real Dolby Digital Plus stream that uses both, the +//! coded bins land within 0.01% of ffmpeg's energy and the whole channel within +//! 0.999 correlation once the two decoders' independent noise is taken out of +//! the comparison ([`Options::dither`]). //! //! No unsafe, no allocation on the block path beyond the output buffer, and no //! dependencies beyond the family IR and DSP crates.