From 08538a8f2114740c936882437ffbe51a2b20c5a9 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 10:55:09 +0300 Subject: [PATCH] ec-opus test: hybrid_fb LB-only run forces Mode::Hybrid too. Root cause: with Bandwidth::Full forced but no mode override, the auto mode pick (encoder.rs:1700-1717, equiv vs threshold) still chooses CELT-only for some 20 ms packets, so the forced-FB run left hybrid (conformance.rs:2314). Fix: hybrid_roundtrip takes an Option passed to set_mode (encoder.rs:490); the LB-only run passes Some(Mode::Hybrid) and keeps Bandwidth::Full, so every packet is config 15 with the SILK layer present. Other call sites pass None (automatic, unchanged). Evidence: cargo check -p ec-opus --all-targets clean; test run left to orchestrator --- crates/ec-opus/tests/conformance.rs | 32 +++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/crates/ec-opus/tests/conformance.rs b/crates/ec-opus/tests/conformance.rs index e9a2b39b..5765c1cb 100644 --- a/crates/ec-opus/tests/conformance.rs +++ b/crates/ec-opus/tests/conformance.rs @@ -2225,11 +2225,13 @@ 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]; @@ -2277,8 +2279,8 @@ fn hybrid_layers_align() { .unwrap() .0 }; - let (lb, _) = hybrid_roundtrip(&click, 32_000, None, (true, false)); - let (hb, _) = hybrid_roundtrip(&click, 32_000, None, (false, true)); + 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}"); @@ -2305,14 +2307,21 @@ fn hybrid_layers_align() { #[test] fn hybrid_fb_roundtrip() { for (name, pcm) in silk_sources() { - let (decoded, packets) = hybrid_roundtrip(&pcm, 32_000, None, (false, false)); + let (decoded, packets) = hybrid_roundtrip(&pcm, 32_000, None, None, (false, false)); 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), (true, false)); + 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), + 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); @@ -2344,11 +2353,16 @@ 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), (false, false)); + let (_, packets) = hybrid_roundtrip( + &speech, + 24_000, + Some(Bandwidth::SuperWide), + None, + (false, false), + ); 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, (false, false)); + let (decoded, packets) = hybrid_roundtrip(&speech, bps, None, None, (false, false)); 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);