Audio: keep XMA frames split across rolling inputs #443
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/443"
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 Marvisak/VIctory. Originally posted by Quat3rnion on 2026-11-24T03:28:15Z.
What
XMA frames can straddle the two rolling input buffers the title gives the APU. The continuation lives in the
first_frame_bitspan of the next packet in the alternate bank.read_frameonly saw one slice, sodecodetreated 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-formatsand 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
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.cargo check --target x86_64-pc-windows-gnu --workspace --testspasses. No Windows host here.cargo xtask policypasses (150 files ok). No game files or data from them were added.Checklist
cargo xtask policypasses. No game files or data from them were added.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T06:14:42Z.
Review: CHANGES_REQUESTED
Tested
ab68f34on Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (249 passed, 0 failed; the branch is based on an older main).The idea is right: finish a frame that straddles the two rolling inputs instead of dropping it. But
read_frame_spanningreads the head part differently fromread_frame.crates/victory-formats/src/xma.rs,read_frame_spanning: the head bits are copied raw, without theCursor's packet handling.Cursor::bitjumps over each packet's 32-bit header and over other streams' packets (skip) when it crosses a packet boundary. The new loop copieshead[start + i]straight up tohead_bits.skipis non-zero, the copied frame includes header bits as payload, so the decoder gets a corrupted frame. That is audible noise instead of the current dropped frame.head_bits - start >= bitshas the same issue, since it measures raw distance including headers.Cursorbut the body without it, so the two disagree whenever a header sits in between.Suggested fix:
Cursoruntil it would run pastdata, counting the payload bits it produced.bits - gotbits from the tail starting at bit 32.continuation == bits - got. That also catches a tail that doesn't belong to this frame; today onlycontinuation < bitsis checked.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T03:38:12Z.
Verified
ab68f34on 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.
Imported from Marvisak/VIctory. Originally posted by Quat3rnion on 2026-11-24T07:30:05Z.
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.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:34:19Z.
Review: APPROVED
Re-tested
f546d65on Windows 11, RTX 5070, MSVC:cargo test -p victory-formats -p victory-hle110 passed, includinga_spanning_frame_skips_the_packet_header_it_crosses.This addresses my earlier review. The head part of a spanning frame is now gathered through the packet-aware
Cursor, which skips packet headers and other streams' packets. The tail is taken only when its header's continuation count equals the bits still needed (continuation != neededgivesNone), so a tail from a different frame is no longer glued on.PACKET..PACKET + HEADER_BITS(packet 1's header), butSTARTis already past it, late in packet 1. The frame actually crosses packet 2's header at2 * PACKET, which the payload loop then overwrites with frame bits. The test still passes becauseread_frame(&whole)andread_frame_spanningrun the same cursor over the same bytes, but it no longer shows a real header being skipped. Changing the skip to(2 * PACKET..2 * PACKET + HEADER_BITS)keeps packet 2's header intact and makes the assertion mean what its name says.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by amorcayReal on 2026-11-24T20:09:06Z.
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:
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
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:30:00Z.
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 currentmain.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Quat3rnion on 2026-11-27T02:47:26Z.
@amorcayReal Thanks for the boundary case and the reproducer. New head: the head-gathering loop now stops when the packet cursor leaves the head input, so the existing continuation path runs; I added your regression test.
cargo test -p victory-formats xma: 23 passed, 0 failed, 3 ignored (the new case included). Windows GNU workspace check passes. Please re-check.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.