From 3f2897d2a6f4218f64c822d7de1595a74ad55c4a Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 11 Nov 2026 17:26:31 -0500 Subject: [PATCH] craft-audio: test the SILK mid-only flag through a coded frame (#866) The existing test sets the decoder's state by hand, so it also passes with a mid-only flag kept from one frame to the next (the behaviour the per-frame flag replaced). This one decodes a stereo frame that codes the flag, then loses a frame: with a kept flag the side channel does not restart and the test fails. --- crates/audio/src/opus/decode/silk/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/audio/src/opus/decode/silk/mod.rs b/crates/audio/src/opus/decode/silk/mod.rs index 338b700a9..ff50ef39d 100644 --- a/crates/audio/src/opus/decode/silk/mod.rs +++ b/crates/audio/src/opus/decode/silk/mod.rs @@ -902,4 +902,19 @@ mod tests { d.decode(None, LostFlag::Lost, true, 20, &mut [0.0; 2 * 960]).unwrap(); assert!(d.ch[1].first_frame_after_reset, "a lost frame codes no mid-only flag, so the side channel restarts"); } + + /// The same after a frame that codes the flag: a flag kept from one frame to the next would + /// still be set at the lost frame, and the side channel would not restart. + #[test] + fn a_lost_frame_after_a_coded_mid_only_frame_resets_the_side_channel() { + let mut d = SilkDecoder::new(48000, 2); + d.set_stream(2, 16000); + // A stereo frame with no voice activity in the side channel and the mid-only flag set. + let frame = [0xCB, 0xEE, 0x02, 0x07]; + d.decode(Some(&mut RangeDecoder::new(&frame)), LostFlag::Normal, true, 20, &mut [0.0; 2 * 960]).unwrap(); + assert!(d.prev_decode_only_middle, "the frame codes the mid channel only"); + d.ch[1].first_frame_after_reset = false; + d.decode(None, LostFlag::Lost, true, 20, &mut [0.0; 2 * 960]).unwrap(); + assert!(d.ch[1].first_frame_after_reset, "the lost frame starts out coding the side channel, so the side channel restarts"); + } }