Opus: 6.1 Vorbis mapping is 5 streams / 2 coupled, not 4 / 3 #506

Closed
github-bot wants to merge 1 commit from gh-pr/506/head into gh-pr/506/base
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 01:04 UTC · original
DavidM1911:opus-vorbis-7ch → main · +7 −1 · 1 files · 1 commits · closed without merging

Part of #327 (item 2).

vorbis_mapping(7) returned (4, 3, [0,4,1,2,3,5,6]) — 4 streams with 3 coupled pairs. The RFC 7845 Vorbis order for 6.1 is 5 streams, 2 coupled (two coupled pairs + center/LFE/surround uncoupled), matching libopus; build_opus_head therefore emitted an OpusHead multistream header that decoders would split into the wrong stream count for 6.1 audio.

What is in it

  • crates/xcl/src/hle/opus.rs: vorbis_mapping(7) → (5, 2, &[0,4,1,2,3,5,6]); the existing opus_head_roundtrip test now also asserts the 7- and 8-channel stream/coupled counts.

Tested

  • Windows 11, Ryzen 9 7900X (Radeon iGPU + NVIDIA RTX 3060 Ti 8 GB, driver 610.88), Rust 1.100.0 x86_64-pc-windows-msvc:
    • cargo test -p xcl --lib opus_head_roundtrip: 1 passed
    • cargo test --workspace -- --test-threads=4: 676 passed, 0 failed, 41 ignored
  • Regression run on the retail title (1.0.2.1, own copy), RTX 3060 Ti, scripts/smoke.ps1 -Seconds 60, cargo build --release -p xcl:

main a6f5f7a (same baseline as the sibling PRs; upstream/main is now 2997c9a, docs-only on top):

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1503 (PresentX 1503)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14437 MB

this PR's head c8a3852:

xcl-smoke v1
commit: c8a3852f877e1eb0bd3a2e63cbcfda43c5ca96f7
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1299 (PresentX 1299)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14382 MB

Frames are lower than the usual ~1500 on this title (86% of main, above the 80% bar); presents held 60 FPS in the last windows and there were no removals or crashes.

Not tested

  • An actual 6.1 multistream stream through the MFT path; Linux/macOS (crate is Windows-only)

AI use

  • Devin (SWE-2 Flash Medium): implemented the fix and test, ran the suites and smoke runs.
**@⁠DavidM1911** on GitHub · 2026-11-24 01:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/506) `DavidM1911:opus-vorbis-7ch` → `main` · +7 −1 · 1 files · 1 commits · closed without merging Part of #327 (item 2). `vorbis_mapping(7)` returned `(4, 3, [0,4,1,2,3,5,6])` — 4 streams with 3 coupled pairs. The RFC 7845 Vorbis order for 6.1 is **5 streams, 2 coupled** (two coupled pairs + center/LFE/surround uncoupled), matching libopus; `build_opus_head` therefore emitted an `OpusHead` multistream header that decoders would split into the wrong stream count for 6.1 audio. **What is in it** - `crates/xcl/src/hle/opus.rs`: `vorbis_mapping(7)` → `(5, 2, &[0,4,1,2,3,5,6])`; the existing `opus_head_roundtrip` test now also asserts the 7- and 8-channel stream/coupled counts. **Tested** - Windows 11, Ryzen 9 7900X (Radeon iGPU + NVIDIA RTX 3060 Ti 8 GB, driver 610.88), Rust 1.100.0 `x86_64-pc-windows-msvc`: - `cargo test -p xcl --lib opus_head_roundtrip`: 1 passed - `cargo test --workspace -- --test-threads=4`: 676 passed, 0 failed, 41 ignored - Regression run on the retail title (1.0.2.1, own copy), RTX 3060 Ti, `scripts/smoke.ps1 -Seconds 60`, `cargo build --release -p xcl`: main `a6f5f7a` (same baseline as the sibling PRs; upstream/main is now `2997c9a`, docs-only on top): ``` xcl-smoke v1 commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212 gpu: NVIDIA GeForce RTX 3060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1503 (PresentX 1503) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14437 MB ``` this PR's head `c8a3852`: ``` xcl-smoke v1 commit: c8a3852f877e1eb0bd3a2e63cbcfda43c5ca96f7 gpu: NVIDIA GeForce RTX 3060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1299 (PresentX 1299) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14382 MB ``` Frames are lower than the usual ~1500 on this title (86% of main, above the 80% bar); presents held 60 FPS in the last windows and there were no removals or crashes. **Not tested** - An actual 6.1 multistream stream through the MFT path; Linux/macOS (crate is Windows-only) **AI use** - Devin (SWE-2 Flash Medium): implemented the fix and test, ran the suites and smoke runs.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:23:47 +00:00
github-bot closed this pull request 2026-11-26 04:23:47 +00:00
Author
Owner

