Audio: an XMA loop's skip is of its first frame, not of its last #194
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!194
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/194/head"
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?
@Maraco91 on GitHub · 2026-11-24 01:18 UTC · original
Maraco91:audio/xma-loop-start-skip→main· +72 −2 · 1 files · 1 commits · merged 2026-11-25 00:15 UTCWhat
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
@DaviTostes on GitHub · 2026-11-24 01:32 UTC · original
Tested
985d8d4(Arch Linux x86_64, rustc 1.98.1,cargo test -p victory-formats): pass.No game data used.
@Marvisak on GitHub · 2026-11-25 00:21 UTC · original
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