Audio: keep XMA frames split across rolling inputs #443

Open
github-bot wants to merge 2 commits from github-bot/gh-443 into main AGit
Owner

@⁠Quat3rnion on GitHub · 2026-11-24 03:28 UTC · original
Quat3rnion:victory-xma-split → main · +257 −6 · 2 files · 2 commits · open

What

XMA frames can straddle the two rolling input buffers the title gives the APU. The continuation lives in the first_frame_bit span of the next packet in the alternate bank. read_frame only saw one slice, so decode treated the bank as spent, switched, and restarted at the alternate bank's first new frame — dropping a valid 512-sample frame and letting the output pump write silence.

This adds a bit-level spanning reader in victory-formats and uses it before switching banks. The decoded frame is kept and the read position moves to the frame after the continuation in the alternate bank.

An AI tool wrote part of this change.

Tested

  • Linux: cargo test --workspace: 166 passed, 0 failed, 3 ignored. Two new hermetic tests — one compares the spanning bit gather against an unsplit frame byte-for-byte, the other drives the CPU output ring with a frame split across two separately allocated banks and asserts the frame is decoded.
  • Windows cross-build: cargo check --target x86_64-pc-windows-gnu --workspace --tests passes. No Windows host here.
  • cargo xtask policy passes (150 files ok). No game files or data from them were added.
  • Not measured: how often GTA VI actually splits frames across banks. The fix is deterministic from the documented packet layout, not tuned to an observed case.

Checklist

  • Workspace tests and Windows cross-check pass.
  • cargo xtask policy passes. No game files or data from them were added.
  • AI authorship is disclosed above.
