Skip to content

Bound audio producer backpressure by actual PCM consumption - #196

Merged
mstan merged 1 commit into
RetroPortingToolKit:mainfrom
sergiomanzur:codex/audio-producer-backpressure
Oct 21, 2026
Merged

mstan merged 1 commit into
RetroPortingToolKit:mainfrom
sergiomanzur:codex/audio-producer-backpressure

Conversation

@sergiomanzur

Copy link
Copy Markdown
Contributor

Audio callbacks can run without consuming native PCM. Previously, that callback activity rearmed the desktop producer's stall timeout, potentially adding another 250 ms at each later checkpoint.

Add optional host producer-wait registration and invoke the desktop callback after releasing the outermost APU mutex. Bound waits with wrap-safe ticks and rearm stalled pacing only after FIFO consumption. Preserve inactive-consumer, fast-forward, and speculative-frame bypasses. A thread-local guard prevents recursive entry when the host callback inspects the FIFO under its mutex. Pacing does not discard PCM or alter guest clocks.

Validation:

  • python -m pytest tests/test_audio_producer_pacing.py -q: 2 passed. The original callback-only stall behavior was reproduced before the fix.
  • tests/runtime_dispatch/run_apu_port_guest_time_test.ps1: passed.
  • tests/audio/run_dsp_trace_gate_test.ps1: all four variants passed.
  • Production audio-delivery harness compiled and executed with SDL2: passed.
  • Independent code review found no actionable issues.

Validation limits: the completed broad local run had 755 passed, 6 skipped and the same 36 environment failures as the baseline (shell discovery/compiler environment). A corrected-PATH retry was stopped in the scaffolder. The existing audio trace matrix also failed audio_trace_clock_gate_test_0 (wall calls with path stats: got 0, want 7); SDL3 headers were unavailable. No hardware-device or ROM playback qualification is claimed here. A permanently stopped consumer intentionally allows execution after the bounded wait, so existing FIFO overflow remains possible.

Extracted from ISSD Native's audio-upload investigation and adapted to current upstream pacing. No obsolete handshake API, timing-model replacement, or commercial game content is included. See docs/audio-producer-backpressure.md for host integration and reproduction.

@mstan mstan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed lock order, recursion prevention, tick-wrap handling and rearming on actual PCM consumption. The host wait is bounded and bypassed for inactive consumers, fast-forward and speculative frames. Production audio-delivery, APU-port guest-time and all four DSP trace-gate variants pass. This does not establish the cause of the earlier X2/X3 startup delay.

Validation: five-head integration passed 826 Python tests (2 skipped) and 109 Rust tests. After excluding #198 for its separate title-save compatibility blocker, the four-head combination passed all 69 focused tests. Linux, Windows, macOS and Lua CI are green for this reviewed head. No new cross-title gameplay playtest is claimed.

@mstan
mstan merged commit 29420f1 into RetroPortingToolKit:main Oct 21, 2026
8 checks passed
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