audio: fix popping and time-stretching in output #966
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!966
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/966/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?
@mhakkuh on GitHub · 2026-10-02 00:18 UTC · original
mhakkuh:fix-audio-output-timing→main· +447 −62 · 3 files · 1 commits · merged 2026-10-02 09:22 UTCProblem
On Linux, Kyty's audio output could produce audible popping and time-stretching/distortion, most noticeably during speech.
A short speech sample could sound as though it was being stretched in time, for example a short "hey" becoming an elongated/distorted "heEEeEy", accompanied by pops.
The issue was reproducible with the SDL audio backend.
Reproduction
Tested with:
KytyPS5-2026-10-01-b3e419fThe SDL audio device was opened at 48000 Hz, 2 channels, and 2048 SDL sample frames.
The game submits audio in 256-sample blocks, corresponding to approximately 5.333 ms per guest audio block.
Investigation
Increasing the SDL audio buffer/queue size did not resolve the problem.
The relevant behavior was found in
AudioOutOutputs().After each output submission,
last_output_timewas being reset to the current host process time:This made the guest audio timing dependent on host scheduling jitter. Small variations in when
AudioOutOutputs()was processed could therefore affect subsequent audio pacing.Fix
Advance
last_output_timeby the duration of one guest audio block instead of resetting it to the current host time:For the tested 48 kHz / 256-sample configuration, one guest audio block represents approximately 5.333 ms.
This keeps the output timing reference tied to the guest audio stream rather than continually resynchronizing it to the host's current scheduling time.
Result
Before the change:
After the change:
Verification
The fix was tested by rebuilding Kyty and running the same game and audio sequences that reproduced the issue.
The issue was reproducible before the change and was no longer reproducible after the change.
Increasing the SDL audio queue/buffer size was also tested separately and did not produce the same improvement, helping isolate the issue to output timing rather than simply insufficient buffering.
Scope
This change only modifies how
last_output_timeis maintained.It does not modify the audio samples, guest sample rate, channel configuration, SDL audio format, SDL device buffer size, or host audio configuration.
@coderabbitai[bot] on GitHub · 2026-10-02 00:22 UTC · original · edited 2026-10-02 00:25 UTC
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
📝 Walkthrough
Walkthrough
Audio output latency and blocking queue capacity increase. Playback and capture setup set the SDL audio device sample-frame hint to
2048; playback also retrieves and logs the obtained audio specification. Output timestamps are maintained per port and advance by the port’s sample-block duration after the first output.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🟡 Moderate · up to
e5ceaThe timestamp change can consume the audio buffer’s intended scheduling cushion and reintroduce popping during rapid blocking submissions. Rebase the timestamp at queue-priming transitions before merging.
Security Architecture Review
Security architecture risk: 🔵 Low · up to
e5ceaThe change remains within audio handling and does not establish increased privileges or a new sensitive destination. However, advancing playback timestamps during unpaced buffering can introduce delays that also block unrelated audio operations.
Retained concerns
Security review details
Security Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
last_output_timefix, testing, results, and scope. It is directly related to the changeset.Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-10-02 00:22 UTC · original
On
src/libs/audio.cppline 593 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Exclude queue priming from the pacing deadline.
When a caller submits blocking buffers rapidly,
QueueSdlAudio()allows unpaced submissions untilqueue_primedbecomes true. This increment advanceslast_output_timeduring every priming submission.With 256 frames at 48 kHz, about 38 rapid submissions advance the timestamp by about 197 ms. The next submission then sleeps toward that future deadline at Lines 397–400. That wait consumes nearly the entire queue cushion and leaves playback exposed to scheduling jitter again. SDL queues submitted input for later consumption. (wiki.libsdl.org)
Rebase the pacing timestamp when the queue becomes primed. Preserve block-duration increments after that transition, and apply the same reset when the queue is cleared or becomes unprimed.
@coderabbitai[bot] on GitHub · 2026-10-02 00:22 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:
c4903d6b-03f2-4472-86d8-2867e9491770📥 Commits
Reviewing files that changed from the base of the PR and between
b3e419ff11and e5ceacb005b82733dbadb0f9778e65128cc672eb.📒 Files selected for processing (1)
src/libs/audio.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.