From 8b98ba99724f6dcaca5ed9dee5808d057be3caa0 Mon Sep 17 00:00:00 2001 From: Salim Hammami Date: Tue, 24 Nov 2026 01:53:31 +0100 Subject: [PATCH] Opus: the 6.1 (7 channel) mapping has 5 streams, 2 coupled RFC 7845 section 5.1.1.2 gives 7 channels as 5 streams with 2 coupled pairs. The table said 4 streams and 3 coupled, so a 6.1 Opus voice was split into the wrong streams. Adds a test that checks the mappings of 3 to 8 channels. Part of #327 --- crates/xcl/src/hle/opus.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/hle/opus.rs b/crates/xcl/src/hle/opus.rs index ac9c01313f..879cb30422 100644 --- a/crates/xcl/src/hle/opus.rs +++ b/crates/xcl/src/hle/opus.rs @@ -407,7 +407,7 @@ fn vorbis_mapping(channels: u8) -> Option<(u8, u8, &'static [u8])> { 4 => Some((2, 2, &[0, 1, 2, 3])), 5 => Some((3, 2, &[0, 4, 1, 2, 3])), 6 => Some((4, 2, &[0, 4, 1, 2, 3, 5])), - 7 => Some((4, 3, &[0, 4, 1, 2, 3, 5, 6])), + 7 => Some((5, 2, &[0, 4, 1, 2, 3, 5, 6])), 8 => Some((5, 3, &[0, 6, 1, 2, 3, 4, 5, 7])), _ => None, } @@ -1611,6 +1611,27 @@ pub(crate) mod tests { } } + /// The channel mappings of RFC 7845, section 5.1.1.2 (family 1): stream count, coupled stream + /// count and the mapping table, for 3 to 8 channels. 6.1 is 5 streams, 2 of them coupled + /// (L/R and SL/SR; C, BC and LFE are single) – streams + coupled = channels holds for a + /// wrong table as well, so the values are listed. + #[test] + fn opus_head_vorbis_channel_mappings_match_rfc7845() { + let table: [(u8, u8, u8, &[u8]); 6] = [ + (3, 2, 1, &[0, 2, 1]), + (4, 2, 2, &[0, 1, 2, 3]), + (5, 3, 2, &[0, 4, 1, 2, 3]), + (6, 4, 2, &[0, 4, 1, 2, 3, 5]), + (7, 5, 2, &[0, 4, 1, 2, 3, 5, 6]), + (8, 5, 3, &[0, 6, 1, 2, 3, 4, 5, 7]), + ]; + for (ch, streams, coupled, mapping) in table { + let h = parse_opus_head(&build_opus_head(ch, 48_000, 0, 0)).unwrap(); + assert_eq!((h.stream_count, h.coupled_count, h.mapping.as_slice()), (streams, coupled, mapping), "{ch} channels"); + assert_eq!(h.stream_count as usize + h.coupled_count as usize, ch as usize); + } + } + /// A sound of the game (`XCL_SAMPLE_AWC`: an AWC with one Opus stream, its data chunk as /// the console stores it): every packet decodes, the length matches the AWC's sample count, /// it is not silence. With `XCL_OPUS_WAV` the result is written there to listen to.