From dccdbb8091c2f44f82ae0ac6108666df847ca1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 23 Aug 2026 17:32:26 +0300 Subject: [PATCH] test(aac/sbr): noise-fraction anchor summed core bands into a "whole-HF" ratio `sbr_actual_noise_fraction` is env-gated (it sets process env vars mid-run, which is unsound alongside parallel tests), so no default run executes it. Run by hand it FAILED: "whole-HF realized noise fraction regressed to 0.0397 (round-44 fix floor is 0.17)". Nothing regressed. Every band above the crossover realizes 0.15-0.27 of its energy as injected noise, right where round-42/44 left it; the total was diluted. `bin_level_conviction`'s rows start at `MIN_BAND` = 14 on ITS band scale (rate/256, so ~2412 Hz), while this stream's crossover is QMF band 14 on the OTHER scale (rate/128, 4823 Hz) -- the same integer, two scales. The dozen core-decoded rows that opens with carry an order of magnitude more energy than the SBR-generated ones (6.4e4 vs ~5e3) and, by definition, zero injected noise, so averaging them in dragged the ratio to 0.0397. The total now starts at the stream's own crossover, taken from the lowest QMF band the bookkeeping table holds (which IS `kx`), so a future QMF-mapping change cannot silently invalidate it the way a constant did. It reads 0.1774 -- round-44 measured 0.1770 on this file -- and the assertion passes untouched at its original 0.17 floor. Noise injection is also still doing work: zeroing it costs 0.000847 of full-band correlation against the reference. Both anchors' SKIP lines now print the exact command that runs them, since being invisible to default runs is what let a stale instrument sit unread. `sbr_instrument_anchor_controls` was run too, and passes: ours-vs-ours 1.0000, reference-vs-remux 1.0000, reference vs itself at a 64-sample offset 0.9317 mean / 0.3323 min (the coherence floor the instrument itself imposes). Suite: 16 passed, 0 failed (54.1s). --- crates/ec-aac/tests/sbr_real_library.rs | 27 +++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/ec-aac/tests/sbr_real_library.rs b/crates/ec-aac/tests/sbr_real_library.rs index 1beacdf6..cddc1f35 100644 --- a/crates/ec-aac/tests/sbr_real_library.rs +++ b/crates/ec-aac/tests/sbr_real_library.rs @@ -3392,7 +3392,10 @@ fn report_conviction(label: &str, rows: &[(f64, f64, f64, f64, f64, f64)]) { #[test] fn sbr_instrument_anchor_controls() { if std::env::var("EC_AAC_SBR_INSTRUMENT_ANCHOR").is_err() { - eprintln!("SKIP: set EC_AAC_SBR_INSTRUMENT_ANCHOR=1 to run (round-41 Task 1)"); + eprintln!( + "SKIP (round-41 Task 1): EC_AAC_SBR_INSTRUMENT_ANCHOR=1 cargo test -p ec-aac \ + --release --test sbr_real_library sbr_instrument_anchor_controls -- --nocapture" + ); return; } if !have_ffmpeg() { @@ -3468,7 +3471,12 @@ fn sbr_instrument_anchor_controls() { #[test] fn sbr_actual_noise_fraction() { if std::env::var("EC_AAC_SBR_NOISE_ANCHOR").is_err() { - eprintln!("SKIP: set EC_AAC_SBR_NOISE_ANCHOR=1 to run (round-41 Task 2)"); + eprintln!( + "SKIP (round-41 Task 2): EC_AAC_SBR_NOISE_ANCHOR=1 cargo test -p ec-aac \ + --release --test sbr_real_library sbr_actual_noise_fraction -- \ + --nocapture --test-threads=1 (env-gated because it sets process \ + env vars mid-run, which is unsound alongside parallel tests)" + ); return; } if !have_ffmpeg() { @@ -3528,6 +3536,8 @@ fn sbr_actual_noise_fraction() { // not a decoder coverage gap (verified: `noise_fraction_table()` itself // has nonzero entries for QMF bands up to `k2`). let band_hz = f64::from(rate) / 128.0; + let kx_band = bookkept.iter().map(|(b, ..)| *b).min().unwrap_or(0); + println!(" (crossover: QMF band {kx_band}, {:.0} Hz -- rows below it are core-decoded and excluded from the total)", kx_band as f64 * band_hz); println!( " ACTUAL noise fraction (band_hz, energy_on, energy_off, actual_fraction, bookkept_fraction):" ); @@ -3553,6 +3563,19 @@ fn sbr_actual_noise_fraction() { println!( " {hz:>6.0}Hz: on {e_on:.3e} off {e_off:.3e} actual {actual:.4} bookkept {book:.4}" ); + // HF ONLY (round-61): `MIN_BAND` (14, ~2412 Hz at 44.1k) sits BELOW + // this stream's crossover (~4500 Hz), so the row list opens with a + // dozen core-decoded bands that carry an order of magnitude more + // energy than the SBR-generated ones (6.4e4 vs ~5e3) and, by + // definition, zero injected noise. Summing them into a "whole-HF" + // ratio dilutes it toward zero -- that is how this metric read + // 0.0397 while every band above the crossover was realizing + // 0.15-0.27. The crossover comes from the bookkeeping table itself + // (its lowest QMF band IS `kx`), so it tracks the stream instead of + // a constant that a QMF-mapping change can invalidate. + if band < kx_band { + continue; + } sum_on += e_on; sum_delta += e_on - e_off; }