From c8a3852f877e1eb0bd3a2e63cbcfda43c5ca96f7 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 24 Nov 2026 01:02:08 +0000 Subject: [PATCH] Opus: 6.1 Vorbis mapping is 5 streams / 2 coupled, not 4 / 3 vorbis_mapping(7) described 4 streams with 3 coupled pairs; the RFC 7845 Vorbis order for 6.1 is 5 streams with 2 coupled pairs and 3 uncoupled channels, matching libopus. build_opus_head emitted a header multistream decoders would split into the wrong stream count. --- crates/xcl/src/hle/opus.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/hle/opus.rs b/crates/xcl/src/hle/opus.rs index ac9c01313f..05e7768ac5 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, } @@ -1609,6 +1609,12 @@ pub(crate) mod tests { assert_eq!(h.output_gain, -256); assert_eq!(h.mapping_family, if ch <= 2 { 0 } else { 1 }); } + // RFC 7845 Vorbis mappings: 6.1 is 5 streams / 2 coupled, 7.1 is 5 / 3. + let h7 = parse_opus_head(&build_opus_head(7, 48_000, 0, 0)).unwrap(); + assert_eq!((h7.stream_count, h7.coupled_count), (5, 2)); + assert_eq!(h7.mapping, [0, 4, 1, 2, 3, 5, 6]); + let h8 = parse_opus_head(&build_opus_head(8, 48_000, 0, 0)).unwrap(); + assert_eq!((h8.stream_count, h8.coupled_count), (5, 3)); } /// A sound of the game (`XCL_SAMPLE_AWC`: an AWC with one Opus stream, its data chunk as