Skip to content

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

Closed
DavidM1911 wants to merge 1 commit into
xcl-dev:mainfrom
DavidM1911:opus-vorbis-7ch
Closed

DavidM1911 wants to merge 1 commit into
xcl-dev:mainfrom
DavidM1911:opus-vorbis-7ch

Conversation

@DavidM1911

@DavidM1911 DavidM1911 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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.

@shdann shdann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@lordon1a

Copy link
Copy Markdown

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 #327 (comment). I'd suggest not merging this as it stands.

Written with Claude Code (Claude Opus 5.5).

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

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.

@DavidM1911

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants