forge
Explore
Log in

Don't you dare go Hollow

ec-opus test: judge hybrid FB lag against pinned libopus, not look_ahead

Browse files at this commit

4a881f9248abb4ee3be76d3c877ff7fdf3a9cb96Ahmet Kaan GümüşParent: 76482df
Root cause: hybrid_fb_roundtrip asserted the speech correlation lag within
look_ahead(960)=312 +/-6. Pinned ffmpeg 9.0.2 libopus (32 kbps, 20 ms,
fullband, voip, CBR) decoded untrimmed (-flags2 +skip_manual) peaks at lag
298 on wav16-mono-48000 (corr 0.9994; lag 312 corr 0.9167), and 308 on the
synthetic speech (corr 0.928). Our 298 therefore matches libopus; the
constant was wrong. Lag is now asserted within +/-6 of the libopus lag
measured by the same aligned_corr. Library code unchanged.
crates/ec-opus/tests/conformance.rsmodified+69 -2
@@ -2125,6 +2125,71 @@ fn oracle_decode(name: &str, packets: &[Vec<u8>], samples: usize, pre_skip: usiz
21252125 decoded
21262126 }
21272127
2128+/// Pinned libopus (ffmpeg) encode of mono `pcm` at the same 32 kbps, 20 ms,
2129+/// fullband VoIP setting, decoded with the pre-skip left in: the output starts
2130+/// at the encoder's input sample 0, so its lag is libopus's real delay.
2131+fn libopus_untrimmed(name: &str, pcm: &[f32]) -> Vec<f32> {
2132+ let raw = temp_path(&format!("{name}.f32"));
2133+ let opus = temp_path(&format!("{name}.opus"));
2134+ let bytes: Vec<u8> = pcm.iter().flat_map(|x| x.to_le_bytes()).collect();
2135+ fs::write(&raw, bytes).unwrap();
2136+ let encode = ec_testkit::ffmpeg()
2137+ .args([
2138+ "-v", "error", "-y", "-f", "f32le", "-ar", "48000", "-ac", "1", "-i",
2139+ ])
2140+ .arg(&raw)
2141+ .args([
2142+ "-c:a",
2143+ "libopus",
2144+ "-application",
2145+ "voip",
2146+ "-b:a",
2147+ "32000",
2148+ "-vbr",
2149+ "off",
2150+ "-frame_duration",
2151+ "20",
2152+ "-fflags",
2153+ "+bitexact",
2154+ ])
2155+ .arg(&opus)
2156+ .output()
2157+ .unwrap();
2158+ assert!(
2159+ encode.status.success(),
2160+ "{name}: ffmpeg encode: {}",
2161+ String::from_utf8_lossy(&encode.stderr)
2162+ );
2163+ let decode = ec_testkit::ffmpeg()
2164+ .args([
2165+ "-v",
2166+ "error",
2167+ "-flags2",
2168+ "+skip_manual",
2169+ "-c:a",
2170+ "libopus",
2171+ "-i",
2172+ ])
2173+ .arg(&opus)
2174+ .args(["-f", "f32le", "-ar", "48000", "-ac", "1", "-"])
2175+ .output()
2176+ .unwrap();
2177+ assert!(
2178+ decode.status.success(),
2179+ "{name}: ffmpeg decode: {}",
2180+ String::from_utf8_lossy(&decode.stderr)
2181+ );
2182+ let _ = fs::remove_file(&raw);
2183+ let _ = fs::remove_file(&opus);
2184+ decode
2185+ .stdout
2186+ .as_chunks::<4>()
2187+ .0
2188+ .iter()
2189+ .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]]))
2190+ .collect()
2191+}
2192+
21282193 fn silk_sources() -> Vec<(&'static str, Vec<f32>)> {
21292194 let wav = fixture("wav16-mono-48000.wav");
21302195 let mut sources = vec![("synthetic", speech_like())];
@@ -2257,9 +2322,11 @@ fn hybrid_fb_roundtrip() {
22572322 );
22582323 assert!(corr >= 0.9, "{name}: full-band corr {corr:.4}");
22592324 let delay = hybrid_delay(32_000);
2325+ let libopus = libopus_untrimmed(&format!("hybrid-lag-{name}"), &pcm);
2326+ let (_, libopus_lag) = aligned_corr(&pcm, &libopus, 400);
22602327 assert!(
2261- (delay - 6..=delay + 6).contains(&lag),
2262- "{name}: aligned at lag {lag}, not the advertised {delay}"
2328+ lag.abs_diff(libopus_lag) <= 6,
2329+ "{name}: aligned at lag {lag}, libopus at {libopus_lag}"
22632330 );
22642331 assert!(lb_corr >= 0.9, "{name}: low-band corr {lb_corr:.4}");
22652332 assert!(