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

Open
opened 2026-11-26 21:20:10 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2134
Author: @syfyra
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/silent-audio-spatial-cadence


📝 Commits (1)

  • 2945eff silent_audio: pace the 10 ms passes with a high-resolution timer (SILENT-AUDIO-PASS-CADENCE)

📊 Changes

2 files changed (+34 additions, -6 deletions)

View changed files

📝 runtime/shims/silent_audio.cpp (+18 -5)
📝 runtime/test/silent_audio_test.cpp (+16 -1)

📄 Description

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 #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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2134 **Author:** [@syfyra](https://github.com/syfyra) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/silent-audio-spatial-cadence` --- ### 📝 Commits (1) - [`2945eff`](https://github.com/ubiquitarianism/leonida/commit/2945eff743e18c0b81d503065babdca1290cc191) silent_audio: pace the 10 ms passes with a high-resolution timer (SILENT-AUDIO-PASS-CADENCE) ### 📊 Changes **2 files changed** (+34 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/silent_audio.cpp` (+18 -5) 📝 `runtime/test/silent_audio_test.cpp` (+16 -1) </details> ### 📄 Description 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 #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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2140
No description provided.