probe(sbr): parity-split direct-coherence instrument, even-gap vs odd-gap territory
Browse files at this commitc39572eec7b33fbeef548d3028d638aa19e1bba9Parent: 2f5c8e21 changed file +38 -0
crates/ec-aac/tests/sbr_real_library.rsmodified+38 -0
| @@ -1426,6 +1426,44 @@ fn sbr_real_library_matches_reference() { | |||
| 1426 | ); | 1426 | ); |
| 1427 | } | 1427 | } |
| 1428 | } | 1428 | } |
| 1429 | + // (Round-36, Task 2) parity-split coherence: round-35 fixed the | ||
| 1430 | + // Synthesis phase-intercept bug only for ODD (target-source) | ||
| 1431 | + // patch gaps, at the patch-copy site. On header A (the real | ||
| 1432 | + // file's own header) that fix can only be SEEN in the odd-gap | ||
| 1433 | + // territory those patches cover (bands 28..42, from patches | ||
| 1434 | + // (3,28,11)/(0,39,3)/(13,42,1)); the even-gap patch (0,14,14) | ||
| 1435 | + // covers bands 14..27 and was already exact before round-35, so | ||
| 1436 | + // it is the control range the fix must NOT move. Reuses | ||
| 1437 | + // `bin_level_conviction`'s per-bin direct-coherence measurement | ||
| 1438 | + // over every HF band in [14, 43) (min_band=14, top_n wide enough | ||
| 1439 | + // to keep every band, not just the top-energy handful), then | ||
| 1440 | + // averages `direct` within each region separately. | ||
| 1441 | + if std::env::var("EC_AAC_SBR_PARITY_SPLIT").is_ok() && n >= 4_096 { | ||
| 1442 | + let band_hz = f64::from(rate) / 256.0; | ||
| 1443 | + let win = &o[oa..oa + n]; | ||
| 1444 | + let twin = &t[ob..ob + n]; | ||
| 1445 | + let rows = bin_level_conviction(win, twin, rate, 14, 29); | ||
| 1446 | + let mean_in = |lo: usize, hi: usize| { | ||
| 1447 | + let vals: Vec<f64> = rows | ||
| 1448 | + .iter() | ||
| 1449 | + .filter(|(hz, ..)| { | ||
| 1450 | + let band = (hz / band_hz).round() as usize; | ||
| 1451 | + band >= lo && band < hi | ||
| 1452 | + }) | ||
| 1453 | + .map(|(_, _, direct, ..)| *direct) | ||
| 1454 | + .collect(); | ||
| 1455 | + if vals.is_empty() { | ||
| 1456 | + (0.0, 0) | ||
| 1457 | + } else { | ||
| 1458 | + (vals.iter().sum::<f64>() / vals.len() as f64, vals.len()) | ||
| 1459 | + } | ||
| 1460 | + }; | ||
| 1461 | + let (even_mean, even_n) = mean_in(14, 28); | ||
| 1462 | + let (odd_mean, odd_n) = mean_in(28, 43); | ||
| 1463 | + println!( | ||
| 1464 | + " 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})" | ||
| 1465 | + ); | ||
| 1466 | + } | ||
| 1429 | println!( | 1467 | println!( |
| 1430 | " ch{ch}: lag {lag}, full {full:.6}, below {:.0}Hz {low:.6}, above {:.0}Hz {high:.6}", | 1468 | " ch{ch}: lag {lag}, full {full:.6}, below {:.0}Hz {low:.6}, above {:.0}Hz {high:.6}", |
| 1431 | c.crossover_hz, c.crossover_hz | 1469 | c.crossover_hz, c.crossover_hz |