xaudio2: pin multi-stream XMA2 decode (packet base, header skip, interleave) #580

Open
qnjk wants to merge 1 commit from qnjk/Darner:xaudio2-multistream-test into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: nothing. This is a tests-only change (no production line is edited).

  • What it pins: decode (crates/darner-hle/src/modules/xaudio2.rs:302) was reached by exactly one test, xma2_voices_play_through_the_host, which builds one two-channel stream and submits a packet of zeros. xma::read_frame refuses that packet outright (if bits <= LENGTH_BITS as usize || bits == 0x7fff { return None; }, darner-formats/src/xma.rs:132), so decode returned an empty vector and the existing test only exercised the silence fallback. Nothing called decode with a stream index above 0 or with a frame that actually decodes, so three things that can only go wrong silently were unpinned: the per-stream packet base s * xma::PACKET_BYTES * 8, the 32-bit packet-header skip added to first_frame_bit on the same line, and the shortest-stream minimum plus stream-order interleave. A mistake in any of them plays noise where PCM belongs, and the only symptom is a once-only warning.

  • This change adds a test that decodes a real two-stream packet pair and pins all three, plus the silence contract the caller relies on.

How it was tested

  • Tested revision: 13fe482 (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-hle --lib -- xaudio2 — 5 passed, 0 failed, with the new test among them; the crate's full suite is green too.
    • New modules::xaudio2::tests::multi_stream_packets_decode_and_interleave_in_stream_order: stream 0's packet (three frames) first and stream 1's (two frames) second, decoded with two mono decoders seeded with opposite overlap values so the streams are told apart by what they carry into their first frame. It pins: the per-stream base (a wrong base changes the length to 3072 instead of 2048); the 32-bit header skip (without it the length is 0 instead of 2048); the interleave (stream 0's sample is the even one, first == -second, only in the first frame — a reversed interleave gives -1000, 1000); the shortest-stream minimum (two 512-sample frames even though stream 0's packet holds three); and that a buffer in which no frame begins decodes to empty.
    • cargo clippy --locked -p darner-hle --all-targets -- -D warnings passes.
    • Fail-before: reading the code, all three are correct, so there is no old behaviour to break. The test's teeth were shown by mutating each of the three in turn and watching the corresponding assertion fail; each mutation was reverted with git checkout --.
  • Changes a default: no. Tests only.
  • A/B result: not applicable — tests-only change.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3, cargo test --workspace --locked: not run to completion here; the pre-existing darner-gpu test deadlock (#224) and darner-shader waterfall fixture failure (#227) make the whole-workspace run non-green on this machine. darner-hle's suite is green.
  • Gameplay, when relevant: not applicable — tests-only change.
  • Shader wave sizes tested, when relevant: not applicable.
  • Hardware dependence: none.
  • Coverage gaps: the packets are synthetic (silent frames plus a seeded overlap), not a title's; stream counts above two and the streams(...) refusal paths are not exercised.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not applicable: tests-only change, stated at the top.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md. (cargo xtask policy: 576 files ok.)
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found. No open pull request changes crates/darner-hle/src/modules/xaudio2.rs (checked against the file list of all 189 open pull requests), and no open or closed issue mentions XMA2 multi-stream decode.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: nothing. This is a **tests-only** change (no production line is edited). - What it pins: `decode` (`crates/darner-hle/src/modules/xaudio2.rs:302`) was reached by exactly one test, `xma2_voices_play_through_the_host`, which builds one two-channel stream and submits a packet of zeros. `xma::read_frame` refuses that packet outright (`if bits <= LENGTH_BITS as usize || bits == 0x7fff { return None; }`, `darner-formats/src/xma.rs:132`), so `decode` returned an empty vector and the existing test only exercised the silence fallback. Nothing called `decode` with a stream index above 0 or with a frame that actually decodes, so three things that can only go wrong silently were unpinned: the per-stream packet base `s * xma::PACKET_BYTES * 8`, the 32-bit packet-header skip added to `first_frame_bit` on the same line, and the shortest-stream minimum plus stream-order interleave. A mistake in any of them plays noise where PCM belongs, and the only symptom is a once-only warning. - This change adds a test that decodes a real two-stream packet pair and pins all three, plus the silence contract the caller relies on. ## How it was tested - Tested revision: `13fe482` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-hle --lib -- xaudio2` — 5 passed, 0 failed, with the new test among them; the crate's full suite is green too. - New `modules::xaudio2::tests::multi_stream_packets_decode_and_interleave_in_stream_order`: stream 0's packet (three frames) first and stream 1's (two frames) second, decoded with two mono decoders seeded with opposite overlap values so the streams are told apart by what they carry into their first frame. It pins: the per-stream base (a wrong base changes the length to 3072 instead of 2048); the 32-bit header skip (without it the length is 0 instead of 2048); the interleave (stream 0's sample is the even one, `first == -second`, only in the first frame — a reversed interleave gives `-1000, 1000`); the shortest-stream minimum (two 512-sample frames even though stream 0's packet holds three); and that a buffer in which no frame begins decodes to empty. - `cargo clippy --locked -p darner-hle --all-targets -- -D warnings` passes. - Fail-before: reading the code, all three are correct, so there is no old behaviour to break. The test's teeth were shown by mutating each of the three in turn and watching the corresponding assertion fail; each mutation was reverted with `git checkout --`. - Changes a default: no. Tests only. - A/B result: not applicable — tests-only change. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3, `cargo test --workspace --locked`: not run to completion here; the pre-existing `darner-gpu` test deadlock (#224) and `darner-shader` waterfall fixture failure (#227) make the whole-workspace run non-green on this machine. `darner-hle`'s suite is green. - Gameplay, when relevant: not applicable — tests-only change. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. - Coverage gaps: the packets are synthetic (silent frames plus a seeded overlap), not a title's; stream counts above two and the `streams(...)` refusal paths are not exercised. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not applicable: tests-only change, stated at the top. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. (`cargo xtask policy`: 576 files ok.) - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found. No open pull request changes `crates/darner-hle/src/modules/xaudio2.rs` (checked against the file list of all 189 open pull requests), and no open or closed issue mentions XMA2 multi-stream decode. - Replaces or overlaps: none found
`decode` reads stream `s` from packet `s` of the buffer, skips each
packet's 32-bit header before its first frame, and interleaves the
decoders in stream order for as many frames as the shortest stream
decoded. The only test that reached it, `xma2_voices_play_through_the_host`,
built one two-channel stream and submitted a packet of zeros that
`xma::read_frame` refuses, so `decode` returned nothing there: the
per-stream packet base, the header skip and the interleave were all
unpinned. A mistake in any of them plays noise where PCM belongs, and
the only symptom is a warn-once that no gate would fail.

The new test builds one packet of silent mono frames per stream, with
three frames in stream 0's and two in stream 1's, so each stream has its
own packet and the shortest stream's length is the one played. Each
decoder is seeded with a carried overlap, which a silent frame turns
into a signed signal in its first frame only, so the interleave is
visible: stream 0's samples are the even ones and stream 1's the odd
ones, opposite in sign. With the per-stream base dropped the test reads
3072 samples for 2048; with `+ 32` dropped, 0; with the interleave
reversed, `sample 0: -1000, 1000`.
TrustNo1 changed title from [pr-tests][audio] xaudio2: pin multi-stream XMA2 decode (packet base, header skip, interleave) to xaudio2: pin multi-stream XMA2 decode (packet base, header skip, interleave) 2026-12-06 03:26:53 +00:00
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 'xaudio2-multistream-test:qnjk-xaudio2-multistream-test'
git switch 'qnjk-xaudio2-multistream-test'

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.

git switch 'Main'
git merge --no-ff 'qnjk-xaudio2-multistream-test'
git switch 'qnjk-xaudio2-multistream-test'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-xaudio2-multistream-test'
git switch 'qnjk-xaudio2-multistream-test'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-xaudio2-multistream-test'
git switch 'Main'
git merge --squash 'qnjk-xaudio2-multistream-test'
git switch 'Main'
git merge --ff-only 'qnjk-xaudio2-multistream-test'
git switch 'Main'
git merge 'qnjk-xaudio2-multistream-test'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!580
No description provided.