forge
Explore
Log in

Don't you dare go Hollow

Per-second dropout gate in the library sweep

Browse files at this commit

4174c4b54c00d447b807bba1699e8e00c007d273Ahmet Kaan GümüşParent: 30a832c
  • test
    • per-second dropout gate in the library sweep
Show full message
test(vorbis): per-second dropout gate in the library sweep

A post-transient silence is invisible in whole-file corr and bimodal per second,
so the sweep now traces corr per second and fails any row with a second under
0.9 where libvorbis is not. Proven both ways on reelm.wav: main 0 dropout
seconds (min-second .911/.934 vs ref .927/.950); reservoir disabled 357/295
seconds, min-second .117.
crates/ec-vorbis/tests/oracle.rsmodified+27 -8
@@ -1169,7 +1169,7 @@ fn real_library_sweep_vs_reference() {
1169 let max_samples = rate as usize * 600;1169 let max_samples = rate as usize * 600;
1170 let out_dir = scratch().join("vorbis7-sweep");1170 let out_dir = scratch().join("vorbis7-sweep");
1171 std::fs::create_dir_all(&out_dir).expect("out dir");1171 std::fs::create_dir_all(&out_dir).expect("out dir");
1172- let mut table = String::from("source kbps ours_kbps ref_kbps rate% corr_ours corr_ref gap verdict\n");1172+ let mut table = String::from("source kbps ours_kbps ref_kbps rate% corr_ours corr_ref gap minsec_o minsec_r drops verdict\n");
1173 let mut failures = Vec::new();1173 let mut failures = Vec::new();
1174 let only = std::env::var("SWEEP_ONLY").ok();1174 let only = std::env::var("SWEEP_ONLY").ok();
1175 for &(name, src_path) in sources {1175 for &(name, src_path) in sources {
@@ -1204,20 +1204,39 @@ fn real_library_sweep_vs_reference() {
1204 let ours = encode_to_file(&source_pcm, rate, (ref_kbps * 1000.0).round() as i32, &format!("vorbis7-sweep/ours-{name}-{kbps}k.ogg"));1204 let ours = encode_to_file(&source_pcm, rate, (ref_kbps * 1000.0).round() as i32, &format!("vorbis7-sweep/ours-{name}-{kbps}k.ogg"));
1205 let ours_kbps = bytes(&ours) * 8.0 / seconds / 1000.0;1205 let ours_kbps = bytes(&ours) * 8.0 / seconds / 1000.0;
1206 let rate_pct = (ours_kbps / ref_kbps - 1.0) * 100.0;1206 let rate_pct = (ours_kbps / ref_kbps - 1.0) * 100.0;
1207- let corr_of = |p: &Path| -> f64 {1207+ // Whole-file corr plus a per-second trace: a dropout (the
1208+ // rate-loop windup class, 200 ms silences after transients) is
1209+ // invisible in the mean and bimodal per second, so it is gated
1210+ // as "seconds where ours is under 0.9 and the reference is not".
1211+ let corr_of = |p: &Path| -> (f64, Vec<f64>) {
1208 let (pcm, _) = our_decode(p);1212 let (pcm, _) = our_decode(p);
1209 let n = pcm[0].len().min(source_pcm[0].len());1213 let n = pcm[0].len().min(source_pcm[0].len());
1210- (0..2).map(|c| correlation(&pcm[c][..n], &source_pcm[c][..n])).sum::<f64>() / 2.01214+ let mean = (0..2).map(|c| correlation(&pcm[c][..n], &source_pcm[c][..n])).sum::<f64>() / 2.0;
1215+ let step = rate as usize;
1216+ let per_second = (0..n / step)
1217+ .map(|s| {
1218+ let r = s * step..(s + 1) * step;
1219+ (0..2).map(|c| correlation(&pcm[c][r.clone()], &source_pcm[c][r.clone()])).sum::<f64>() / 2.0
1220+ })
1221+ .collect();
1222+ (mean, per_second)
1211 };1223 };
1212- let corr_ours = corr_of(&ours);1224+ let (corr_ours, sec_ours) = corr_of(&ours);
1213- let corr_ref = corr_of(&reference);1225+ let (corr_ref, sec_ref) = corr_of(&reference);
1214 let gap = corr_ref - corr_ours;1226 let gap = corr_ref - corr_ours;
1215- let pass = rate_pct.abs() <= 3.0 && gap <= 0.005;1227+ let min_of = |v: &[f64]| v.iter().copied().fold(1.0f64, f64::min);
1228+ let (min_ours, min_ref) = (min_of(&sec_ours), min_of(&sec_ref));
1229+ let dropouts = sec_ours
1230+ .iter()
1231+ .zip(&sec_ref)
1232+ .filter(|(o, r)| **o < 0.9 && **r >= 0.9)
1233+ .count();
1234+ let pass = rate_pct.abs() <= 3.0 && gap <= 0.005 && dropouts == 0;
1216 if !pass {1235 if !pass {
1217- failures.push(format!("{name}@{kbps}k rate {rate_pct:+.2}% gap {gap:.4}"));1236+ failures.push(format!("{name}@{kbps}k rate {rate_pct:+.2}% gap {gap:.4} dropouts {dropouts}"));
1218 }1237 }
1219 table.push_str(&format!(1238 table.push_str(&format!(
1220- "{name:<7} {kbps:<6} {ours_kbps:<9.1} {ref_kbps:<8.1} {rate_pct:+6.2} {corr_ours:<9.4} {corr_ref:<8.4} {gap:<7.4} {}\n",1239+ "{name:<7} {kbps:<6} {ours_kbps:<9.1} {ref_kbps:<8.1} {rate_pct:+6.2} {corr_ours:<9.4} {corr_ref:<8.4} {gap:<7.4} {min_ours:<8.3} {min_ref:<7.3} {dropouts:<5} {}\n",
1221 if pass { "PASS" } else { "FAIL" }1240 if pass { "PASS" } else { "FAIL" }
1222 ));1241 ));
1223 eprintln!("{}", table.lines().last().unwrap());1242 eprintln!("{}", table.lines().last().unwrap());