XAudio2: an XMA voice keeps the decoder's channels beyond 8 #1287

Open
github-bot wants to merge 1 commit from github-bot/gh-1287 into main AGit
Owner

@⁠emirduran707 on GitHub · 2026-11-24 14:20 UTC · original
emirduran707:xaudio2-xma-voice-channels → main · +69 −2 · 1 files · 1 commits · open

The XMA2 decoder accepts up to 16 channels (xma2::MAX_CHANNELS), and a decoded XMA voice is created with the decoder's channel count. But pcm16_for_rate clamped it to 8, so a voice with 9–16 channels got an 8-channel PCM voice. Each decoded frame still carried all its channels: with 10 channels, XAudio2 read every 10 samples as 1.25 frames of 8 channels, so the channels landed on the wrong speakers, drifted every frame, and the buffer played 1.25 times too long (2 times with 16 channels). XAudio2's limit is XAUDIO2_MAX_AUDIO_CHANNELS (64). On this machine, xaudio2_9 created plain PCM16 voices of 9, 10, 12, 16, 32 and 64 channels that played at the right length, and refused 65 (XAUDIO2_E_INVALID_CALL).

pcm16_for_rate now clamps to 1–64. The XMA voice's state takes the decoder's channel count too: the silence that stands in for an undecodable buffer is sized from it, and with 8 there Windows refused the submit of a 10-channel voice. Silent fallback voices and Opus voices still use 8, as before.

What is in it

  • crates/xcl/src/hle/xaudio2.rs:
    • the clamp, and the channel count of the XMA branch;
    • test pcm16_keeps_up_to_64_channels, which needs no device;
    • test xma_voice_keeps_the_decoders_ten_channels, which skips without an audio device. It uses an XMA2WAVEFORMATEX with 10 channels in 5 streams: the voice reports 10 channels, and an undecodable buffer submits.

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release
  • cargo test --workspace -- --test-threads=4 on fe5b1f3: 743 passed, 0 failed, 41 ignored; no SKIPPED GPU tests (the audio tests ran; an audio device is present)
  • without the change: pcm16_keeps_up_to_64_channels left: (8, 16, 768000), right: (10, 20, 960000); with it both new tests pass

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1541 (PresentX 1541)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19650 MB

this PR:

xcl-smoke v1
commit: fe5b1f3b81b1ef64242c7ad1a8ef5f075b68d74a
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1515 (PresentX 1515)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19512 MB

Not tested

  • A title with an XMA voice of more than 8 channels; the smoke title's run is a regression check only.
  • An XMA voice of more than 8 channels whose decoder fails to start still gets the 8-channel silent voice.
  • With #1249 (saturating avg_bytes in the same function): the two merge cleanly, and its test's 8-channel case is unchanged by the 64 clamp; not run together.
  • NVIDIA and Intel GPUs.

AI use

  • Claude Code with Claude Opus 5.5: found the problem, wrote the change, the tests and this description; I reviewed the diff and ran the tests and smoke runs above.

🤖 Generated with Claude Code

