From c39572eec7b33fbeef548d3028d638aa19e1bba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 20 Aug 2026 06:37:02 +0300 Subject: [PATCH] probe(sbr): parity-split direct-coherence instrument, even-gap vs odd-gap territory EC_AAC_SBR_PARITY_SPLIT reports bin_level_conviction's direct-coherence mean separately for header A's even-gap patch territory (bands 14..28, from (0,14,14), already exact before round-35) and its odd-gap territory (bands 28..43, from (3,28,11)/(0,39,3)/(13,42,1), where round-35's Synthesis phase-intercept correction landed) -- the region split the full-band/HF "direct" numbers can't see (odd-gap bands are ~15 of ~100 total HF bands, swamped by even-gap's dominant energy in any energy-weighted metric). Round-36 before/after (git-checked-out src at HEAD~1 vs HEAD, same real file): odd-gap direct coherence REGRESSES sharply after round-35's fix (ch0 0.1907->0.0714, ch1 0.2461->0.0741) while even-gap stays flat (ch0 0.1526->0.1510, ch1 0.1848->0.1749) -- the opposite of the charter's "odd-gap improves" expectation. bw=0 (EC_AAC_SBR_BW_SCALE=0) moves neither region (ch0 even 0.1517/odd 0.0707, ch1 even 0.1745/odd 0.0727, both indistinguishable from bw=1), exonerating the chirp/whitening IIR as the cause of either number. --- crates/ec-aac/tests/sbr_real_library.rs | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/crates/ec-aac/tests/sbr_real_library.rs b/crates/ec-aac/tests/sbr_real_library.rs index bac8f8d4..cce9bf82 100644 --- a/crates/ec-aac/tests/sbr_real_library.rs +++ b/crates/ec-aac/tests/sbr_real_library.rs @@ -1426,6 +1426,44 @@ fn sbr_real_library_matches_reference() { ); } } + // (Round-36, Task 2) parity-split coherence: round-35 fixed the + // Synthesis phase-intercept bug only for ODD (target-source) + // patch gaps, at the patch-copy site. On header A (the real + // file's own header) that fix can only be SEEN in the odd-gap + // territory those patches cover (bands 28..42, from patches + // (3,28,11)/(0,39,3)/(13,42,1)); the even-gap patch (0,14,14) + // covers bands 14..27 and was already exact before round-35, so + // it is the control range the fix must NOT move. Reuses + // `bin_level_conviction`'s per-bin direct-coherence measurement + // over every HF band in [14, 43) (min_band=14, top_n wide enough + // to keep every band, not just the top-energy handful), then + // averages `direct` within each region separately. + if std::env::var("EC_AAC_SBR_PARITY_SPLIT").is_ok() && n >= 4_096 { + let band_hz = f64::from(rate) / 256.0; + let win = &o[oa..oa + n]; + let twin = &t[ob..ob + n]; + let rows = bin_level_conviction(win, twin, rate, 14, 29); + let mean_in = |lo: usize, hi: usize| { + let vals: Vec = rows + .iter() + .filter(|(hz, ..)| { + let band = (hz / band_hz).round() as usize; + band >= lo && band < hi + }) + .map(|(_, _, direct, ..)| *direct) + .collect(); + if vals.is_empty() { + (0.0, 0) + } else { + (vals.iter().sum::() / vals.len() as f64, vals.len()) + } + }; + let (even_mean, even_n) = mean_in(14, 28); + let (odd_mean, odd_n) = mean_in(28, 43); + println!( + " ch{ch} PARITY-SPLIT direct-coherence mean: even-gap[14,28)={even_mean:.4} (n={even_n}) odd-gap[28,43)={odd_mean:.4} (n={odd_n})" + ); + } println!( " ch{ch}: lag {lag}, full {full:.6}, below {:.0}Hz {low:.6}, above {:.0}Hz {high:.6}", c.crossover_hz, c.crossover_hz