From e3bba2b2520d4237b4382f55156014ab92ad9f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 13:33:27 +0300 Subject: [PATCH] U10: ec-aac he_parity: compare the five FATE SBR files against ffmpeg at test time, before tests/sbr_real_library is deleted --- crates/ec-aac/tests/it/he_parity.rs | 68 +++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/crates/ec-aac/tests/it/he_parity.rs b/crates/ec-aac/tests/it/he_parity.rs index 47dd5eff..cc1f543b 100644 --- a/crates/ec-aac/tests/it/he_parity.rs +++ b/crates/ec-aac/tests/it/he_parity.rs @@ -3,8 +3,7 @@ //! Fixtures live in `tests/data/he/` and are generated by `scripts/aac-tables/make-he-fixtures.sh`. //! Each stream is written as ADTS (`.aac`) and MP4 (`.m4a`). The reference is FFmpeg's own decode //! of the `.aac`, stored next to it as signed 16-bit little-endian PCM (`.s16`), in FFmpeg's channel -//! count and order. Nothing here runs FFmpeg, so the test needs neither FFmpeg nor the fdk-aac -//! library. +//! count and order. The FATE files are decoded by FFmpeg at test time. //! //! Acceptance: every channel of every container must correlate with the matching reference channel //! at least `MIN_CORR` at the best lag in `-LAG_MAX..=LAG_MAX`, and the channel count and sample rate @@ -126,6 +125,59 @@ fn best_lag(ours: &[f32], theirs: &[f32]) -> (i64, f64) { (best.0, correlation(a, b)) } +const FATE_FILES: &[&str] = &[ + "open/fate/aac/al_sbr_cm_48_2.mp4", + "open/fate/aac/al_sbr_cm_48_5.1.mp4", + "open/fate/aac/al_sbr_ps_04_new.mp4", + "open/fate/aac/al_sbr_ps_06_new.mp4", + "open/fate/aac/al_sbr_sr_48_2_fsaac48.mp4", +]; + +fn ffmpeg_decode(path: &Path, channels: usize) -> Vec> { + let out = ec_testkit::ffmpeg() + .args(["-v", "error", "-i"]) + .arg(path) + .args(["-map", "0:0", "-f", "f32le", "-acodec", "pcm_f32le", "-"]) + .output() + .expect("ffmpeg runs"); + assert!(out.status.success(), "ffmpeg decode failed: {}", String::from_utf8_lossy(&out.stderr)); + let samples: Vec = out + .stdout + .as_chunks::<4>() + .0 + .iter() + .map(|c| f32::from_le_bytes(*c)) + .collect(); + deinterleave(&samples, channels) +} + +fn check_channels(label: &str, ours: &[Vec], theirs: &[Vec], failures: &mut Vec) { + for ch in 0..ours.len() { + let (lag, corr) = best_lag(&ours[ch], &theirs[ch]); + println!( + "he {label} ch{ch}: ours {} frames, ffmpeg {} frames, lag {lag}, corr {corr:.6}", + ours[ch].len(), + theirs[ch].len() + ); + if corr < MIN_CORR { + failures.push(format!("{label} ch{ch}: corr {corr:.6} < {MIN_CORR}")); + } + } +} + +#[test] +fn fate_sbr_fixtures_match_ffmpeg_per_channel() { + let mut failures = Vec::new(); + for rel in FATE_FILES { + let path = ec_testkit::fixture(rel); + let (channels, _, samples) = decode_m4a(&path); + let ours = deinterleave(&samples, usize::from(channels)); + let theirs = ffmpeg_decode(&path, usize::from(channels)); + check_channels(rel, &ours, &theirs, &mut failures); + } + assert!(failures.is_empty(), "HE-AAC does not match ffmpeg:\n{}", failures.join("\n")); +} + #[test] fn he_fixtures_match_ffmpeg_per_channel() { let mut failures = Vec::new(); @@ -145,17 +197,7 @@ fn he_fixtures_match_ffmpeg_per_channel() { continue; } let ours = deinterleave(&samples, fixture.channels); - for ch in 0..fixture.channels { - let (lag, corr) = best_lag(&ours[ch], &theirs[ch]); - println!( - "he {label} ch{ch}: ours {} frames, ffmpeg {} frames, lag {lag}, corr {corr:.6}", - ours[ch].len(), - theirs[ch].len() - ); - if corr < MIN_CORR { - failures.push(format!("{label} ch{ch}: corr {corr:.6} < {MIN_CORR}")); - } - } + check_channels(&label, &ours, &theirs, &mut failures); } } assert!(failures.is_empty(), "HE-AAC does not match ffmpeg:\n{}", failures.join("\n"));