Merge branch 'aac-main-ltp'
Browse files at this commit1 changed file +74 -0
crates/ec-aac/tests/sbr_real_library.rsmodified+74 -0
| @@ -3431,3 +3431,77 @@ fn sbr_header_feature_table() { | |||
| 3431 | ); | 3431 | ); |
| 3432 | } | 3432 | } |
| 3433 | } | 3433 | } |
| 3434 | + | ||
| 3435 | +/// One channel of `path`'s given absolute stream, isolated with an ffmpeg | ||
| 3436 | +/// `pan` filter rather than raw de-interleaving -- the charter's own witness | ||
| 3437 | +/// rule (see `ffmpeg_decode`'s doc and the ledger's "never use -ac 1", which | ||
| 3438 | +/// applies just as much to picking one of N channels as to downmixing). | ||
| 3439 | +fn ffmpeg_decode_pan_channel(path: &Path, absolute_stream: usize, channel: usize) -> Vec<f32> { | ||
| 3440 | + let out = Command::new("ffmpeg") | ||
| 3441 | + .args(["-v", "error", "-i"]) | ||
| 3442 | + .arg(path) | ||
| 3443 | + .args([ | ||
| 3444 | + "-map", | ||
| 3445 | + &format!("0:{absolute_stream}"), | ||
| 3446 | + "-t", | ||
| 3447 | + "10", | ||
| 3448 | + "-af", | ||
| 3449 | + &format!("pan=1c|c0=c{channel}"), | ||
| 3450 | + "-f", | ||
| 3451 | + "f32le", | ||
| 3452 | + "-acodec", | ||
| 3453 | + "pcm_f32le", | ||
| 3454 | + "-", | ||
| 3455 | + ]) | ||
| 3456 | + .output() | ||
| 3457 | + .expect("ffmpeg runs"); | ||
| 3458 | + assert!( | ||
| 3459 | + out.status.success(), | ||
| 3460 | + "ffmpeg pan decode failed: {}", | ||
| 3461 | + String::from_utf8_lossy(&out.stderr) | ||
| 3462 | + ); | ||
| 3463 | + out.stdout | ||
| 3464 | + .chunks_exact(4) | ||
| 3465 | + .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]])) | ||
| 3466 | + .collect() | ||
| 3467 | +} | ||
| 3468 | + | ||
| 3469 | +/// The user's real 7.1 mp4 whose lone AAC track was once suspected (per the | ||
| 3470 | +/// ledger) to need AAC Main/LTP (§4.6.6/§4.6.7) prediction support this | ||
| 3471 | +/// decoder doesn't have. Re-checked here: its AudioSpecificConfig's | ||
| 3472 | +/// `audioObjectType` is 2 (AAC-LC, confirmed both from the container's ASC | ||
| 3473 | +/// bytes and from the ADTS `profile` field ffmpeg remuxes it to), and this | ||
| 3474 | +/// decoder in fact reads its whole ~994s track -- 45000+ access units -- | ||
| 3475 | +/// with zero `Err` returns. No `predictor_data_present` refusal is reachable | ||
| 3476 | +/// on this file; the capability gap the ledger recorded does not exist for | ||
| 3477 | +/// it. This test is the standing proof: it decodes 10s of all 8 channels and | ||
| 3478 | +/// checks each against ffmpeg's own decode, isolated per channel by `pan` | ||
| 3479 | +/// (never `-ac 1`, which would remix rather than isolate). | ||
| 3480 | +#[test] | ||
| 3481 | +fn reelq_multichannel_lc_matches_reference() { | ||
| 3482 | + if !have_ffmpeg() { | ||
| 3483 | + eprintln!("SKIP: ffmpeg not on PATH"); | ||
| 3484 | + return; | ||
| 3485 | + } | ||
| 3486 | + let home = std::env::var("HOME").unwrap_or_default(); | ||
| 3487 | + let path = PathBuf::from(format!( | ||
| 3488 | + "{home}/Downloads/reelq/reelq.mp4" | ||
| 3489 | + )); | ||
| 3490 | + if !path.exists() { | ||
| 3491 | + eprintln!("SKIP: {} not present", path.display()); | ||
| 3492 | + return; | ||
| 3493 | + } | ||
| 3494 | + let Some((ours, _sbr, rate)) = our_decode(&path, 0) else { | ||
| 3495 | + panic!("ReelQ AAC track failed to decode at all"); | ||
| 3496 | + }; | ||
| 3497 | + assert_eq!(ours.len(), 8, "expected 7.1 (8 channels)"); | ||
| 3498 | + let want = (rate as usize) * 10; // 10s per the charter | ||
| 3499 | + for (ch, o) in ours.iter().enumerate() { | ||
| 3500 | + let o = &o[..o.len().min(want)]; | ||
| 3501 | + let t = ffmpeg_decode_pan_channel(&path, 2, ch); | ||
| 3502 | + let t = &t[..t.len().min(want)]; | ||
| 3503 | + let (lag, corr) = best_lag_correlation(o, t); | ||
| 3504 | + println!("ReelQ ch{ch}: lag {lag}, corr {corr:.6}"); | ||
| 3505 | + assert!(corr >= 0.999, "ch{ch} corr {corr:.6} < 0.999 (lag {lag})"); | ||
| 3506 | + } | ||
| 3507 | +} | ||