audio: keep blocking AudioOut writes on an even cadence #822
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!822
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/822/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?
@6d4m on GitHub · 2026-09-25 05:12 UTC · original
6d4m:fix/audioout-write-pacing→main· +21 −2 · 1 files · 2 commits · merged 2026-09-25 08:33 UTCFixes slow, warbling audio in games that mix on a timer (Unity/FMOD titles such as PPSA03647 and PPSA09232).
Problem
QueueSdlAudioenforces a minimum cushion of queued audio before it lets the guest write again, but it only checks queue depth. Nothing stops the guest from refilling the queue as fast as it can, so its audio thread ends up running in bursts: several buffers queued back to back, then blocked for the whole cushion while it drains.Measured on PPSA03647 with 256-frame blocks at 48 kHz, the interval between guest writes alternated between 0 ms and ~44 ms instead of a steady 5.33 ms buffer period:
The long-run rate is correct either way — 48000 frames/s in both cases — which is why this is easy to miss. Format, sample rate, buffer contents, queue depth and drain timeouts all look healthy. But a mixer driven by a timer cannot track a cadence that jumps between 0 ms and 44 ms, and the result is music that is slow and warbles.
Fix
Keep the cushion exactly as it was, and additionally hold writes to one buffer period so the cadence stays even. The wait is skipped when the stream is running low, so it can never cause an underrun, and the deadline is per-port so multiple output ports do not interfere with each other.
Testing
PPSA03647 (3D Mini Golf) on Linux, menu music, before and after. With the fix the music plays correctly and the write interval is steady at ~5.4 ms with microsecond-level deviation.
This is not Windows-specific in principle; it just does not show up as clearly there, since a bursty cadence is easier for a Windows audio backend to absorb.
AI assistance (OpenCode) was used for the measurements and this description; I reviewed the results before posting.
@coderabbitai[bot] on GitHub · 2026-09-25 05:19 UTC · original
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
📝 Walkthrough
Walkthrough
PortOutnow stores a deadline for the next blocking write. When the buffer period is nonzero and the SDL queue exceeds two prepared buffers,QueueSdlAudioresets a stale deadline or waits until a future deadline, then advances it by one buffer period. Existing queue-depth pacing and its 200 ms timeout remain unchanged.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🔵 Low · up to
0d8c8Simultaneous writes to one audio port may produce audible pacing errors. Serialize per-port writes before merging, or accept this bounded risk.
Security Architecture Review
Security architecture risk: 🔵 Low · up to
0d8c8The change affects audio-write pacing, not access privileges or a new external interface. No introduced security issue was established, though concurrent access and failure recovery need clearer guarantees.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-09-25 05:19 UTC · original
On
src/libs/audio.cppline 395 (outdated):🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6580
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 19062
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 18846
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 16002
Serialize each output port through its deadline update and stream write.
AudioOutOutputvalidates the handle underm_mutex, butAudio::AudioOutOutputsruns after that lock is released. Two calls for the same handle can therefore enterQueueSdlAudioconcurrently. The calls race onPortOut::next_write, and their stream writes are not serialized with the deadline updates.This can break the intended output cadence and cause audible pacing errors. Use a per-port mutex for all output modes. Acquire it before
QueueSdlAudio, and acquire the same mutex inAudioOutClosebefore resetting the port. Keep the mutex outsidePortOut, becauseAudioOutCloseassignsport = {}.Suggested fix
@coderabbitai[bot] on GitHub · 2026-09-25 05:19 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
08bdf1c6-0b14-4e18-9378-07ad511e2019📥 Commits
Reviewing files that changed from the base of the PR and between
5a705dd15fand0d8c85a936.📒 Files selected for processing (1)
src/libs/audio.cppIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@Nmzik on GitHub · 2026-09-25 08:29 UTC · original
@6d4m Thanks!