audio: avoid mixer stalls while decoding XMA voices #515
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/gamingwithhomie--larp!515
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-515"
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?
@HolyRoses on GitHub · 2026-12-06 01:44 UTC · original
HolyRoses:main→main· +711 −132 · 6 files · 2 commits · openMixer read commands currently share the lock held while an XMA voice's output ring is decoded and filled. A long decode or a preempted decoder can therefore hold up the title's time-critical mixer, contributing to audio stalls and crackling.
Separate decoder state from ring bookkeeping so mixer reads take only the short ring-update lock. Decode and publish one output block per voice per round, releasing the voice lock between blocks, so other voices get a turn before one ring is filled. Reuse the scheduling list between passes.
The port retains existing overlap carry, input-refill handling, complete-block guards, read/write offset wrapping, decoder priority, and Opus/PCM conversion. Scheduling logic is adapted from the December 5 source snapshot identified as
67a25de.Two regression tests verify that mixer reads proceed while decoder state is locked and that the scheduler visits the next voice before refilling the first.
Validation
459db13,cargo xwin check --locked -p larp-hle --target x86_64-pc-windows-msvcpassed. The audio source is byte-for-byte identical to the previously tested version.Native Windows cutscene playback has not yet been evaluated, so improvement to the reported desync/crackling still needs an in-game comparison.
@christopear on GitHub · 2026-12-06 02:01 UTC · original
I think the lock split leaves a Rust-side race on context word 1 in
ef7eab2b. This follows from the access paths even without concurrent writes by the title.advance_read()holdsslot.ringand usesset_field(1, 31, 1, 1)for a nonzero advance. That reads and writes the whole u32.slot.voicewhenstep()reads that same word's writable bit, before acquiring the ring lock. There are also whole-word reads for other fields during decode, includingchannels(). The outer XMA lock is shared on both paths.read_volatileandwrite_volatiledo not synchronize those accesses. Even writing the same bit value, or reading a different field of the word, can race. The previous common voice lock serialized these two paths.Could the decoder snapshot the needed shared words under a short ring lock, decode from the snapshot outside the lock, then recheck the live read position under the publication lock? I'd audit all word-1 reads when doing that. The existing progress test holds the voice mutex without actually reading the context concurrently, so it can still pass with this issue. This is a source review finding. I haven't attributed an audible glitch or crash to it.
@HolyRoses on GitHub · 2026-12-06 02:39 UTC · original
@christopear recheck pls
@christopear on GitHub · 2026-12-06 02:56 UTC · original
Rechecked
1f44510. My earlier objection about the mixer and decoder racing on context word 1 is resolved for those access paths.I used the new concurrent test as a positive control against
ef7eab2bon x86-64 Linux. ThreadSanitizer caught the race between the decoder read and the mixer update. On the revised head:The snapshot is taken under the ring lock, field updates merge into the live word under that lock, and publication checks the live read position again. This addresses both the unsynchronized access and the risk of losing a mixer advance during decode. I haven't measured audible stutter or cutscene behavior.
@TrinityForever15 on GitHub · 2026-12-06 03:17 UTC · original
Ported onto
amd-testv1.1.7 and running on RX 6650 XT. All 17modules::audiounit tests pass, including this PR'sxma_read_commands_do_not_wait_for_decoder_state,xma_decode_and_mixer_reads_share_context_safely,xma_visits_the_next_voice_before_refilling_the_firstandxma_publication_uses_the_live_read_position. In play the XMA decoder thread starts and decodes normally, with no XMA errors in the log. I haven't done a dedicated before/after audio comparison, so I can't put a number on the stall reduction yet. https://github.com/iceboerg00/larp-amd/issues/64View 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.