forge
Explore
Log in

Don't you dare go Hollow

U8: ec-opus conformance drop LB-only/HB-only hybrid layer tests and the mute argument (full-band assertions kept)

Browse files at this commit

76ef26d15fa58dbeef947a1099895bf295d737e8Ahmet Kaan GümüşParent: 5c36cb7
crates/ec-opus/tests/conformance.rsmodified+7 -69
@@ -2219,21 +2219,18 @@ fn silk_packets_track_encoder_bitrate() {
22192219 // Hybrid (SILK 16 kHz + CELT from band 17, one range-coded stream).
22202220
22212221 /// Encodes mono `pcm` as hybrid packets at `bps` and decodes them with our
2222-/// decoder, `mute` = (celt, silk) layers dropped at the decoder; asserts
2223-/// range-state parity packet for packet. Returns (decoded, packets).
2222+/// decoder; asserts range-state parity packet for packet. Returns (decoded, packets).
22242223 fn hybrid_roundtrip(
22252224 pcm: &[f32],
22262225 bps: u32,
22272226 bandwidth: Option<Bandwidth>,
22282227 mode: Option<Mode>,
2229- mute: (bool, bool),
22302228 ) -> (Vec<f32>, Vec<Vec<u8>>) {
22312229 let mut enc = Encoder::new(48000, 1, Application::Voip).unwrap();
22322230 enc.set_bitrate(bps);
22332231 enc.set_bandwidth(bandwidth);
22342232 enc.set_mode(mode);
22352233 let mut dec = Decoder::new(48000, 1).unwrap();
2236- dec.debug_mute_layers(mute.0, mute.1);
22372234 let mut out = vec![0u8; 1500];
22382235 let mut buf = vec![0f32; 5760];
22392236 let (mut decoded, mut packets) = (Vec::new(), Vec::new());
@@ -2254,9 +2251,6 @@ fn hybrid_roundtrip(
22542251 (decoded, packets)
22552252 }
22562253
2257-/// The two layers of a hybrid packet reach the decoder's output at the same
2258-/// delay: a click's low-band-only and high-band-only peaks coincide at the
2259-/// encoder's documented look-ahead.
22602254 /// The delay [`hybrid_roundtrip`]'s encoder advertises for a 20 ms frame —
22612255 /// [`Encoder::look_ahead`] of that same configuration, so the lag assertions
22622256 /// track the layer's real delay instead of a constant.
@@ -2266,71 +2260,22 @@ fn hybrid_delay(bps: u32) -> usize {
22662260 enc.look_ahead(960)
22672261 }
22682262
2269-#[test]
2270-fn hybrid_layers_align() {
2271- let mut click = vec![0f32; 48000];
2272- // Well inside the stream so both layers' predictors are running.
2273- let at = 960 * 10 + 300;
2274- click[at] = 0.9;
2275- let peak = |x: &[f32]| {
2276- x.iter()
2277- .enumerate()
2278- .max_by(|a, b| a.1.abs().partial_cmp(&b.1.abs()).unwrap())
2279- .unwrap()
2280- .0
2281- };
2282- let (lb, _) = hybrid_roundtrip(&click, 32_000, None, None, (true, false));
2283- let (hb, _) = hybrid_roundtrip(&click, 32_000, None, None, (false, true));
2284- let delay = hybrid_delay(32_000) as i64;
2285- let (plb, phb) = (peak(&lb) as i64 - at as i64, peak(&hb) as i64 - at as i64);
2286- eprintln!("hybrid click: LB peak +{plb}, HB peak +{phb}, look_ahead {delay}");
2287- // A fullband CELT click lands at exactly the encoder's advertised delay
2288- // (`celt_click_peak_offset`); the band-limited HB layer's main lobe sits
2289- // up to 2 samples early once transient frames keep their short blocks,
2290- // and SILK lands one sample late.
2291- assert!(
2292- (plb - phb).abs() <= 3,
2293- "layers misaligned: LB +{plb} vs HB +{phb}"
2294- );
2295- assert!(
2296- (phb - delay).abs() <= 2,
2297- "HB peak +{phb}, look_ahead {delay}"
2298- );
2299-}
2300-
23012263 /// 20 ms FB hybrid at 32 kbps: decodes in our decoder range-exactly, tracks
2302-/// the input full-band and in the SILK layer's band alone, and the reference
2303-/// oracle decodes the packets to the same signal.
2264+/// the input full-band, and the reference oracle decodes the packets to the
2265+/// same signal.
23042266 ///
23052267 /// The delay [`hybrid_roundtrip`]'s encoder advertises for a 20 ms frame is
23062268 /// [`Encoder::look_ahead`] of that same configuration, never a constant.
23072269 #[test]
23082270 fn hybrid_fb_roundtrip() {
23092271 for (name, pcm) in silk_sources() {
2310- let (decoded, packets) = hybrid_roundtrip(&pcm, 32_000, None, None, (false, false));
2272+ let (decoded, packets) = hybrid_roundtrip(&pcm, 32_000, None, None);
23112273 let toc = ec_opus::Toc::new(packets[0][0]);
23122274 assert_eq!(toc.config, 15, "{name}: TOC config {}", toc.config);
23132275 let (corr, lag) = aligned_corr(&pcm, &decoded, 400);
2314- let (lb_only, lb_packets) = hybrid_roundtrip(
2315- &pcm,
2316- 32_000,
2317- Some(Bandwidth::Full),
2318- Some(Mode::Hybrid),
2319- (true, false),
2320- );
2321- assert!(
2322- lb_packets
2323- .iter()
2324- .all(|p| ec_opus::Toc::new(p[0]).config == 15),
2325- "{name}: forced-FB run left hybrid"
2326- );
2327- let lb_ref = lowpass(&pcm, 7000.0);
2328- let (lb_corr, lb_lag) = aligned_corr(&lb_ref, &lb_only, 400);
23292276 let bytes: usize = packets.iter().map(Vec::len).sum();
23302277 let kbps = bytes as f64 * 8.0 / (packets.len() as f64 * 20.0);
2331- eprintln!(
2332- "hybrid FB {name}: corr {corr:.4} at lag {lag}, LB corr {lb_corr:.4} at lag {lb_lag}, {kbps:.1} kbps"
2333- );
2278+ eprintln!("hybrid FB {name}: corr {corr:.4} at lag {lag}, {kbps:.1} kbps");
23342279 assert!(corr >= 0.9, "{name}: full-band corr {corr:.4}");
23352280 let delay = hybrid_delay(32_000);
23362281 let libopus = libopus_untrimmed(&format!("hybrid-lag-{name}"), &pcm);
@@ -2339,7 +2284,6 @@ fn hybrid_fb_roundtrip() {
23392284 lag.abs_diff(libopus_lag) <= 6,
23402285 "{name}: aligned at lag {lag}, libopus at {libopus_lag}"
23412286 );
2342- assert!(lb_corr >= 0.9, "{name}: low-band corr {lb_corr:.4}");
23432287 assert!(
23442288 (28.0..=36.0).contains(&kbps),
23452289 "{name}: {kbps:.1} kbps for a 32 kbps CBR target"
@@ -2353,16 +2297,10 @@ fn hybrid_fb_roundtrip() {
23532297 // SWB when asked for it, and the rest of the automatic hybrid range
23542298 // (SILK's share leaves CELT least at the bottom of it).
23552299 let speech = speech_like();
2356- let (_, packets) = hybrid_roundtrip(
2357- &speech,
2358- 24_000,
2359- Some(Bandwidth::SuperWide),
2360- None,
2361- (false, false),
2362- );
2300+ let (_, packets) = hybrid_roundtrip(&speech, 24_000, Some(Bandwidth::SuperWide), None);
23632301 assert_eq!(ec_opus::Toc::new(packets[0][0]).config, 13);
23642302 for bps in [20_000u32, 24_000, 39_000] {
2365- let (decoded, packets) = hybrid_roundtrip(&speech, bps, None, None, (false, false));
2303+ let (decoded, packets) = hybrid_roundtrip(&speech, bps, None, None);
23662304 let (corr, _) = aligned_corr(&speech, &decoded, 400);
23672305 let kbps = packets.iter().map(Vec::len).sum::<usize>() as f64 * 8.0
23682306 / (packets.len() as f64 * 20.0);