@⁠lordon1a on GitHub · 2026-11-24 04:07 UTC · original

The 6.1 entry on main already matches libopus: vorbis_mappings[8] in xiph/opus src/opus_multistream_encoder.c has {4, 3, {0, 4, 1, 2, 3, 5, 6}}, /* 7: 6.1 surround */. With (5, 2), a 7-channel multistream packet from a libopus encoder (4 streams) would be split as 5 and rejected or misdecoded on the default-header path (Decoder::new without an OpusHead). Details and the source lines are in https://github.com/ivall/xcl/issues/327#issuecomment-7121722096. I'd suggest not merging this as it stands.

Written with Claude Code (Claude Opus 5.5).

**@⁠lordon1a** on GitHub · 2026-11-24 04:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/506#issuecomment-7121724551) The 6.1 entry on `main` already matches libopus: `vorbis_mappings[8]` in xiph/opus `src/opus_multistream_encoder.c` has `{4, 3, {0, 4, 1, 2, 3, 5, 6}}, /* 7: 6.1 surround */`. With (5, 2), a 7-channel multistream packet from a libopus encoder (4 streams) would be split as 5 and rejected or misdecoded on the default-header path (`Decoder::new` without an `OpusHead`). Details and the source lines are in https://github.com/ivall/xcl/issues/327#issuecomment-7121722096. I'd suggest not merging this as it stands. Written with Claude Code (Claude Opus 5.5).
Author
Owner

@⁠MesshM on GitHub · 2026-11-24 04:08 UTC · original

Test run and review of c8a3852f877e1eb0bd3a2e63cbcfda43c5ca96f7 on AMD RDNA4. I merged it onto current main f4ce27c locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 701 passed, 0 failed, 41 ignored, exit code 0; opus_head_roundtrip_mono_stereo_surround passes (with the new values).

Review: I think the current value is the right one, and this changes it to a wrong one. The description says 5 streams / 2 coupled for 6.1 "matching libopus". libopus's own table (src/opus_multistream_encoder.c, vorbis_mappings[8], current xiph/opus master) has for 7 channels {4, 3, {0, 4, 1, 2, 3, 5, 6}} (commented "6.1 surround"): 4 streams, 3 coupled, the mapping main already has. With that layout the third coupled stream carries channels 4–5 (centre and rear centre) and LFE is the one uncoupled stream; with 5/2 and the same mapping array the decoder would read centre, rear centre and LFE as three uncoupled streams.

RFC 7845 lets the encoder choose the counts for family 1, so what matters is what the title's packets were encoded with: the OpusHead XCL builds has to declare the stream / coupled counts of the actual packets, or the multistream decoder splits each packet wrongly. If a 6.1 sample from a title showed 5 / 2 packets, that would be a reason to change it, but then the change would be "follow the source", not "match libopus", and libopus-encoded 6.1 would break. Without such a sample I would leave vorbis_mapping(7) as it is.

Not tested: no 6.1 Opus stream from a title (I have no game data), so I could not decode either variant; release build.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the libopus table was read from its repository.

