XAudio2: validate and clamp voice sample rates and channel counts #1427
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1437"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by slopgobblercobbler on 2026-11-24T15:57:02Z.
Summary
Audits and bounds XAudio2 voice sample rates and channel counts in
crates/xcl/src/hle/xaudio2.rs:XAUDIO2_MIN_SAMPLE_RATE(11,025 Hz),XAUDIO2_MAX_SAMPLE_RATE(192,000 Hz),XAUDIO2_MIN_CHANNELS(1),XAUDIO2_MAX_CHANNELS(8), andXAUDIO2_E_INVALID_CALL(0x88960001).is_valid_sample_rate,is_valid_channel_count,clamp_sample_rate(defaults 0 to 48 kHz, clamps to [11025, 192000]), andclamp_channel_count(clamps to [1, 8]).pcm16_for_rate,opus_format, andxma_info: clamp channel counts to 1..=8 and sample rates to 11025..=192000 Hz to prevent invalid parameter rejection by host XAudio2.create_source_voice: added fallback clamping for plain PCM formats rejected by host XAudio2 due to out-of-bounds rates/channels, retrying with clamped PCM16 so titles with unusual audio specs continue playing via silent voice rather than failing creation.create_mastering_voice: sanitized out-of-bounds channels (> 8) or invalid sample rates to default native endpoint format.sample_rate_and_channel_bounds_validation_and_clampingandclamped_voices_accepted_by_windows_xaudio2.Changes
crates/xcl/src/hle/xaudio2.rs:Tested
cargo test -p xcl -- xaudio2: 11 passed, 0 failed (100% pass rate).Not Tested
AI Use
Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T17:05:40Z.
Review: COMMENTED
AI-assisted review; I checked the CreateMasteringVoice sample-rate constraints against the XAudio2 API contract.
Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-24T16:24:33Z.
Regression run for this PR: head
ac222f7, based onmaincbea872. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release,XCL_NETWORK=0, A pressed every 4 s from 20 s,scripts/smoke.ps1on a retail title for 60 s.main
cbea872:this PR:
No device removals or crashes; 113 % of main's frames, 118 % of its peak commit.
Peak commit in both runs is mostly the pipeline preload's DXC compiles on this machine (#1035; 23 GB on
mainwithXCL_PSO_PRELOAD=0), so it varies run to run.Not tested: the whole suite; whether the title reaches the changed code in these 60 s.
Written with Claude Code (Claude Opus 5.5) from runs on this machine.
Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T16:53:52Z.
Full-suite run, since this PR has no test report yet. Tested exact head
ac222f7(on its basecbea872).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 758 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.sample_rate_and_channel_bounds_validation_and_clamping,clamped_voices_accepted_by_windows_xaudio2.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 758 passed, 0 failed, 41 ignored, no skips.Not tested
AI use
Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T17:05:40Z.
Code review location:
crates/xcl/src/hle/xaudio2.rs; line 1032CreateMasteringVoice also requires a nonzero
InputSampleRateto be a multiple ofXAUDIO2_QUANTUM_DENOMINATOR(100). This check treats 11,025 Hz as valid and passes it toorig, but XAudio2 rejects that rate for a mastering voice, so this fallback can still fail. Please default rates that violate the quantum requirement and add a test for 11,025 Hz. AI-assisted review; I checked the CreateMasteringVoice contract and the XAudio2 header.Imported from ivall/xcl. Originally posted by slopgobblercobbler on 2026-11-24T18:25:16Z.
Review: COMMENTED
No description provided.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:52:30Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
Imported from ivall/xcl. Originally posted by slopgobblercobbler on 2026-11-24T18:25:16Z.
Code review location:
crates/xcl/src/hle/xaudio2.rs; line 1032Addressed in commit
e49f75d: updated CreateMasteringVoice to checkate % XAUDIO2_QUANTUM_DENOMINATOR == 0 for non-zero InputSampleRate, defaulting non-conforming rates (such as 11,025 Hz) to 0 (endpoint native rate). Also added mastering_voice_quantum_sample_rate_defaults_to_native verifying 11,025 Hz defaults to native format and passes voice creation against Windows XAudio2.
Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:31:09Z.
Regression run of
e49f75d1on the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon4178e888, this PR on its head commit with no uncommitted changes, same title and time.Against the limits in CONTRIBUTING.md: 101 % of
main's frames, 100 % of its peak commit, no crash, no device removal.AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0,
cargo build --release -p xcl, 60 s,XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.AI use: Claude Code (Claude Opus 5.5) built both trees and ran
scripts/smoke.ps1; I checked the blocks before posting.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T05:13:11Z.
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T07:40:15Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:44:47Z.
Triage (#1607) – head
e49f75dNo open PR makes the same change (the 7 lines shared with #1881 are test voice-teardown boilerplate).
The limits added in xaudio2.rs are not XAudio2's: xaudio2.h has XAUDIO2_MIN_SAMPLE_RATE 1000, XAUDIO2_MAX_SAMPLE_RATE 200000 and XAUDIO2_MAX_AUDIO_CHANNELS 64, not 11025 / 192000 / 8.
Because opus_format() and xma_info() now clamp the declared rate, an 8 kHz Opus voice (valid in Opus and in XAudio2) is passed to opus::Decoder::new and pcm16_for_rate as 11025 Hz, a rate Opus cannot decode to; on main it plays at 8 kHz. Rates above 192 kHz would likewise be played at the wrong speed.
The CreateSourceVoice retry only builds a silent stand-in voice for PCM Windows rejected, which could be a separate small change using the real limits.
Recommendation: close (bad: clamps valid rates and breaks 8 kHz Opus voices).
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.