HLE/audio: defer loop_start skip to next frame and loop decode in pump #301
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!301
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-301"
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?
@AscilCH on GitHub · 2026-11-24 23:25 UTC · original
AscilCH:fix/audio-xma2-loop-skip-and-pump→main· +136 −3 · 1 files · 1 commits · openProblem
Two XMA2 audio playback bugs in
crates/victory-hle/src/modules/audio.rs:loop_startskip applied to theloop_endframe:decode(), whenloops > 0 && ends_loop,voice.skipwas immediately overwritten withloop_start's subframe skip (word 1, bits 17..20) before consumingvoice.skipon the currentloop_endframe'spcm.loop_start_subframe > 0, this ate samples out of theloop_endframe (dropping the tail of the loop) and decrementedvoice.skipbefore the next frame atloop_startwas decoded (emitting pre-loop samples instead of skipping them).pump()emits spurious 128-sample silence blocks on buffer switches and full-frame skips:pump()usedif voice.pcm.len() < SAMPLES_PER_BLOCK && !decode(context, voice)instead of awhileloop.decode()call returnedtruewithout pushing 128 samples — e.g., clearing an exhausted input buffer before switching to the second double-buffer, or skipping an entire 512-sample frame whenstart_skip >= 4—pump()wrote a silent 256-byte block into the output ring buffer. Conversely, at EOF with< 128tail samples left invoice.pcm,pump()returned early and dropped those tail samples.Fix
decode(), apply the currentvoice.skiptopcmand extendvoice.pcmbefore storingloop_start's skip intovoice.skip.pump(), replace theifwith awhile voice.pcm.len() < SAMPLES_PER_BLOCKloop (with a zero-progress cap of 16 empty steps, and flushing any remaining non-empty tail on EOF).loop_end_keeps_current_samples_and_defers_loop_start_skipandpump_keeps_decoding_across_empty_steps_without_injecting_silence.Verification
rustfmt --edition 2024 --check crates/victory-hle/src/modules/audio.rs(changed hunks): cleancargo test -p victory-hle --locked audio -- --test-threads=1: 7 passed, 0 failedcargo xtask policy: 169 files okcargo clippy -p victory-hle --all-targets --locked -- -D warnings: cleancargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings: clean(AI-assisted; synthetic tests only, no game data.)
@superboynick on GitHub · 2026-11-25 17:47 UTC · original
Numbers for the pump, gathered with an opt-in trace (PR #1046) on a run that reaches the prologue on an RTX 5070 Ti. One representative voice over 110 s of that run:
submissions 317,440 bytes total 2.8 KB/s process events 21 0.2/s queue depth 1 buffer, pending fell 35,330 -> 35,138 bytesFor reference, 48 kHz 16-bit stereo is 192 KB/s. So this voice is being fed at roughly 1.5% of real time, and the pump drains it at the same order of magnitude. Whatever the title believes about pacing, the amounts do not add up to continuous playback - which matches what it sounds like: a short fragment repeating rather than a clean dropout.
Completion is reported immediately after submission on this path, before any processing happens:
submit sub=2 bytes=45056 pending=43310 queue=1 complete sub=2 bytes=45056 pending=43310 queue=1 process sub=2 bytes=45056 pending=42415 queue=1 process sub=2 bytes=45056 pending=42415 queue=1So the title is told its submit finished while ~42 KB of it is still pending. If the title uses completion to decide when to refill, that alone could explain both the low submission rate and the repetition.
Two questions this raises for the loop handling you are changing here: should completion wait for the pending bytes of that voice to drain rather than firing at submit time, and should the pump step be driven by bytes consumed instead of a fixed 2 ms tick? I do not know which the title expects; the trace above is what I can measure today.
No buffer contents in the trace: the hash covers 64 bytes only. AI-assisted.
@superboynick on GitHub · 2026-11-25 18:05 UTC · original
Correction to my previous comment, before anyone acts on it.
I reported a single voice at 2.8 KB/s and compared it with 192 KB/s for real-time PCM. That comparison was wrong: that voice is one of 351, and most of them are short sound effects rather than a continuous stream. Summed across all voices in the same run, submissions are about 468 KB/s, which is not starved at all.
I also built the experiment my question implied - hold the completion until the voice's pending bytes drain, with a 200 ms ceiling - and measured both ways on the same machine and stage:
completion at submit time 60.6 s 777 submissions 28,374 KB 468 KB/s completion deferred 61.1 s 705 submissions 29,086 KB 476 KB/sThe difference is 1.6%, inside run-to-run noise. So the title does not pace its refills off our completion callback in any way that shows up here, and deferring it does not change the feed.
What stands from the earlier message is only the observation that completion fires while pending bytes remain, which is worth knowing but does not explain a repeated fragment by itself. I do not have a measurement that identifies the cause of the repetition yet, and I would rather retract the inference than have it sit in the thread as if it were established.
The tracing itself is unaffected and still available in #1046. AI-assisted.
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.