**@⁠MesshM** on GitHub · 2026-11-24 04:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/506#issuecomment-7121737307) Test run and review of `c8a3852f877e1eb0bd3a2e63cbcfda43c5ca96f7` on AMD RDNA4. I merged it onto current `main` `f4ce27c` locally (clean merge) and tested that tree. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug - `cargo build --workspace` + `cargo test --workspace -- --test-threads=4` on the merge: **701 passed, 0 failed, 41 ignored**, exit code 0; `opus_head_roundtrip_mono_stereo_surround` passes (with the new values). **Review: I think the current value is the right one, and this changes it to a wrong one.** The description says 5 streams / 2 coupled for 6.1 "matching libopus". libopus's own table (`src/opus_multistream_encoder.c`, `vorbis_mappings[8]`, current `xiph/opus` master) has for 7 channels `{4, 3, {0, 4, 1, 2, 3, 5, 6}}` (commented "6.1 surround"): **4 streams, 3 coupled**, the mapping `main` already has. With that layout the third coupled stream carries channels 4–5 (centre and rear centre) and LFE is the one uncoupled stream; with 5/2 and the same mapping array the decoder would read centre, rear centre and LFE as three uncoupled streams. RFC 7845 lets the encoder choose the counts for family 1, so what matters is what the title's packets were encoded with: the `OpusHead` XCL builds has to declare the stream / coupled counts of the actual packets, or the multistream decoder splits each packet wrongly. If a 6.1 sample from a title showed 5 / 2 packets, that would be a reason to change it, but then the change would be "follow the source", not "match libopus", and libopus-encoded 6.1 would break. Without such a sample I would leave `vorbis_mapping(7)` as it is. **Not tested:** no 6.1 Opus stream from a title (I have no game data), so I could not decode either variant; release build. Run and review by Claude Code (Claude Opus 5.5) on this machine; the libopus table was read from its repository.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 08:54 UTC · original

Closing — the reviewers are right and the issue's premise was wrong. libopus vorbis_mappings[8] in src/opus_multistream_encoder.c uses {4, 3, {0,4,1,2,3,5,6}} for 7 channels (6.1), which is what main already has. My (5,2) entry would have described a different packet layout and broken decoding of reference 6.1 streams. Thanks @⁠shdann and @⁠lordon1a for checking against the source. The remaining #327 items (framing ambiguity, MFT guards) stand on their own in #926.

**@⁠DavidM1911** on GitHub · 2026-11-24 08:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/506#issuecomment-7126722399) Closing — the reviewers are right and the issue's premise was wrong. libopus `vorbis_mappings[8]` in `src/opus_multistream_encoder.c` uses `{4, 3, {0,4,1,2,3,5,6}}` for 7 channels (6.1), which is what `main` already has. My (5,2) entry would have described a different packet layout and broken decoding of reference 6.1 streams. Thanks @⁠shdann and @⁠lordon1a for checking against the source. The remaining #327 items (framing ambiguity, MFT guards) stand on their own in #926.
Author
Owner

@⁠shdann on GitHub · 2026-11-24 01:12 UTC · original · reviewed

The new 6.1 entry differs from the reference libopus encoder. Its seven-channel mapping-family-1 table uses four streams, three coupled streams, and the same channel map already used on main. A header that declares five streams describes a different packet layout and can break decoding of reference 6.1 packets. Please keep the original counts and check with a seven-channel packet from the reference encoder. https://github.com/xiph/opus/blob/main/src/opus_multistream_encoder.c . Static review with OpenAI Codex (GPT-6.2 Sol).

**@⁠shdann** on GitHub · 2026-11-24 01:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/506#pullrequestreview-6032121622) · **reviewed** The new 6.1 entry differs from the reference libopus encoder. Its seven-channel mapping-family-1 table uses four streams, three coupled streams, and the same channel map already used on main. A header that declares five streams describes a different packet layout and can break decoding of reference 6.1 packets. Please keep the original counts and check with a seven-channel packet from the reference encoder. https://github.com/xiph/opus/blob/main/src/opus_multistream_encoder.c . Static review with OpenAI Codex (GPT-6.2 Sol).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.