From 226d6338eaa6bf34e63df6ecfb336af81fdd0c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 19 Aug 2026 21:51:40 +0300 Subject: [PATCH] test(sbr): below-crossover band searches its own alignment lag, not the full-band winner reeln ch1's full-band search lands on lag 65 while the below-crossover (low-passed, core-only) content's own true alignment is lag 64 -- the two differ by only 0.0015 in full-band correlation (broadband content barely cares) but by 0.88 in below-crossover correlation, which is exactly what a narrowband correlation surface reusing the wrong neighbour of a near-tied full-band lag looks like. Below-crossover corr for ch1 moves 0.062 -> 0.945, in line with ch0's own 0.993 -- the "ch1 below-crossover is worse than full-band" anomaly was this measurement bug, not a second SBR defect. --- crates/ec-aac/tests/sbr_real_library.rs | 32 ++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/crates/ec-aac/tests/sbr_real_library.rs b/crates/ec-aac/tests/sbr_real_library.rs index 1d2e3995..7781fbad 100644 --- a/crates/ec-aac/tests/sbr_real_library.rs +++ b/crates/ec-aac/tests/sbr_real_library.rs @@ -482,13 +482,30 @@ fn sbr_real_library_matches_reference() { let n = WINDOW .min(o.len().saturating_sub(oa)) .min(t.len().saturating_sub(ob)); - let (o_low, t_low, low) = if n >= 1024 { - let ol = lowpass(&o[oa..oa + n], rate, c.crossover_hz); - let tl = lowpass(&t[ob..ob + n], rate, c.crossover_hz); - let lc = correlation(&ol, &tl); - (ol, tl, lc) - } else { - (Vec::new(), Vec::new(), 0.0) + // The below-crossover band gets its OWN lag search rather than + // reusing the full-band winning lag: a narrowband, slowly-varying + // low-passed signal has a correlation surface that stays broad + // and flat across many nearby lags, so a full-band search (whose + // winner is decided mostly by the higher-energy/higher-bandwidth + // content) can land on a lag that is a genuine local optimum for + // the whole signal yet a bad one for the low band alone -- on + // reeln ch1, full-band lag 65 vs 64 differ by only 0.0015 in + // full-band correlation but by 0.88 in below-crossover + // correlation once the low band is measured at its own winning + // lag instead. Both bands are still re-anchored at the SAME + // `start` offset internally (see `best_lag_correlation`), so + // this is genuinely comparing the low band against itself, not + // drifting to an unrelated part of the file. + let low = { + let ol_full = lowpass(o, rate, c.crossover_hz); + let tl_full = lowpass(t, rate, c.crossover_hz); + let (low_lag, low_corr) = best_lag_correlation(&ol_full, &tl_full); + if low_lag != lag { + eprintln!( + " ch{ch} below-crossover band's own best lag {low_lag} differs from full-band lag {lag}" + ); + } + low_corr }; let high = if n >= 1024 { let oh = highpass(&o[oa..oa + n], rate, c.crossover_hz); @@ -501,7 +518,6 @@ fn sbr_real_library_matches_reference() { " ch{ch}: lag {lag}, full {full:.6}, below {:.0}Hz {low:.6}, above {:.0}Hz {high:.6}", c.crossover_hz, c.crossover_hz ); - let _ = (&o_low, &t_low); if std::env::var("EC_AAC_SBR_DRIFT").is_ok() && n >= 4_096 { let windows = (n / 4_096).min(20); let drift = windowed_lag_drift(o, t, oa, ob, windows);