ec-opus test: judge hybrid FB lag against pinned libopus, not look_ahead
Browse files at this commit4a881f9248abb4ee3be76d3c877ff7fdf3a9cb96Parent: 76482df1 changed file +69 -2
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 | ||
| 2125 | 2125 | decoded |
| 2126 | 2126 | } |
| 2127 | 2127 | |
| 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 | + | |
| 2128 | 2193 | fn silk_sources() -> Vec<(&'static str, Vec<f32>)> { |
| 2129 | 2194 | let wav = fixture("wav16-mono-48000.wav"); |
| 2130 | 2195 | let mut sources = vec![("synthetic", speech_like())]; |
| @@ -2257,9 +2322,11 @@ fn hybrid_fb_roundtrip() { | ||
| 2257 | 2322 | ); |
| 2258 | 2323 | assert!(corr >= 0.9, "{name}: full-band corr {corr:.4}"); |
| 2259 | 2324 | 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); | |
| 2260 | 2327 | 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}" | |
| 2263 | 2330 | ); |
| 2264 | 2331 | assert!(lb_corr >= 0.9, "{name}: low-band corr {lb_corr:.4}"); |
| 2265 | 2332 | assert!( |