forge
Explore
Log in

Don't you dare go Hollow

Add coupled-CPE L/R swap probe for the 44.1k implicit-family break

Browse files at this commit

96300274e1e218bc0a202ab876a0298f1b467955Ahmet Kaan GümüşParent: aadc033
  • test
    • add coupled-CPE L/R swap probe for the 44.1k implicit-family break
Show full message
test(aac-sbr): add coupled-CPE L/R swap probe for the 44.1k implicit-family break

Ledger charter asked why implicit-output-rate-ASC 44.1k HE-AAC fixtures
break the full SBR chain while their core-only decode is fine. Root cause
found, not where the charter expected: heaac_44100_48k.m4a's SBR side info
shows bs_coupling=1 on almost every AU (reeln/FMJ, both passing, show
coupling=false) -- coupling, not the 44.1k rate family, is the actual
discriminant refuted rate-family theories missed.

coupled_cpe_channel_swap_probe decodes both channels and correlates each
against the reference's L and R separately: our ch0 reads 0.98 correlated
with the REFERENCE's RIGHT channel (ch1 with its LEFT) at a fixed lag --
the full chain's stereo output is L/R-swapped for this file. The
core-only (SBR-disabled) decode of the same file is NOT swapped (ch0 vs
ref L 0.83 > ch0 vs ref R 0.72), so the swap is introduced somewhere in
the SBR chain specifically for coupled CPEs, not the AAC-LC core.

Tried and reverted: swapping dequant_pair's left/right assignment in
sbr_env::dequantize_frame's coupling branch (the textbook suspect for a
coupled-CPE channel swap) measurably changed nothing -- rebuilt twice,
identical correlation to 6 decimals -- so the swap site is elsewhere in
the SBR chain (sbr_chain.rs's per-tag/per-ch wiring, or sbr_payload's CPE
channel read order) and is still open. Left as a dead-end + reproducible
instrument rather than shipping an unverified fix.
crates/ec-aac/tests/sbr_real_library.rsmodified+69 -0
@@ -3866,3 +3866,72 @@ fn reelq_multichannel_lc_matches_reference() {
3866 assert!(corr >= 0.999, "ch{ch} corr {corr:.6} < 0.999 (lag {lag})");3866 assert!(corr >= 0.999, "ch{ch} corr {corr:.6} < 0.999 (lag {lag})");
3867 }3867 }
3868 }3868 }
3869+
3870+/// Coupled-CPE swap probe: the `heaac_44100_48k` fixture's SBR side info
3871+/// shows `coupling: true` on nearly every AU (reeln/FMJ, both passing,
3872+/// show `coupling: false`) -- checks whether our decoded ch0 actually
3873+/// correlates better against the REFERENCE's R channel than its own L,
3874+/// which would mean `dequant_pair`'s left/right assignment in
3875+/// `sbr_env::dequantize_frame` is swapped for coupled CPEs.
3876+#[test]
3877+fn coupled_cpe_channel_swap_probe() {
3878+ if !have_ffmpeg() {
3879+ eprintln!("SKIP: ffmpeg not on PATH");
3880+ return;
3881+ }
3882+ let dir = std::env::var("EC_AAC_HEAAC_FIXTURES").unwrap_or_else(|_| {
3883+ format!("{}/../../.cache/heaac-fixtures", env!("CARGO_MANIFEST_DIR"))
3884+ });
3885+ let path = PathBuf::from(&dir).join("heaac_44100_48k.m4a");
3886+ if !path.exists() {
3887+ eprintln!("SKIP: {} absent", path.display());
3888+ return;
3889+ }
3890+ let Some((ours, sbr, _rate)) = our_decode(&path, 0) else {
3891+ panic!("heaac_44100_48k failed to decode");
3892+ };
3893+ assert_eq!(sbr, ec_aac::SbrSupport::V1);
3894+ assert_eq!(ours.len(), 2, "expect stereo");
3895+ let ref_l = ffmpeg_decode_pan_channel(&path, 0, 0);
3896+ let ref_r = ffmpeg_decode_pan_channel(&path, 0, 1);
3897+ for (och, ochan) in ours.iter().enumerate() {
3898+ let (lag_l, corr_l) = best_lag_correlation_wide(ochan, &ref_l, SEARCH_LAG_MAX);
3899+ let (lag_r, corr_r) = best_lag_correlation_wide(ochan, &ref_r, SEARCH_LAG_MAX);
3900+ println!(
3901+ "ch{och}: vs ref L lag={lag_l} corr={corr_l:.6}; vs ref R lag={lag_r} corr={corr_r:.6}"
3902+ );
3903+ }
3904+
3905+ // Same probe on the CORE-ONLY decode (SBR disabled): if the swap
3906+ // already shows here, it's in the AAC-LC core's own CPE/M-S decode,
3907+ // not in the SBR coupling math.
3908+ let (asc, aus) = extract_aac_track(&path, 0).expect("extract");
3909+ let mut core_cfg = parse_audio_specific_config(&asc).expect("asc parses");
3910+ core_cfg.sbr_present = false;
3911+ core_cfg.ps_present = false;
3912+ core_cfg.extension_sample_rate = None;
3913+ let mut core_dec = AacDecoder::with_config(core_cfg);
3914+ let mut core_planes: Vec<Vec<f32>> = vec![Vec::new(), Vec::new()];
3915+ for au in &aus {
3916+ if let Ok(f) = core_dec.decode(au, None) {
3917+ let ch = usize::from(f.channels);
3918+ if ch == 2 {
3919+ for (i, v) in f.samples.iter().enumerate() {
3920+ core_planes[i % 2].push(*v);
3921+ }
3922+ }
3923+ }
3924+ if core_planes[0].len() >= MAX_SAMPLES {
3925+ break;
3926+ }
3927+ }
3928+ let core_rate = core_dec.output_sample_rate().unwrap_or(22050);
3929+ let ref_core = ffmpeg_decode_at_rate(&path, 0, 2, core_rate);
3930+ for (och, ochan) in core_planes.iter().enumerate() {
3931+ for (rch, rplane) in ref_core.iter().enumerate() {
3932+ let (lag, corr) = best_lag_correlation_wide(ochan, rplane, SEARCH_LAG_MAX);
3933+ let name = if rch == 0 { "L" } else { "R" };
3934+ println!("core ch{och} vs ref {name}: lag={lag} corr={corr:.6}");
3935+ }
3936+ }
3937+}