**@⁠emirduran707** on GitHub · 2026-11-24 14:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/1287) `emirduran707:xaudio2-xma-voice-channels` → `main` · +69 −2 · 1 files · 1 commits · open The XMA2 decoder accepts up to 16 channels (`xma2::MAX_CHANNELS`), and a decoded XMA voice is created with the decoder's channel count. But `pcm16_for_rate` clamped it to 8, so a voice with 9–16 channels got an 8-channel PCM voice. Each decoded frame still carried all its channels: with 10 channels, XAudio2 read every 10 samples as 1.25 frames of 8 channels, so the channels landed on the wrong speakers, drifted every frame, and the buffer played 1.25 times too long (2 times with 16 channels). XAudio2's limit is `XAUDIO2_MAX_AUDIO_CHANNELS` (64). On this machine, xaudio2_9 created plain PCM16 voices of 9, 10, 12, 16, 32 and 64 channels that played at the right length, and refused 65 (`XAUDIO2_E_INVALID_CALL`). `pcm16_for_rate` now clamps to 1–64. The XMA voice's state takes the decoder's channel count too: the silence that stands in for an undecodable buffer is sized from it, and with 8 there Windows refused the submit of a 10-channel voice. Silent fallback voices and Opus voices still use 8, as before. **What is in it** - `crates/xcl/src/hle/xaudio2.rs`: - the clamp, and the channel count of the XMA branch; - test `pcm16_keeps_up_to_64_channels`, which needs no device; - test `xma_voice_keeps_the_decoders_ten_channels`, which skips without an audio device. It uses an `XMA2WAVEFORMATEX` with 10 channels in 5 streams: the voice reports 10 channels, and an undecodable buffer submits. **Tested** - AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release - `cargo test --workspace -- --test-threads=4` on fe5b1f3: 743 passed, 0 failed, 41 ignored; no SKIPPED GPU tests (the audio tests ran; an audio device is present) - without the change: `pcm16_keeps_up_to_64_channels` `left: (8, 16, 768000)`, `right: (10, 20, 960000)`; with it both new tests pass **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1541 (PresentX 1541) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19650 MB ``` this PR: ``` xcl-smoke v1 commit: fe5b1f3b81b1ef64242c7ad1a8ef5f075b68d74a gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1515 (PresentX 1515) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19512 MB ``` **Not tested** - A title with an XMA voice of more than 8 channels; the smoke title's run is a regression check only. - An XMA voice of more than 8 channels whose decoder fails to start still gets the 8-channel silent voice. - With #1249 (saturating `avg_bytes` in the same function): the two merge cleanly, and its test's 8-channel case is unchanged by the 64 clamp; not run together. - NVIDIA and Intel GPUs. **AI use** - Claude Code with Claude Opus 5.5: found the problem, wrote the change, the tests and this description; I reviewed the diff and ran the tests and smoke runs above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The XMA2 decoder takes up to 16 channels (8 streams of 2), and the
decoded voice asks for dec.channels(), but pcm16_for_rate clamped the
PCM16 voice to 8 channels. A 10- to 16-channel XMA voice got an
8-channel voice while every decoded frame carried 10-16 interleaved
samples: channels landed on the wrong speakers, drifted each frame, and
the buffer was cut into 1.25-2x as many frames as it holds.

Windows XAudio2 2.9 takes a plain WAVEFORMATEX PCM16 voice of up to
XAUDIO2_MAX_AUDIO_CHANNELS. Measured on this machine (stereo 44.1 kHz
master): CreateSourceVoice succeeds for 2, 6, 8, 9, 10, 12, 16, 32 and
64 channels (GetVoiceDetails reports them), a 100 ms buffer of each
plays out in ~100 ms, and 65 channels fail with XAUDIO2_E_INVALID_CALL.
So the clamp is 64; WAVEFORMATEXTENSIBLE is not needed.

The silence that replaces an undecodable buffer is sized by the voice's
XmaInfo, which xma_info still clamps to 8: with the 10-channel voice its
8-channel frames were refused (0x88960001). The decoded XMA voice now
gives that XmaInfo the decoder's channel count. Silent voices and Opus
voices keep their own clamp to 8 and are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:49:28 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 14:34 UTC · original

Full-suite run, since this PR has no test report yet. Tested exact head fe5b1f3 (on its base 47efa2e).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 743 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: pcm16_keeps_up_to_64_channels, xma_voice_keeps_the_decoders_ten_channels.

Not tested

  • AMD, a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-24 14:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/1287#issuecomment-7134602894) Full-suite run, since this PR has no test report yet. Tested exact head `fe5b1f3` (on its base `47efa2e`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **743 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `pcm16_keeps_up_to_64_channels`, `xma_voice_keeps_the_decoders_ten_channels`. **Not tested** - AMD, a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-24 14:35 UTC · original

Independent native 16-channel XMA check on fe5b1f3 and its parent 930e8b4. Windows 11 build 26300, system XAudio2 2.9, Rust 1.99.1 MSVC, debug.

I submitted a synthetic XMA2 packet that produces no decoded samples to a muted voice. With the PR, the native voice reported 16 input channels and queued 15,360 zero PCM bytes for 480 frames. XAudio2 consumed exactly 480 source frames, drained the queue, and XCL freed the fallback buffer. The parent consumed 480 frames too, but its voice had eight channels and queued only 7,680 bytes. The stock 10-channel test also passed without a skip.

This checks native playback of synthetic fallback silence. Valid multichannel XMA decoding and retail audio were outside this run. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the scratch fixture and drafted this report.

**@⁠thehollowedone** on GitHub · 2026-11-24 14:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/1287#issuecomment-7134617201) Independent native 16-channel XMA check on [`fe5b1f3`](https://github.com/ivall/xcl/commit/fe5b1f3b81b1ef64242c7ad1a8ef5f075b68d74a) and its parent [`930e8b4`](https://github.com/ivall/xcl/commit/930e8b49c1c2ec683d22c724a398b39111cd0e56). Windows 11 build 26300, system XAudio2 2.9, Rust 1.99.1 MSVC, debug. I submitted a synthetic XMA2 packet that produces no decoded samples to a muted voice. With the PR, the native voice reported 16 input channels and queued 15,360 zero PCM bytes for 480 frames. XAudio2 consumed exactly 480 source frames, drained the queue, and XCL freed the fallback buffer. The parent consumed 480 frames too, but its voice had eight channels and queued only 7,680 bytes. The stock 10-channel test also passed without a skip. This checks native playback of synthetic fallback silence. Valid multichannel XMA decoding and retail audio were outside this run. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the scratch fixture and drafted this report.
Author
Owner

@⁠S1m0ne1997 on GitHub · 2026-11-25 14:46 UTC · original

Test report for fe5b1f3b81b1ef64242c7ad1a8ef5f075b68d74a (this PR's head), for #1607.

Tested

  • NVIDIA GeForce RTX 4090 24 GB (driver 621.40), AMD Ryzen 9 9950X3D, 47 GB RAM, Windows 11 Home 10.0.26300, rustc 1.100.0 (0ef1bc386 2026-11-09) x86_64-pc-windows-msvc, debug.
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4 at the head: 743 passed, 0 failed, 41 ignored.
  • SKIPPED (2): gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64).

Regression run (retail title, scripts/smoke.ps1 -Seconds 60, release; main built from the commit in its block, this PR from its head with no changes to crates/, both run with the scripts/smoke.ps1 of main, which hashes the name of the game folder)

main:

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: NVIDIA GeForce RTX 4090
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1599 (PresentX 1599)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16384 MB

this PR:

xcl-smoke v1
commit: fe5b1f3b81b1ef64242c7ad1a8ef5f075b68d74a
gpu: NVIDIA GeForce RTX 4090
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1655 (PresentX 1655)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19596 MB

Not tested

  • AMD, other NVIDIA cards and drivers, Linux. I did not review the diff; this report is the build, the suite and the regression run only.

AI use: Claude Code with Claude Opus 5.5 ran the build, the suite and the regression run and wrote this report at my request.

**@⁠S1m0ne1997** on GitHub · 2026-11-25 14:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/1287#issuecomment-7165792351) Test report for `fe5b1f3b81b1ef64242c7ad1a8ef5f075b68d74a` (this PR's head), for #1607. **Tested** - NVIDIA GeForce RTX 4090 24 GB (driver 621.40), AMD Ryzen 9 9950X3D, 47 GB RAM, Windows 11 Home 10.0.26300, `rustc 1.100.0 (0ef1bc386 2026-11-09)` `x86_64-pc-windows-msvc`, debug. - `cargo build --workspace`, then `cargo test --workspace -- --test-threads=4` at the head: **743 passed, 0 failed, 41 ignored**. - SKIPPED (2): `gpu_geometry_wave32_prefix_count_over_a_mask` (no wave64), `gpu_wave32_program_in_wave64_hardware` (no wave64). **Regression run** (retail title, `scripts/smoke.ps1 -Seconds 60`, release; `main` built from the commit in its block, this PR from its head with no changes to `crates/`, both run with the `scripts/smoke.ps1` of `main`, which hashes the name of the game folder) main: ``` xcl-smoke v1 commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324 gpu: NVIDIA GeForce RTX 4090 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1599 (PresentX 1599) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16384 MB ``` this PR: ``` xcl-smoke v1 commit: fe5b1f3b81b1ef64242c7ad1a8ef5f075b68d74a gpu: NVIDIA GeForce RTX 4090 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1655 (PresentX 1655) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19596 MB ``` **Not tested** - AMD, other NVIDIA cards and drivers, Linux. I did not review the diff; this report is the build, the suite and the regression run only. *AI use: Claude Code with Claude Opus 5.5 ran the build, the suite and the regression run and wrote this report at my request.*
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 01:17 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 26 ignored.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 01:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/1287#issuecomment-7179627661) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 26 ignored. Thanks! — Devin
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1287/head:github-bot/gh-1287'
git switch 'github-bot/gh-1287'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1287'
git switch 'github-bot/gh-1287'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1287'
git switch 'github-bot/gh-1287'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1287'
git switch 'main'
git merge --squash 'github-bot/gh-1287'
git switch 'main'
git merge --ff-only 'github-bot/gh-1287'
git switch 'main'
git merge 'github-bot/gh-1287'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.