forge
Explore
Log in

Don't you dare go Hollow

Parametrise the startup hop-energy and band-window diagnostics

Browse files at this commit

488aada5f9163f3dce9e8da5edc33eda05c83399Ahmet Kaan GümüşParent: 63753b8
  • test
    • parametrise the startup hop-energy and band-window diagnostics
Show full message
test(opus): parametrise the startup hop-energy and band-window diagnostics

HOP_SRC/HOP_MS recentre reell_startup_hop_energies on any source and instant;
WIN_CENTRE recentres spectral_divergence_vs_libopus's per-band window dump;
'her' joins its source list. Used to name the her@96 residue: a missed
right-channel HF transient at 88.29 s coded as a long block.
crates/ec-opus/tests/conformance.rsmodified+33 -26
@@ -3233,6 +3233,7 @@ fn spectral_divergence_vs_libopus() {
3233 let all: &[(&str, &str)] = &[3233 let all: &[(&str, &str)] = &[
3234 ("reell", "~/Music/reell.mp4"),3234 ("reell", "~/Music/reell.mp4"),
3235 ("dl8a", "~/Downloads/8a3b6d1d19.mp3"),3235 ("dl8a", "~/Downloads/8a3b6d1d19.mp3"),
3236+ ("her", "~/Music/reeli.mp3"),
3236 ];3237 ];
3237 let only: Vec<String> = std::env::var("SWEEP_ONLY")3238 let only: Vec<String> = std::env::var("SWEEP_ONLY")
3238 .unwrap_or_else(|_| "reell,dl8a".to_owned())3239 .unwrap_or_else(|_| "reell,dl8a".to_owned())
@@ -3515,7 +3516,9 @@ fn spectral_divergence_vs_libopus() {
3515 report.push_str(3516 report.push_str(
3516 "# windows 12..=20: win +ms band lo-hi | lnE src/ours/ref, ch L then R\n",3517 "# windows 12..=20: win +ms band lo-hi | lnE src/ours/ref, ch L then R\n",
3517 );3518 );
3518- for xi in 12..=20 {3519+ // WIN_CENTRE=<window index> recentres the dump on another window.
3520+ let wc: usize = std::env::var("WIN_CENTRE").ok().and_then(|v| v.parse().ok()).unwrap_or(16);
3521+ for xi in wc.saturating_sub(4)..=wc + 4 {
3519 if xi >= nframes {3522 if xi >= nframes {
3520 break;3523 break;
3521 }3524 }
@@ -3629,47 +3632,51 @@ fn celt_silence_then_attack_decodes_bounded() {
3629 #[ignore]3632 #[ignore]
3630 fn reell_startup_hop_energies() {3633 fn reell_startup_hop_energies() {
3631 const CH: usize = 2;3634 const CH: usize = 2;
3632- let src = shellexpand("~/Music/reell.mp4");3635+ // HOP_SRC / HOP_MS pick another source and window centre (diagnostic).
3636+ let src_s = std::env::var("HOP_SRC").unwrap_or_else(|_| "~/Music/reell.mp4".into());
3637+ let centre_ms: f64 = std::env::var("HOP_MS").ok().and_then(|v| v.parse().ok()).unwrap_or(42.5);
3638+ let src = shellexpand(&src_s);
3633 if !src.exists() {3639 if !src.exists() {
3634 return;3640 return;
3635 }3641 }
3636- let pcm = ffmpeg_decode_pcm(&src, 2.0);3642+ let secs = (centre_ms / 1000.0 + 1.0).max(2.0);
3643+ let pcm = ffmpeg_decode_pcm(&src, secs);
3637 let scratch = std::env::temp_dir().join("ec-opus-reell-startup.opus");3644 let scratch = std::env::temp_dir().join("ec-opus-reell-startup.opus");
3638- ffmpeg_encode_libopus(&src, 96, &scratch, 2.0);3645+ ffmpeg_encode_libopus(&src, 96, &scratch, secs);
3639 let (ref_dec, _) = decode_ogg(&scratch);3646 let (ref_dec, _) = decode_ogg(&scratch);
3640 let (lag_r, ref_al) = align_to_source(&pcm, &ref_dec, CH, 2000);3647 let (lag_r, ref_al) = align_to_source(&pcm, &ref_dec, CH, 2000);
3641 let mut enc = Encoder::new(48000, CH, Application::Audio).unwrap();3648 let mut enc = Encoder::new(48000, CH, Application::Audio).unwrap();
3642 enc.set_bitrate(96_000);3649 enc.set_bitrate(96_000);
3643 enc.set_vbr_constrained(true);3650 enc.set_vbr_constrained(true);
3644- let (ours_dec, _) = roundtrip_own(&mut enc, &pcm, CH, 960);3651+ let mut frames_diag = Vec::new();
3652+ let mut dec = Decoder::new(48000, CH).unwrap();
3653+ let mut out = vec![0u8; 1500];
3654+ let mut buf = vec![0f32; 5760 * CH];
3655+ let mut ours_dec = Vec::new();
3656+ for block in pcm.chunks_exact(960 * CH) {
3657+ let n = enc.encode_float(block, 960, &mut out).unwrap();
3658+ let m = dec.decode_float(&out[..n], &mut buf).unwrap();
3659+ ours_dec.extend_from_slice(&buf[..m * CH]);
3660+ let e = enc.last_celt_diag().clone();
3661+ let d = dec.last_celt_diag().clone();
3662+ frames_diag.push((n, e.is_transient, e.intra, d.tf_res.clone(), d.anti_collapse));
3663+ }
3645 let (lag_o, ours_al) = align_to_source(&pcm, &ours_dec, CH, 2000);3664 let (lag_o, ours_al) = align_to_source(&pcm, &ours_dec, CH, 2000);
3646 let first = |v: &[f32]| v.iter().position(|x| x.abs() > 1e-4).map(|i| i / CH);3665 let first = |v: &[f32]| v.iter().position(|x| x.abs() > 1e-4).map(|i| i / CH);
3647 println!("lag ref {lag_r} ours {lag_o}; first>1e-4: src {:?} ours {:?} ref {:?}", first(&pcm), first(&ours_al), first(&ref_al));3666 println!("lag ref {lag_r} ours {lag_o}; first>1e-4: src {:?} ours {:?} ref {:?}", first(&pcm), first(&ours_al), first(&ref_al));
3648 let e = |v: &[f32], h: usize| -> f64 {3667 let e = |v: &[f32], h: usize| -> f64 {
3649- v[h * 120 * CH..((h + 1) * 120 * CH).min(v.len())].iter().map(|&x| (x as f64) * (x as f64)).sum()3668+ let a = (h * 120 * CH).min(v.len());
3669+ let b = ((h + 1) * 120 * CH).min(v.len());
3670+ v[a..b].iter().map(|&x| (x as f64) * (x as f64)).sum()
3650 };3671 };
3651- // Frame-2 flags of both streams through our decoder.3672+ let hc = (centre_ms / 2.5) as usize;
3652- let data = fs::read(&scratch).unwrap();3673+ for f in (hc / 8).saturating_sub(1)..=(hc / 8 + 1) {
3653- let packets = ogg_packets(&data);3674+ if let Some((n, t, i, tf, ac)) = frames_diag.get(f) {
3654- let mut rd = Decoder::new(48000, CH).unwrap();3675+ println!("frame {f} ({:.1} ms): bytes {n} trans {t} intra {i} ac {ac} tf {tf:?}", f as f64 * 20.0);
3655- let mut od = Decoder::new(48000, CH).unwrap();3676+ }
3656- let mut oe = Encoder::new(48000, CH, Application::Audio).unwrap();
3657- oe.set_bitrate(96_000);
3658- oe.set_vbr_constrained(true);
3659- let mut buf = vec![0f32; 5760 * CH];
3660- let mut out = vec![0u8; 1500];
3661- for f in 0..4 {
3662- rd.decode_float(&packets[2 + f], &mut buf).unwrap();
3663- let r = rd.last_celt_diag().clone();
3664- let n = oe.encode_float(&pcm[f * 960 * CH..(f + 1) * 960 * CH], 960, &mut out).unwrap();
3665- od.decode_float(&out[..n], &mut buf).unwrap();
3666- let o = od.last_celt_diag().clone();
3667- let e = oe.last_celt_diag().clone();
3668- println!("frame {f} REF bytes {} sil {} intra {} trans {} spread {} ac {} tf {:?}", packets[2 + f].len(), r.silence, r.intra, r.transient, r.spread, r.anti_collapse, r.tf_res);
3669- println!("frame {f} OUR bytes {n} sil {} intra {} trans {} spread {} ac {} tf {:?} shorts {} pulses {:?}", o.silence, o.intra, o.transient, o.spread, o.anti_collapse, o.tf_res, e.short_blocks, e.pulses);
3670 }3677 }
3671 println!("hop(ms)\tsrc\tours\tref");3678 println!("hop(ms)\tsrc\tours\tref");
3672- for h in 10..24 {3679+ for h in hc.saturating_sub(8)..hc + 8 {
3673 println!("{:.1}\t{:.3e}\t{:.3e}\t{:.3e}", h as f64 * 2.5, e(&pcm, h), e(&ours_al, h), e(&ref_al, h));3680 println!("{:.1}\t{:.3e}\t{:.3e}\t{:.3e}", h as f64 * 2.5, e(&pcm, h), e(&ours_al, h), e(&ref_al, h));
3674 }3681 }
3675 }3682 }