Audio: an XMA loop's skip is of its first frame, not of its last #194
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/194"
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 Maraco91 on 2026-11-24T01:18:07Z.
What
A looping XMA context with a loop-start skip plays the wrong samples at every turn of the loop.
When a frame ends a loop,
decodecuts it at the loop's end subframe, setsvoice.skipfrom the context ("loop start subframes to skip", word 1 bits 17-19) and jumps back to the loop's start. But the lines right after it applyvoice.skipto the frame in hand, which is the loop's last frame:So the head of the loop's last frame is dropped, and the loop's first frame, decoded next with nothing left to skip, plays from its start: the subframes before the loop point. With an end subframe of 1 and a skip of 2 the last frame contributes nothing at all. The total number of samples per turn comes out the same, which is why the output ring's counts never showed it; what plays at the seam is wrong, by up to 7 subframes (896 samples).
Now the pending skip is applied to the frame in hand as before (the stream's start skip; or the loop's, when its first frame is also its last), and the loop's skip is set after that, for the frame decoded next.
Basis: the field's description in this file's own header, and the public XMA2 loop definition, where the skip is "subframes to skip in the start frame until we reach the loop" (from memory of
xma2defs.h). I have not compared against the console's output or a title's stream (I have no game files).Tested
Windows 11 Pro 10.0.26200, rustc 1.98.1 (
x86_64-pc-windows-msvc), no game data, no GPU involved.New unit test
a_loop_skips_subframes_of_its_first_frame: the existing synthetic silent stream (frames at bits 32, 63, 94), a context looping once over the first two frames with end subframe 1 and a skip of 2 subframes, anddecodecalled frame by frame. It checks how many samples each call adds and where the read position goes: 512 (the first frame, before the loop), 256 (the loop's last frame: its first two subframes), 256 (the loop's first frame without its first two), then, control, 512 again with no loops left and the read position on the third frame. The stream is silence, so it proves which frame each cut is taken from, not the audio.main(d2a4bae) + the test only:cargo test -p victory-hle --lib a_loop_skipsfails:the loop's last frame: left: 0, right: 256.cargo test -p victory-hle --lib audio::: 6 passed, 0 failed (among themxma_contexts_decode_into_their_output_rings, unchanged: 26 blocks).cargo clippy -p victory-hle --tests: nothing inaudio.rs.rustfmt --check: nothing in the lines changed (existing differences atpumpanddump_input, and inaudio/capture.rs).cargo xtask policy --staged: ok.Not tested: a title run, or by ear.
#88 touches
advance_readin this file, notdecode.AI-assisted (Claude Code); the tests above were run on the machine described.
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:32:10Z.
Tested
985d8d4(Arch Linux x86_64, rustc 1.98.1,cargo test -p victory-formats): pass.No game data used.
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T09:50:09Z.
Review: APPROVED
Tested
985d8d4on Windows 11, RTX 5070, MSVC: the workspace passes (196 outsidevictory-shader;victory-shader --libsingle-threaded: 69), includinga_loop_skips_subframes_of_its_first_frame.The bug is a real ordering mistake.
voice.skipwas set to the loop-start skip and then applied to the frame in hand, which is the loop's last frame. Moving the assignment after the skip is consumed applies it to the next decoded frame, the loop's first. The remainingvoice.skipfrom stream start is still honoured on the current frame. The test checks all four steps, including the "no loops left" pass through to the third frame.No issues found.
AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:21:57Z.
Automated triage for the maintainers.
Merge candidate. In
decodeincrates/victory-hle/src/modules/audio.rs, when a frame ends a loop, main setsvoice.skipto the loop-start skip and then immediately applies it to the frame being decoded, i.e. the loop's last frame instead of its first. The PR applies the pending skip to the current frame first and then sets the loop's skip for the next frame, which matches the field's description in the file header ("loop start subframes to skip"); the single-frame loop case still works. The new testa_loop_skips_subframes_of_its_first_framechecks how many samples each frame contributes, which is the right thing to check.CI: no check runs on the head commit.
Generated by Claude Code