forge
Explore
Log in

Don't you dare go Hollow

U10: ec-aac drop env experiments (EC_AAC_SBR_BW_SCALE, CHIRP_SMOOTH, BW_DUMP, ENV_DEBUG; defaults kept) and dead band_shift_correction

Browse files at this commit

ade9b5453e2d48576fe156dbeee2a0f4b25b23dbAhmet Kaan GümüşParent: 6c331af
crates/ec-aac/src/sbr_hf.rsmodified+9 -126
@@ -57,64 +57,6 @@
57 use crate::sbr_bands::BandTables;57 use crate::sbr_bands::BandTables;
58 use ec_dsp::Complex;58 use ec_dsp::Complex;
59 59
60-/// Characterizes (but, as of round-37, is deliberately NOT applied to) a QMF
61-/// bank convention gap `sbr_qmf`'s round-trip tuning never exercised:
62-/// replaying a source band's raw complex series into a *different* synthesis
63-/// band (exactly what patch copying does) lands the content at the "wrong"
64-/// absolute frequency by exactly one synthesis-band width whenever
65-/// `target_band - source_band` is odd, with the sign flipping every other
66-/// odd step -- i.e. a period-4 pattern in `target - source` (even
67-/// difference: no error; `+1 mod 4`: content lands one band flat; `+3 mod
68-/// 4`: one band sharp). `sbr_qmf::Synthesis`'s modulation kernel centres
69-/// band `k` at `(k+0.5) * pi/(2*SYNTHESIS_BANDS)` via a phase intercept that
70-/// is itself `(k+0.5) * pi/4` -- exactly the odd-stacked cosine-modulated-
71-/// bank convention the round-trip test tuned for same-band replay, where
72-/// this intercept cancels against the receiving band's own reconstruction.
73-///
74-/// Round-35 had `generate` counter-rotate the patched series by this amount
75-/// before it reaches `Synthesis`, and proved (in isolation, via a
76-/// stationary-tone FFT probe through the actual production call site --
77-/// `sbr_qmf::tests::patch_replay_through_generate_preserves_absolute_frequency_mapping`)
78-/// that doing so restores textbook-coherent absolute-frequency placement.
79-/// Round-36/37's real-file mechanical A/B (`EC_AAC_SBR_PARITY_SPLIT`)
80-/// showed applying that correction REGRESSES odd-gap coherence against the
81-/// reference decoder (ch0 0.1907->0.0714, ch1 0.2461->0.0741; a
82-/// sign-flipped variant and a half-rate variant both regress it too, to
83-/// 0.0757 and 0.1449 respectively on ch0) -- the reference apparently
84-/// reproduces this same "wrong" convention itself, so leaving the raw copy
85-/// unrotated is what actually matches it. This function is kept (and
86-/// pinned by its own unit tests) purely to document that convention as
87-/// intentional, not to be called from `generate`'s patch-copy site.
88-///
89-/// Round-46 raised a re-trial candidate: `EC_AAC_SBR_PARITY_SPLIT` (an 8-bin
90-/// STFT metric) had been suspected untrustworthy at this precision, and a
91-/// QMF-exact fit of the reference decoder's own HF content on patch
92-/// `(3,28,11)` (gap 25, `mod 4 == 1`) found a transfer with this function's
93-/// quarter-turn phase signature. Round-47 re-applied the rotation at
94-/// `generate`'s patch-copy site (env-gated, both signs) and re-judged with
95-/// `EC_AAC_SBR_QMF_WITNESS`'s own QMF-domain coherence table instead of the
96-/// STFT one -- the trustworthy instrument the re-trial was chartered to use.
97-/// Both signs made sim-vs-ours coherence on patch `(3,28,11)` WORSE, not
98-/// better (band28 0.2628 unrotated -> 0.0161 rotated -> 0.0282 flipped;
99-/// band38 0.0669 -> 0.0694 -> 0.1068), moving further from the reference's
100-/// 0.42-0.79 rather than toward it, refuting round-46's fit-based
101-/// prediction under the very instrument that was supposed to vindicate it.
102-/// (One sign did nudge whole-file full-band correlation up rather than
103-/// round-36's dip, but that's moot once the witness itself disagrees.) The
104-/// verdict stands as round-37 left it: `generate`'s patch-copy site keeps
105-/// the plain, unrotated copy.
106-/// Returns the signed number of `pi/2` quarter-turns per QMF slot that
107-/// *would* need to be applied to restore frequency-pure placement.
108-#[allow(dead_code)] // documentation of the characterized convention; tests call it
109-pub(crate) fn band_shift_correction(_target_band: usize, _source_band: usize) -> i64 {
110- // The fitted Kaiser bank's odd-stacked convention needed a per-slot
111- // quarter-turn correction here (see the doc above); the normative
112- // ISO/IEC 14496-3 4.6.18.4/4.6.18.8.2 QMF pair in `sbr_qmf` carries its
113- // own correct phase from the spec equations directly, so patching needs
114- // no extra rotation at this site.
115- 0
116-}
117-
118 /// One copy-up patch: `width` consecutive QMF bands starting at60 /// One copy-up patch: `width` consecutive QMF bands starting at
119 /// `source_start` are written to `target_start..target_start+width`.61 /// `source_start` are written to `target_start..target_start+width`.
120 #[derive(Clone, Copy, Debug, PartialEq, Eq)]62 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -283,40 +225,18 @@ impl ChirpState {
283 225
284 /// Advances the state one frame given this frame's `bs_invf_mode` per226 /// Advances the state one frame given this frame's `bs_invf_mode` per
285 /// noise band, returning the smoothed bw to use for HF generation.227 /// noise band, returning the smoothed bw to use for HF generation.
286- ///
287- /// (Round-22 sweep instrumentation, zero cost unset) `EC_AAC_SBR_BW_SCALE`
288- /// scales the chirp target globally (clamped below 1.0) before
289- /// smoothing, to probe whether the chirp/inverse-filter strength is
290- /// miscalibrated on real content. `EC_AAC_SBR_CHIRP_SMOOTH=none` skips
291- /// the attack/release smoothing entirely (target used immediately);
292- /// `=swap` swaps which curve (0.75/0.25 vs 0.90625/0.09375) applies to
293- /// rising vs falling bw, to probe whether the asymmetry is backwards.
294 pub fn update(&mut self, invf_mode: &[u8]) -> &[f64] {228 pub fn update(&mut self, invf_mode: &[u8]) -> &[f64] {
295- let scale = bw_scale_override();
296- let smooth = chirp_smooth_mode();
297 for ((slot, prev), &mode) in self.bw.iter_mut().zip(&mut self.prev_mode).zip(invf_mode) {229 for ((slot, prev), &mode) in self.bw.iter_mut().zip(&mut self.prev_mode).zip(invf_mode) {
298- let target = (bw_target(mode, *prev) * scale).min(0.999_999);230+ let target = bw_target(mode, *prev).min(0.999_999);
299 *prev = mode;231 *prev = mode;
300- *slot = match smooth {232+ // 4.6.18.6.3 bwArray smoothing: both branches weight the
301- ChirpSmooth::None => target,233+ // NEW value (0.75 falling, 0.90625 rising). The rising
302- ChirpSmooth::Current => {234+ // branch previously had the operands swapped (0.09375
303- // 4.6.18.6.3 bwArray smoothing: both branches weight the235+ // of the new value), making every rise ~10x too slow.
304- // NEW value (0.75 falling, 0.90625 rising). The rising236+ *slot = if target < *slot {
305- // branch previously had the operands swapped (0.09375237+ 0.75 * target + 0.25 * *slot
306- // of the new value), making every rise ~10x too slow.238+ } else {
307- if target < *slot {239+ 0.90625 * target + 0.09375 * *slot
308- 0.75 * target + 0.25 * *slot
309- } else {
310- 0.90625 * target + 0.09375 * *slot
311- }
312- }
313- ChirpSmooth::Swap => {
314- if target < *slot {
315- 0.90625 * target + 0.09375 * *slot
316- } else {
317- 0.75 * *slot + 0.25 * target
318- }
319- }
320 };240 };
321 // 4.6.18.6.3: a smoothed bw under 0.015 is forced to zero.241 // 4.6.18.6.3: a smoothed bw under 0.015 is forced to zero.
322 if *slot < 0.015 {242 if *slot < 0.015 {
@@ -327,32 +247,6 @@ impl ChirpState {
327 }247 }
328 }248 }
329 249
330-/// `EC_AAC_SBR_BW_SCALE` global multiplier on the chirp target, clamped below 1.0
331-/// (a chirp target at or past 1.0 is an undamped all-pole resonance, not a
332-/// meaningful "stronger" whitening). `1.0` (no-op) when unset or unparsable.
333-fn bw_scale_override() -> f64 {
334- std::env::var("EC_AAC_SBR_BW_SCALE")
335- .ok()
336- .and_then(|s| s.parse::<f64>().ok())
337- .map(|s| s.max(0.0))
338- .unwrap_or(1.0)
339-}
340-
341-#[derive(Clone, Copy, PartialEq, Eq)]
342-enum ChirpSmooth {
343- None,
344- Current,
345- Swap,
346-}
347-
348-fn chirp_smooth_mode() -> ChirpSmooth {
349- match std::env::var("EC_AAC_SBR_CHIRP_SMOOTH").as_deref() {
350- Ok("none") => ChirpSmooth::None,
351- Ok("swap") => ChirpSmooth::Swap,
352- _ => ChirpSmooth::Current,
353- }
354-}
355-
356 /// Order-2 linear-prediction coefficients per ISO 14496-3 4.6.18.6.2250 /// Order-2 linear-prediction coefficients per ISO 14496-3 4.6.18.6.2
357 /// (covariance method, `phi(i,j) = sum_n x[n-i]*conj(x[n-j])` over251 /// (covariance method, `phi(i,j) = sum_n x[n-i]*conj(x[n-j])` over
358 /// `n = 2..x.len()`, index 0 of `x` is the oldest slot). Returns the spec's252 /// `n = 2..x.len()`, index 0 of `x` is the oldest slot). Returns the spec's
@@ -464,13 +358,6 @@ pub fn generate(
464 lpc2(&ext)358 lpc2(&ext)
465 };359 };
466 let g = bw[noise_band_of(target_band)];360 let g = bw[noise_band_of(target_band)];
467- // (Round-46, Task 2) `EC_AAC_SBR_BW_DUMP` -- one line per patched
468- // band per frame with the smoothed chirp bw actually applied,
469- // to compare against the QMF-domain fitted reference transfer
470- // (`hf_patch_transfer_fit` in the real-file test).
471- if std::env::var("EC_AAC_SBR_BW_DUMP").is_ok() {
472- eprintln!("BW_DUMP target_band={target_band} source_band={source_band} bw={g:.6}");
473- }
474 // 4.6.18.6.3 feed-forward: X_high = X_low + bw*alpha0*X_low[l-1]361 // 4.6.18.6.3 feed-forward: X_high = X_low + bw*alpha0*X_low[l-1]
475 // + bw^2*alpha1*X_low[l-2]. bw=0 is a plain copy, bw->1 is the362 // + bw^2*alpha1*X_low[l-2]. bw=0 is a plain copy, bw->1 is the
476 // full inverse (whitening) filter. The all-pole recursion this363 // full inverse (whitening) filter. The all-pole recursion this
@@ -493,10 +380,6 @@ pub fn generate(
493 };380 };
494 let dst = &mut out[target_band - kx];381 let dst = &mut out[target_band - kx];
495 for (n, &x) in series.iter().enumerate() {382 for (n, &x) in series.iter().enumerate() {
496- // Round-37 (Task 2): `band_shift_correction` is proven exact
497- // in isolation but a real-file A/B (`EC_AAC_SBR_PARITY_SPLIT`)
498- // shows applying it REGRESSES odd-gap coherence against the
499- // reference; `dst` stays the uncorrected band placement.
500 dst[n] = x + c1 * x_prev1 + c2 * x_prev2;383 dst[n] = x + c1 * x_prev1 + c2 * x_prev2;
501 x_prev2 = x_prev1;384 x_prev2 = x_prev1;
502 x_prev1 = x;385 x_prev1 = x;
crates/ec-aac/src/sbr_payload.rsmodified+0 -5
@@ -443,11 +443,6 @@ impl SbrParser {
443 row[b] = (row[b - 1] + delta).clamp(0, cap);443 row[b] = (row[b - 1] + delta).clamp(0, cap);
444 }444 }
445 }445 }
446- if std::env::var("EC_AAC_SBR_ENV_DEBUG").is_ok() {
447- eprintln!(
448- "ENVDBG dt={dt} balance={balance} amp_res={amp_res} bands={bands} prev={prev:?} row={row:?}"
449- );
450- }
451 Ok(row)446 Ok(row)
452 }447 }
453 448