Skip to content

silent_audio: pace the 10 ms passes with a high-resolution timer (SILENT-AUDIO-PASS-CADENCE) - #2134

Draft
syfyra wants to merge 1 commit into
ProjectLeonida:mainfrom
syfyra:fix/silent-audio-spatial-cadence
Draft

syfyra wants to merge 1 commit into
ProjectLeonida:mainfrom
syfyra:fix/silent-audio-spatial-cadence

Conversation

@syfyra

@syfyra syfyra commented Nov 25, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as: SILENT-AUDIO-PASS-CADENCE (claim comment to follow)

What and why

runtime/shims/silent_audio.cpp PeriodicThread::run drives both silent streams' 10 ms passes. It waited for each pass with WaitForSingleObject(stop_, wait) and a timeout in whole milliseconds. On Windows a wait timeout ends on the system timer's tick: 15.625 ms for a process that has not raised the timer resolution, and nothing in runtime/ does (no timeBeginPeriod/NtSetTimerResolution). The 10 ms period therefore woke once per tick, and the fixed schedule re-anchored after each late wake: about 64 passes a second instead of 100.

The title activates ISpatialAudioClient first (docs/runtime_imports.md), and the spatial stream hands out 480 frames per pass and signals its event once per pass. A title paced by that event rendered about 30,700 frames a second against 48,000: its audio clock ran at 64% of real time. The IAudioClient stream's event came at the same rate (its padding is measured with QPC, so only its cadence was off).

The wait now uses a CREATE_WAITABLE_TIMER_HIGH_RESOLUTION timer set to the next pass's due time, with the stop event beside it in WaitForMultipleObjects, as the gameinput and d3d12_xs shims already do. Where the timer cannot be created, the timeout wait remains. It also ends the short busy spin the old loop did when less than 1 ms was left (wait truncated to 0).

Tested

Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo:

  • silent_audio_test now records when each spatial pass's event arrives and checks the median gap of the nine after Start (8 to 12.5 ms), unless the whole run took over 300 ms: a host that starved the passes says nothing about the timer, so there the gaps are only printed.
    • main: 10 passes in 143 to 159 ms, median gap 15.6 to 17.2 ms; the check fails in 3 of 3 runs.
    • this branch: 10 passes in 90 ms, median gap 10.0 ms; all 130 checks pass in 3 of 3 runs (earlier runs: 94 to 102 ms, 9.7 to 10.7 ms).
  • ctest -j 8 (162 CPU tests) passes, apart from xmem_test's system-wide commit check that tests: xmem commit-on-touch checks read the test's own view, not system commit (TEST-XMEM-COMMIT-CHECK) #1316 addresses.
  • scripts/check_no_game_data.py on both files.

Not tested under Wine; there the high-resolution timer may be unavailable and the old wait stays in use.

GPUs tested: n/a (CPU tests)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

…ENT-AUDIO-PASS-CADENCE)

PeriodicThread waited for each pass with WaitForSingleObject and a
timeout in milliseconds. On Windows a timeout ends on the system timer's
tick, 15.625 ms for a process that has not raised the timer resolution,
and nothing in the runtime does. The 10 ms period therefore woke once per
tick: about 64 passes a second instead of 100. A spatial stream hands out
480 frames each pass, so the title, which activates ISpatialAudioClient
first (docs/runtime_imports.md) and is paced by its event, rendered about
30,700 frames a second against 48,000: its audio clock ran at 64% of real
time. The IAudioClient stream's event came at the same rate.

The wait now uses a CREATE_WAITABLE_TIMER_HIGH_RESOLUTION timer, as the
gameinput and d3d12_xs shims do, set to the next pass's due time, with
the stop event beside it. Where the timer cannot be created, the timeout
wait remains.

Tested (Windows 11, MSVC 14.44): silent_audio_test records when each
spatial pass's event arrives and checks the median gap of the nine after
Start, unless the whole run took over 300 ms (a starved host, where the
spacing says nothing about the timer). On main: 10 passes in 143 to
159 ms, median gap 15.6 to 17.2 ms, the check fails in 3 of 3 runs. With
the fix: 10 passes in 90 ms, median gap 10.0 ms, all 130 checks pass in
3 of 3 runs. ctest -j 8 (162 CPU tests) passes apart from the
system-commit check of xmem_test that ProjectLeonida#1316 addresses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant