forge
Explore
Log in

Don't you dare go Hollow

The SBR "second-half collapse" was a mismatched-split test artifact

Browse files at this commit

8bdf7f541d65a555354158ba7e8cbb3c5d9041cdAhmet Kaan GümüşParent: 0fb1dc2
  • fix
    • the SBR "second-half collapse" was a mismatched-split test artifact
Show full message
fix(ec-aac): the SBR "second-half collapse" was a mismatched-split test artifact

sbr_real_library's SWEEP_SEGMENT diagnostic sliced ours/theirs at their
own independent len()/2, but ours is capped at MAX_SAMPLES while the
reference decodes the file in full (30s vs our 22.7s on reeln) --
so the "second half" compared ours' 11.35s-22.7s against the
reference's 15.0s-30.0s, two different passages 3.6s apart, reading as
a catastrophic collapse (~-0.01 corr) with no decode defect behind it.
Splitting both sides at the shorter side's midpoint fixes it (0.981/
0.976 full-band). A new whole-file corr-vs-time timeline (windowed
local-lag search, EC_AAC_SBR_TIMELINE) confirms there is no sustained
mid-file collapse on reeln: 0.958/0.954 mean windowed corr across
all 22.7s, dipping briefly (~0.2s) only near t=0 and t=20.2s.
crates/ec-aac/tests/sbr_real_library.rsmodified+52 -1
@@ -1058,9 +1058,23 @@ fn sbr_real_library_matches_reference() {
1058 // the second half of the file instead of the first, so a1058 // the second half of the file instead of the first, so a
1059 // calibration candidate can be checked on two disjoint segments1059 // calibration candidate can be checked on two disjoint segments
1060 // rather than just the file's start.1060 // rather than just the file's start.
1061+ //
1062+ // (Round-23) The split point MUST be the same absolute sample
1063+ // index on both sides, not each side's own `len() / 2`: `ours`
1064+ // is capped at MAX_SAMPLES while `theirs` (the reference) is
1065+ // decoded in full, so on a file longer than the cap `o_full` and
1066+ // `t_full` have different total lengths and an independent
1067+ // `len() / 2` on each picks DIFFERENT seconds of the file --
1068+ // reeln is a 30s file capped to ours=22.7s, so the old code
1069+ // compared ours' 11.35s-22.7s against theirs' 15.0s-30.0s, a
1070+ // 3.6s-misaligned pair of unrelated passages that reads as a
1071+ // catastrophic collapse (~-0.01 corr) with no decode defect
1072+ // behind it. Splitting both sides at the shorter side's midpoint
1073+ // keeps the two halves pointed at the same audio.
1061 let (o, t): (&[f32], &[f32]) =1074 let (o, t): (&[f32], &[f32]) =
1062 if std::env::var("EC_AAC_SBR_SWEEP_SEGMENT").as_deref() == Ok("1") {1075 if std::env::var("EC_AAC_SBR_SWEEP_SEGMENT").as_deref() == Ok("1") {
1063- (&o_full[o_full.len() / 2..], &t_full[t_full.len() / 2..])1076+ let half = o_full.len().min(t_full.len()) / 2;
1077+ (&o_full[half..], &t_full[half..])
1064 } else {1078 } else {
1065 (&o_full[..], &t_full[..])1079 (&o_full[..], &t_full[..])
1066 };1080 };
@@ -1188,6 +1202,43 @@ fn sbr_real_library_matches_reference() {
1188 println!(" w{w}: lag {l} corr {cr:.4}");1202 println!(" w{w}: lag {l} corr {cr:.4}");
1189 }1203 }
1190 }1204 }
1205+ // (Round-23, Task 1/3) whole-file corr-vs-time timeline: the
1206+ // DRIFT diagnostic above caps at 20 windows (~1.85s) starting at
1207+ // the full-band lag offset near sample 0, so it never sees a
1208+ // collapse that only appears later in the file. This walks
1209+ // every 4096-sample window from that same start to EOF on BOTH
1210+ // sides, with its own local lag search per window, so a
1211+ // mid-file onset shows up as a specific window index/timestamp
1212+ // instead of being averaged away inside one giant WINDOW-sized
1213+ // correlation. The mean/min across every window is also the
1214+ // TRUE whole-file correlation number (`best_lag_correlation`
1215+ // above only ever measures one WINDOW=200_000-sample slice
1216+ // starting near the file's first quarter): unlike that one
1217+ // fixed-lag figure, this one is immune to a single global lag
1218+ // being slightly wrong for a later part of the file.
1219+ {
1220+ let avail = o.len().saturating_sub(oa).min(t.len().saturating_sub(ob));
1221+ let windows = avail / 4_096;
1222+ let timeline = windowed_lag_drift(o, t, oa, ob, windows);
1223+ if std::env::var("EC_AAC_SBR_TIMELINE").is_ok() {
1224+ println!(
1225+ " ch{ch} TIMELINE ({windows} windows, {rate} Hz, window_idx@sec, local_lag, corr):"
1226+ );
1227+ for (w, (l, cr)) in timeline.iter().enumerate() {
1228+ let t_sec = (oa + w * 4_096) as f64 / f64::from(rate);
1229+ println!(" w{w}@{t_sec:.2}s: lag {l} corr {cr:.4}");
1230+ }
1231+ }
1232+ if !timeline.is_empty() {
1233+ let mean = timeline.iter().map(|(_, c)| c).sum::<f64>() / timeline.len() as f64;
1234+ let min = timeline.iter().map(|(_, c)| *c).fold(f64::MAX, f64::min);
1235+ println!(
1236+ " ch{ch} WHOLE-FILE windowed corr: mean {mean:.6} min {min:.6} over {} windows ({:.2}s)",
1237+ timeline.len(),
1238+ windows as f64 * 4_096.0 / f64::from(rate)
1239+ );
1240+ }
1241+ }
1191 if std::env::var("EC_AAC_SBR_RESIDUAL_DEBUG").is_ok() {1242 if std::env::var("EC_AAC_SBR_RESIDUAL_DEBUG").is_ok() {
1192 residual_sideinfo_analysis(o, t, oa, ob, rate, ch);1243 residual_sideinfo_analysis(o, t, oa, ob, rate, ch);
1193 }1244 }