**@⁠Quat3rnion** on GitHub · 2026-11-24 03:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/443) `Quat3rnion:victory-xma-split` → `main` · +257 −6 · 2 files · 2 commits · open ## What XMA frames can straddle the two rolling input buffers the title gives the APU. The continuation lives in the `first_frame_bit` span of the next packet in the alternate bank. `read_frame` only saw one slice, so `decode` treated the bank as spent, switched, and restarted at the alternate bank's first new frame — dropping a valid 512-sample frame and letting the output pump write silence. This adds a bit-level spanning reader in `victory-formats` and uses it before switching banks. The decoded frame is kept and the read position moves to the frame after the continuation in the alternate bank. An AI tool wrote part of this change. ## Tested - Linux: `cargo test --workspace`: 166 passed, 0 failed, 3 ignored. Two new hermetic tests — one compares the spanning bit gather against an unsplit frame byte-for-byte, the other drives the CPU output ring with a frame split across two separately allocated banks and asserts the frame is decoded. - Windows cross-build: `cargo check --target x86_64-pc-windows-gnu --workspace --tests` passes. No Windows host here. - `cargo xtask policy` passes (150 files ok). No game files or data from them were added. - Not measured: how often GTA VI actually splits frames across banks. The fix is deterministic from the documented packet layout, not tuned to an observed case. ## Checklist - [x] Workspace tests and Windows cross-check pass. - [x] `cargo xtask policy` passes. No game files or data from them were added. - [x] AI authorship is disclosed above.
A frame starting near the end of one APU input bank can finish in the continuation bits of the other. read_frame only saw one bank, so the frame was dropped and the pump wrote silence. Add a bit-level spanning reader and finish the frame before switching banks. Two hermetic tests cover the bit gather and the CPU output ring.
read_frame_spanning copied head bits raw, so packet headers and other streams' packets became frame payload when a frame crossed a packet boundary. Gather the head with the packet-aware Cursor, take exactly the remaining bits from the tail, and require the tail's first_frame_bit to match. Add a regression with a header inside the frame (review note on #443).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:04:11 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 03:38 UTC · original

Verified ab68f34 on Arch Linux x86_64 (rustc 1.98.1, cargo test -p victory-formats): 21 passed, 0 failed, 3 ignored.

Not covered: decoding real title audio streams (no game data) and playback under Wine.

**@⁠DaviTostes** on GitHub · 2026-11-24 03:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/443#issuecomment-7121280923) Verified `ab68f34` on **Arch Linux x86_64** (rustc 1.98.1, `cargo test -p victory-formats`): **21 passed, 0 failed, 3 ignored**. Not covered: decoding real title audio streams (no game data) and playback under Wine.
Author
Owner

@⁠Quat3rnion on GitHub · 2026-11-24 07:30 UTC · original

Rebased on current main. read_frame_spanning now gathers the head through the packet-aware Cursor, takes exactly the remaining bits from the tail, and requires first_frame_bit to match. Added a regression with a packet header inside the frame. New head f546d65.

**@⁠Quat3rnion** on GitHub · 2026-11-24 07:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/443#issuecomment-7125059734) Rebased on current main. read_frame_spanning now gathers the head through the packet-aware Cursor, takes exactly the remaining bits from the tail, and requires first_frame_bit to match. Added a regression with a packet header inside the frame. New head f546d65.
Author
Owner

@⁠amorcayReal on GitHub · 2026-11-24 20:09 UTC · original

I found a remaining boundary case on head 54f4329932, after the packet-aware Cursor changes.

When the first rolling input ends with another stream’s packet, cursor.bit() follows the preceding packet’s skip past the end of the input. The ? then returns None before read_frame_spanning can gather the continuation from the second input.

The attached patch adds a synthetic regression with packets laid out as:

  • First input: A0, then an interleaved B1 packet.
  • Second input: A2, containing the remaining frame bits.
    The same frame is read correctly from the unsplit buffer, but the spanning read fails on the current PR head.

The proposed fix breaks out of the head-gathering loop when the cursor reaches the input boundary, allowing the existing continuation-length check to run.

Verification: the regression fails before the fix. Afterward, the standalone XMA suite reports 8 passed, 2 ignored on Windows, Rust 1.98.1.

No game execution or playback improvement was verified. AI-assisted investigation and implementation using Codex/Luna; synthetic data only.

pr443-xma-fix.diff.txt

**@⁠amorcayReal** on GitHub · 2026-11-24 20:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/443#issuecomment-7143112462) I found a remaining boundary case on head 54f4329932b163fe9a83428c1177cd5bc8e3ca50, after the packet-aware Cursor changes. When the first rolling input ends with another stream’s packet, cursor.bit() follows the preceding packet’s skip past the end of the input. The ? then returns None before read_frame_spanning can gather the continuation from the second input. The attached patch adds a synthetic regression with packets laid out as: - First input: A0, then an interleaved B1 packet. - Second input: A2, containing the remaining frame bits. The same frame is read correctly from the unsplit buffer, but the spanning read fails on the current PR head. The proposed fix breaks out of the head-gathering loop when the cursor reaches the input boundary, allowing the existing continuation-length check to run. Verification: the regression fails before the fix. Afterward, the standalone XMA suite reports 8 passed, 2 ignored on Windows, Rust 1.98.1. No game execution or playback improvement was verified. AI-assisted investigation and implementation using Codex/Luna; synthetic data only. [pr443-xma-fix.diff.txt](https://github.com/user-attachments/files/35372536/pr443-xma-fix.diff.txt)
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:30 UTC · original · edited 2026-11-25 01:16 UTC

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-formats/src/xma.rs, crates/victory-hle/src/modules/audio.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/443#issuecomment-7148572407) · edited 2026-11-25 01:16 UTC <!-- victory-triage v1 head=54f4329932b163fe9a83428c1177cd5bc8e3ca50 verdict=needs-rebase at=2026-11-25T01:16:06Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-formats/src/xma.rs`, `crates/victory-hle/src/modules/audio.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-formats/src/xma.rs
  • crates/victory-hle/src/modules/audio.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-443'
git switch 'github-bot/gh-443'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-443'
git switch 'github-bot/gh-443'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-443'
git switch 'main'
git merge --squash 'github-bot/gh-443'
git switch 'main'
git merge --ff-only 'github-bot/gh-443'
git switch 'main'
git merge 'github-bot/gh-443'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
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
github/Marvisak--VIctory!443
No description provided.