From 76ef26d15fa58dbeef947a1099895bf295d737e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 13:35:31 +0300 Subject: [PATCH] U8: ec-opus conformance drop LB-only/HB-only hybrid layer tests and the mute argument (full-band assertions kept) --- crates/ec-opus/tests/conformance.rs | 76 +++-------------------------- 1 file changed, 7 insertions(+), 69 deletions(-) diff --git a/crates/ec-opus/tests/conformance.rs b/crates/ec-opus/tests/conformance.rs index 5765c1cb..8ebea06e 100644 --- a/crates/ec-opus/tests/conformance.rs +++ b/crates/ec-opus/tests/conformance.rs @@ -2219,21 +2219,18 @@ fn silk_packets_track_encoder_bitrate() { // Hybrid (SILK 16 kHz + CELT from band 17, one range-coded stream). /// Encodes mono `pcm` as hybrid packets at `bps` and decodes them with our -/// decoder, `mute` = (celt, silk) layers dropped at the decoder; asserts -/// range-state parity packet for packet. Returns (decoded, packets). +/// decoder; asserts range-state parity packet for packet. Returns (decoded, packets). fn hybrid_roundtrip( pcm: &[f32], bps: u32, bandwidth: Option, mode: Option, - mute: (bool, bool), ) -> (Vec, Vec>) { let mut enc = Encoder::new(48000, 1, Application::Voip).unwrap(); enc.set_bitrate(bps); enc.set_bandwidth(bandwidth); enc.set_mode(mode); let mut dec = Decoder::new(48000, 1).unwrap(); - dec.debug_mute_layers(mute.0, mute.1); let mut out = vec![0u8; 1500]; let mut buf = vec![0f32; 5760]; let (mut decoded, mut packets) = (Vec::new(), Vec::new()); @@ -2254,9 +2251,6 @@ fn hybrid_roundtrip( (decoded, packets) } -/// The two layers of a hybrid packet reach the decoder's output at the same -/// delay: a click's low-band-only and high-band-only peaks coincide at the -/// encoder's documented look-ahead. /// The delay [`hybrid_roundtrip`]'s encoder advertises for a 20 ms frame — /// [`Encoder::look_ahead`] of that same configuration, so the lag assertions /// track the layer's real delay instead of a constant. @@ -2266,71 +2260,22 @@ fn hybrid_delay(bps: u32) -> usize { enc.look_ahead(960) } -#[test] -fn hybrid_layers_align() { - let mut click = vec![0f32; 48000]; - // Well inside the stream so both layers' predictors are running. - let at = 960 * 10 + 300; - click[at] = 0.9; - let peak = |x: &[f32]| { - x.iter() - .enumerate() - .max_by(|a, b| a.1.abs().partial_cmp(&b.1.abs()).unwrap()) - .unwrap() - .0 - }; - let (lb, _) = hybrid_roundtrip(&click, 32_000, None, None, (true, false)); - let (hb, _) = hybrid_roundtrip(&click, 32_000, None, None, (false, true)); - let delay = hybrid_delay(32_000) as i64; - let (plb, phb) = (peak(&lb) as i64 - at as i64, peak(&hb) as i64 - at as i64); - eprintln!("hybrid click: LB peak +{plb}, HB peak +{phb}, look_ahead {delay}"); - // A fullband CELT click lands at exactly the encoder's advertised delay - // (`celt_click_peak_offset`); the band-limited HB layer's main lobe sits - // up to 2 samples early once transient frames keep their short blocks, - // and SILK lands one sample late. - assert!( - (plb - phb).abs() <= 3, - "layers misaligned: LB +{plb} vs HB +{phb}" - ); - assert!( - (phb - delay).abs() <= 2, - "HB peak +{phb}, look_ahead {delay}" - ); -} - /// 20 ms FB hybrid at 32 kbps: decodes in our decoder range-exactly, tracks -/// the input full-band and in the SILK layer's band alone, and the reference -/// oracle decodes the packets to the same signal. +/// the input full-band, and the reference oracle decodes the packets to the +/// same signal. /// /// The delay [`hybrid_roundtrip`]'s encoder advertises for a 20 ms frame is /// [`Encoder::look_ahead`] of that same configuration, never a constant. #[test] fn hybrid_fb_roundtrip() { for (name, pcm) in silk_sources() { - let (decoded, packets) = hybrid_roundtrip(&pcm, 32_000, None, None, (false, false)); + let (decoded, packets) = hybrid_roundtrip(&pcm, 32_000, None, None); let toc = ec_opus::Toc::new(packets[0][0]); assert_eq!(toc.config, 15, "{name}: TOC config {}", toc.config); let (corr, lag) = aligned_corr(&pcm, &decoded, 400); - let (lb_only, lb_packets) = hybrid_roundtrip( - &pcm, - 32_000, - Some(Bandwidth::Full), - Some(Mode::Hybrid), - (true, false), - ); - assert!( - lb_packets - .iter() - .all(|p| ec_opus::Toc::new(p[0]).config == 15), - "{name}: forced-FB run left hybrid" - ); - let lb_ref = lowpass(&pcm, 7000.0); - let (lb_corr, lb_lag) = aligned_corr(&lb_ref, &lb_only, 400); let bytes: usize = packets.iter().map(Vec::len).sum(); let kbps = bytes as f64 * 8.0 / (packets.len() as f64 * 20.0); - eprintln!( - "hybrid FB {name}: corr {corr:.4} at lag {lag}, LB corr {lb_corr:.4} at lag {lb_lag}, {kbps:.1} kbps" - ); + eprintln!("hybrid FB {name}: corr {corr:.4} at lag {lag}, {kbps:.1} kbps"); assert!(corr >= 0.9, "{name}: full-band corr {corr:.4}"); let delay = hybrid_delay(32_000); let libopus = libopus_untrimmed(&format!("hybrid-lag-{name}"), &pcm); @@ -2339,7 +2284,6 @@ fn hybrid_fb_roundtrip() { lag.abs_diff(libopus_lag) <= 6, "{name}: aligned at lag {lag}, libopus at {libopus_lag}" ); - assert!(lb_corr >= 0.9, "{name}: low-band corr {lb_corr:.4}"); assert!( (28.0..=36.0).contains(&kbps), "{name}: {kbps:.1} kbps for a 32 kbps CBR target" @@ -2353,16 +2297,10 @@ fn hybrid_fb_roundtrip() { // SWB when asked for it, and the rest of the automatic hybrid range // (SILK's share leaves CELT least at the bottom of it). let speech = speech_like(); - let (_, packets) = hybrid_roundtrip( - &speech, - 24_000, - Some(Bandwidth::SuperWide), - None, - (false, false), - ); + let (_, packets) = hybrid_roundtrip(&speech, 24_000, Some(Bandwidth::SuperWide), None); assert_eq!(ec_opus::Toc::new(packets[0][0]).config, 13); for bps in [20_000u32, 24_000, 39_000] { - let (decoded, packets) = hybrid_roundtrip(&speech, bps, None, None, (false, false)); + let (decoded, packets) = hybrid_roundtrip(&speech, bps, None, None); let (corr, _) = aligned_corr(&speech, &decoded, 400); let kbps = packets.iter().map(Vec::len).sum::() as f64 * 8.0 / (packets.len() as f64 * 20.0);