U10: ec-aac he_parity: compare the five FATE SBR files against ffmpeg at test time, before tests/sbr_real_library is deleted
Browse files at this commite3bba2b2520d4237b4382f55156014ab92ad9f7cParent: 41510f01 changed file +55 -13
crates/ec-aac/tests/it/he_parity.rsmodified+55 -13
| @@ -3,8 +3,7 @@ | |||
| 3 | //! Fixtures live in `tests/data/he/` and are generated by `scripts/aac-tables/make-he-fixtures.sh`. | 3 | //! Fixtures live in `tests/data/he/` and are generated by `scripts/aac-tables/make-he-fixtures.sh`. |
| 4 | //! Each stream is written as ADTS (`.aac`) and MP4 (`.m4a`). The reference is FFmpeg's own decode | 4 | //! Each stream is written as ADTS (`.aac`) and MP4 (`.m4a`). The reference is FFmpeg's own decode |
| 5 | //! of the `.aac`, stored next to it as signed 16-bit little-endian PCM (`.s16`), in FFmpeg's channel | 5 | //! of the `.aac`, stored next to it as signed 16-bit little-endian PCM (`.s16`), in FFmpeg's channel |
| 6 | -//! count and order. Nothing here runs FFmpeg, so the test needs neither FFmpeg nor the fdk-aac | 6 | +//! count and order. The FATE files are decoded by FFmpeg at test time. |
| 7 | -//! library. | ||
| 8 | //! | 7 | //! |
| 9 | //! Acceptance: every channel of every container must correlate with the matching reference channel | 8 | //! Acceptance: every channel of every container must correlate with the matching reference channel |
| 10 | //! at least `MIN_CORR` at the best lag in `-LAG_MAX..=LAG_MAX`, and the channel count and sample rate | 9 | //! 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) { | |||
| 126 | (best.0, correlation(a, b)) | 125 | (best.0, correlation(a, b)) |
| 127 | } | 126 | } |
| 128 | 127 | ||
| 128 | +const FATE_FILES: &[&str] = &[ | ||
| 129 | + "open/fate/aac/al_sbr_cm_48_2.mp4", | ||
| 130 | + "open/fate/aac/al_sbr_cm_48_5.1.mp4", | ||
| 131 | + "open/fate/aac/al_sbr_ps_04_new.mp4", | ||
| 132 | + "open/fate/aac/al_sbr_ps_06_new.mp4", | ||
| 133 | + "open/fate/aac/al_sbr_sr_48_2_fsaac48.mp4", | ||
| 134 | +]; | ||
| 135 | + | ||
| 136 | +fn ffmpeg_decode(path: &Path, channels: usize) -> Vec<Vec<f32>> { | ||
| 137 | + let out = ec_testkit::ffmpeg() | ||
| 138 | + .args(["-v", "error", "-i"]) | ||
| 139 | + .arg(path) | ||
| 140 | + .args(["-map", "0:0", "-f", "f32le", "-acodec", "pcm_f32le", "-"]) | ||
| 141 | + .output() | ||
| 142 | + .expect("ffmpeg runs"); | ||
| 143 | + assert!(out.status.success(), "ffmpeg decode failed: {}", String::from_utf8_lossy(&out.stderr)); | ||
| 144 | + let samples: Vec<f32> = out | ||
| 145 | + .stdout | ||
| 146 | + .as_chunks::<4>() | ||
| 147 | + .0 | ||
| 148 | + .iter() | ||
| 149 | + .map(|c| f32::from_le_bytes(*c)) | ||
| 150 | + .collect(); | ||
| 151 | + deinterleave(&samples, channels) | ||
| 152 | +} | ||
| 153 | + | ||
| 154 | +fn check_channels(label: &str, ours: &[Vec<f32>], theirs: &[Vec<f32>], failures: &mut Vec<String>) { | ||
| 155 | + for ch in 0..ours.len() { | ||
| 156 | + let (lag, corr) = best_lag(&ours[ch], &theirs[ch]); | ||
| 157 | + println!( | ||
| 158 | + "he {label} ch{ch}: ours {} frames, ffmpeg {} frames, lag {lag}, corr {corr:.6}", | ||
| 159 | + ours[ch].len(), | ||
| 160 | + theirs[ch].len() | ||
| 161 | + ); | ||
| 162 | + if corr < MIN_CORR { | ||
| 163 | + failures.push(format!("{label} ch{ch}: corr {corr:.6} < {MIN_CORR}")); | ||
| 164 | + } | ||
| 165 | + } | ||
| 166 | +} | ||
| 167 | + | ||
| 168 | +#[test] | ||
| 169 | +fn fate_sbr_fixtures_match_ffmpeg_per_channel() { | ||
| 170 | + let mut failures = Vec::new(); | ||
| 171 | + for rel in FATE_FILES { | ||
| 172 | + let path = ec_testkit::fixture(rel); | ||
| 173 | + let (channels, _, samples) = decode_m4a(&path); | ||
| 174 | + let ours = deinterleave(&samples, usize::from(channels)); | ||
| 175 | + let theirs = ffmpeg_decode(&path, usize::from(channels)); | ||
| 176 | + check_channels(rel, &ours, &theirs, &mut failures); | ||
| 177 | + } | ||
| 178 | + assert!(failures.is_empty(), "HE-AAC does not match ffmpeg:\n{}", failures.join("\n")); | ||
| 179 | +} | ||
| 180 | + | ||
| 129 | #[test] | 181 | #[test] |
| 130 | fn he_fixtures_match_ffmpeg_per_channel() { | 182 | fn he_fixtures_match_ffmpeg_per_channel() { |
| 131 | let mut failures = Vec::new(); | 183 | let mut failures = Vec::new(); |
| @@ -145,17 +197,7 @@ fn he_fixtures_match_ffmpeg_per_channel() { | |||
| 145 | continue; | 197 | continue; |
| 146 | } | 198 | } |
| 147 | let ours = deinterleave(&samples, fixture.channels); | 199 | let ours = deinterleave(&samples, fixture.channels); |
| 148 | - for ch in 0..fixture.channels { | 200 | + check_channels(&label, &ours, &theirs, &mut failures); |
| 149 | - let (lag, corr) = best_lag(&ours[ch], &theirs[ch]); | ||
| 150 | - println!( | ||
| 151 | - "he {label} ch{ch}: ours {} frames, ffmpeg {} frames, lag {lag}, corr {corr:.6}", | ||
| 152 | - ours[ch].len(), | ||
| 153 | - theirs[ch].len() | ||
| 154 | - ); | ||
| 155 | - if corr < MIN_CORR { | ||
| 156 | - failures.push(format!("{label} ch{ch}: corr {corr:.6} < {MIN_CORR}")); | ||
| 157 | - } | ||
| 158 | - } | ||
| 159 | } | 201 | } |
| 160 | } | 202 | } |
| 161 | assert!(failures.is_empty(), "HE-AAC does not match ffmpeg:\n{}", failures.join("\n")); | 203 | assert!(failures.is_empty(), "HE-AAC does not match ffmpeg:\n{}", failures.join("\n")); |