Skip to content

fix(audio): replace queue clears with bounded callback buffering - #92

Draft
sunshinewithmoonlight wants to merge 5 commits into
xlanor:masterfrom
sunshinewithmoonlight:fix/audio-low-latency-buffer
Draft

sunshinewithmoonlight wants to merge 5 commits into
xlanor:masterfrom
sunshinewithmoonlight:fix/audio-low-latency-buffer

Conversation

@sunshinewithmoonlight

@sunshinewithmoonlight sunshinewithmoonlight commented Sep 13, 2026

Copy link
Copy Markdown

Summary

  • Replace SDL queued-audio playback and full-queue clears with a bounded PCM ring.
  • Start playback after a small prefill and fill callback underruns with silence.
  • Drop only the oldest complete 10 ms blocks when the high watermark is exceeded.
  • Add low-frequency diagnostics across the SDL callback and ring watermarks.

Problem

  • Current AudioManager requests 1024 samples, accumulates SDL queued audio,
    and clears the whole queue above 16000 bytes.
  • Full clears can cause audible gaps, and the retained queue adds latency.

Scope

  • Akira client playback only.
  • No video, input, network protocol, codec, or release-version changes.
  • Server-side packet redundancy and scheduling fixes live in
    OrbisWindowBridge and are not part of this PR.
  • The library/chiaki-ng submodule is not modified.

Follow-up from hardware testing

  • Initial hardware testing exposed audible distortion and noise that the
    original buffering change did not resolve.
  • Use an absolute discard sequence so high-watermark drops always advance the
    effective read position.
  • Preserve PCM during prefill instead of consuming it while outputting silence.
  • Remove the 1.80x playback gain.
  • Serialize producer writes with the SDL callback PCM access.
  • Rate-limit summary logging correctly.

Tests

  • Host ring-buffer unit tests cover prefill, wrapping, high-watermark drops,
    underruns, clear/new-session behavior, non-stereo parameters, and concurrent
    producer/consumer stress.
  • make test: 174 passed, 0 failed.
  • Focused ASan/UBSan and TSan runs: 10 passed, 0 failed each.
  • Akira build/CI result: pending.
  • Hardware retest of the rebuilt client is still pending.

Risk and rollback

  • Real-time callback synchronization and session cleanup are the main risks.
  • Revert the focused commit to restore the previous AudioManager.

This client-side change is not claimed to remove the full end-to-end latency by
itself; the sender packet history and pacing fixes are separate.

@xlanor

xlanor commented Sep 13, 2026

Copy link
Copy Markdown
Owner

I currently have a bunch of fixes in flight around something similar, so will only look at this after.

I ask that before sending any PRs you please test this on hardware first as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants