audio: report pacing error against the ideal cadence in the pacing control #1501

Merged
triggered02 merged 3 commits from upstream-pr/1508 into main 2026-11-24 14:08:46 +00:00
triggered02 commented 2026-11-24 13:18:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T13:18:47Z.


A sharper instrument for the boundary #1368 measures — pacing error against the ideal cadence, not just gaps and drain.

Why

A stutter is a statement about timing error. The existing control reports first submission, largest gap, drained interval and recovery, so it can show that a bursty feed starved the queue. What it cannot express is drift: how far each submission landed from where it should have been. This adds that per-block deviation, computed against the ideal cadence (block duration counted from phase start, including blocks a bursty feed withheld), and reports worst-case and RMS per phase.

Measured on this machine's endpoint (shared mode, float32, 2 ch, 48 kHz, 24000-frame buffer)

steady: pacing_error_max=15.9ms pacing_error_rms=9.1ms
bursty: pacing_error_max=1847.5ms pacing_error_rms=1060.4ms
timer:  Sleep(1) median 15.5 ms, steady bound 46.6 ms

The bound is measured, not chosen

A feed scheduled with Sleep(1) cannot be tighter than the host's timer tick, and the tick differs per host (#1448 measured the same overshoot here). So the fixture measures Sleep(1)'s median overshoot and sets the steady bound to three ticks (46.6 ms here). It then fails if:

  • the steady feed drifts beyond that bound — the feed failed to keep up with its own schedule; or
  • the bursty feed does not drift further than steady by five ticks — the metric cannot separate the two feeds and is not evidence.

Both arms must hold for the test to pass, so the metric has to be sensitive rather than merely non-zero.

What this does not establish

Where the title's stutter comes from. This still measures the desktop sink, not the title's audible path, which it drives through the system XAudio2. It sharpens the same boundary; it does not locate the fault. #1145 stays open for the path-level work I asked direction on.

startup_audio_pacing passes; build clean. AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6582687199 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1508). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T13:18:47Z. --- A sharper instrument for the boundary #1368 measures — **pacing error against the ideal cadence**, not just gaps and drain. ## Why A stutter is a statement about timing *error*. The existing control reports first submission, largest gap, drained interval and recovery, so it can show that a bursty feed starved the queue. What it cannot express is drift: how far each submission landed from where it should have been. This adds that per-block deviation, computed against the ideal cadence (block duration counted from phase start, including blocks a bursty feed withheld), and reports worst-case and RMS per phase. ## Measured on this machine's endpoint (shared mode, float32, 2 ch, 48 kHz, 24000-frame buffer) ``` steady: pacing_error_max=15.9ms pacing_error_rms=9.1ms bursty: pacing_error_max=1847.5ms pacing_error_rms=1060.4ms timer: Sleep(1) median 15.5 ms, steady bound 46.6 ms ``` ## The bound is measured, not chosen A feed scheduled with `Sleep(1)` cannot be tighter than the host's timer tick, and the tick differs per host (#1448 measured the same overshoot here). So the fixture measures `Sleep(1)`'s median overshoot and sets the steady bound to three ticks (46.6 ms here). It then fails if: - the steady feed drifts beyond that bound — the feed failed to keep up with its own schedule; or - the bursty feed does not drift further than steady by five ticks — the metric cannot separate the two feeds and is not evidence. Both arms must hold for the test to pass, so the metric has to be sensitive rather than merely non-zero. ## What this does not establish **Where the title's stutter comes from.** This still measures the desktop sink, not the title's audible path, which it drives through the system `XAudio2`. It sharpens the same boundary; it does not locate the fault. #1145 stays open for the path-level work I asked direction on. `startup_audio_pacing` passes; build clean. AI-assisted (Claude Code).
chatgpt-codex-connector[bot commented 2026-11-24 14:03:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T13:21:25Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f933a45a2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6039924850 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1508#pullrequestreview-6039924850). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T13:21:25Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `2f933a45a2` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
R0Y00 commented 2026-11-24 14:03:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T14:01:47Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6040585856 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1508#pullrequestreview-6040585856). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T14:01:47Z. **Review:** COMMENTED --- _No description provided._
chatgpt-codex-connector[bot commented 2026-11-24 14:03:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T13:19:00Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T13:21:28.213670Z 2f933a4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7132654968 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1508#issuecomment-7132654968). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T13:19:00Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"2f933a45a205bfe02b96e3fc10b7ad05a037cc37","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T13:21:28.213670Z">2026-11-24T13:21:28.213670Z</relative-time> | `2f933a4` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
triggered02 commented 2026-11-24 14:03:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T13:22:46Z.


Good catch — fixed in 69a3e0ef.

You were right on both halves: the bound was the tick, not the scheduling, and the steady phase takes the worst of 120 wake-ups while the nine calibration sleeps only measure Sleep(1)'s typical overshoot. On this host (16.0 ms tick) the old three-tick bound happened to be loose enough, which is exactly why it would have passed here and flaked on a host with a raised timer resolution.

The fix calibrates the mechanism the fixture actually uses: it runs the same wait loop, the same number of times (120), with nothing submitted, and takes the worst deviation from the ideal cadence. The steady bound is then max(3 × tick, 2 × measured scheduler worst + 5 ms):

timer: Sleep(1) median 16.0 ms, scheduler worst 15.4 ms over 120 wake-ups, steady bound 48.0 ms
steady: pacing_error_max=16.0ms rms=9.2ms
bursty: pacing_error_max=1853.3ms rms=1062.3ms

So on a ~1 ms-tick host the three-tick term collapses to a few ms and the calibrated scheduler term is what the bound rests on — the case you described. It also still fails if the bursty feed does not drift further than the steady one, so the metric has to separate the two feeds to pass.

One residual I am naming rather than hiding: a deschedule longer than any of the 120 calibration wake-ups during the measurement phase would still fail the steady check. I think that is the right behaviour — a stall that big is a real scheduling event worth reporting, not noise to be absorbed — but if you would rather the steady bound be a percentile of the calibration (say the 95th) so isolated stalls never fail the run, say so and I will change it.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7132745346 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1508#issuecomment-7132745346). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T13:22:46Z. --- Good catch — fixed in `69a3e0ef`. You were right on both halves: the bound was the tick, not the scheduling, and the steady phase takes the **worst of 120 wake-ups** while the nine calibration sleeps only measure `Sleep(1)`'s typical overshoot. On this host (16.0 ms tick) the old three-tick bound happened to be loose enough, which is exactly why it would have passed here and flaked on a host with a raised timer resolution. **The fix calibrates the mechanism the fixture actually uses:** it runs the same wait loop, the same number of times (120), with nothing submitted, and takes the worst deviation from the ideal cadence. The steady bound is then `max(3 × tick, 2 × measured scheduler worst + 5 ms)`: ``` timer: Sleep(1) median 16.0 ms, scheduler worst 15.4 ms over 120 wake-ups, steady bound 48.0 ms steady: pacing_error_max=16.0ms rms=9.2ms bursty: pacing_error_max=1853.3ms rms=1062.3ms ``` So on a ~1 ms-tick host the three-tick term collapses to a few ms and the calibrated scheduler term is what the bound rests on — the case you described. It also still fails if the bursty feed does not drift further than the steady one, so the metric has to separate the two feeds to pass. One residual I am naming rather than hiding: a deschedule longer than *any* of the 120 calibration wake-ups during the measurement phase would still fail the steady check. I think that is the right behaviour — a stall that big is a real scheduling event worth reporting, not noise to be absorbed — but if you would rather the steady bound be a percentile of the calibration (say the 95th) so isolated stalls never fail the run, say so and I will change it.
R0Y00 commented 2026-11-24 14:03:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T13:59:34Z.


Maintainer update at 15e42bef keeps maximum and RMS timing diagnostic and uses p95 for acceptance. The synthetic control ignores one isolated delay and detects a sustained tail. The real Windows Release pacing test passed twice in a row.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7133658877 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1508#issuecomment-7133658877). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T13:59:34Z. --- Maintainer update at 15e42bef keeps maximum and RMS timing diagnostic and uses p95 for acceptance. The synthetic control ignores one isolated delay and detects a sustained tail. The real Windows Release pacing test passed twice in a row.
chatgpt-codex-connector[bot commented 2026-11-24 14:03:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T13:21:25Z.

Code review location: tests/startup_audio_pacing.cpp; line 253

@@ -208,6 +244,23 @@ int run()
         std::printf("FAIL: bursty phase never recovered (recovery not measured)\n");
         return 1;
     }
+    // Sensitivity first: if the metric cannot separate an evenly paced feed from one that withholds
+    // blocks, it cannot speak about the title's stutter either. The steady bound is a few measured timer
+    // ticks, because the feed is scheduled with Sleep(1) and cannot beat the host's tick.
+    const double tick_ms = sleep_granularity_ms();
+    const double steady_limit_ms = 3.0 * tick_ms;
+    std::printf("timer: Sleep(1) median %.1f ms, steady bound %.1f ms\n", tick_ms, steady_limit_ms);
+    if (steady.pacing_error_max_ms > steady_limit_ms) {

P2 Badge Allow scheduler jitter in the steady-pacing threshold

On a Windows host with a usable endpoint and a raised timer resolution, Sleep(1) can have a roughly 1 ms median, making this a roughly 3 ms hard limit. The steady phase checks the maximum over 120 submissions, while the nine calibration sleeps measure timer granularity rather than scheduler delays; one deschedule longer than the limit during the run can therefore make CTest fail despite a healthy sink. Use a tail-tolerant criterion or keep this bound informational so the diagnostic does not fail intermittently on loaded hosts.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4680574146 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1508#discussion_r4680574146). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T13:21:25Z. **Code review location:** `tests/startup_audio_pacing.cpp`; line 253 ~~~~diff @@ -208,6 +244,23 @@ int run() std::printf("FAIL: bursty phase never recovered (recovery not measured)\n"); return 1; } + // Sensitivity first: if the metric cannot separate an evenly paced feed from one that withholds + // blocks, it cannot speak about the title's stutter either. The steady bound is a few measured timer + // ticks, because the feed is scheduled with Sleep(1) and cannot beat the host's tick. + const double tick_ms = sleep_granularity_ms(); + const double steady_limit_ms = 3.0 * tick_ms; + std::printf("timer: Sleep(1) median %.1f ms, steady bound %.1f ms\n", tick_ms, steady_limit_ms); + if (steady.pacing_error_max_ms > steady_limit_ms) { ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Allow scheduler jitter in the steady-pacing threshold** On a Windows host with a usable endpoint and a raised timer resolution, `Sleep(1)` can have a roughly 1 ms median, making this a roughly 3 ms hard limit. The steady phase checks the maximum over 120 submissions, while the nine calibration sleeps measure timer granularity rather than scheduler delays; one deschedule longer than the limit during the run can therefore make CTest fail despite a healthy sink. Use a tail-tolerant criterion or keep this bound informational so the diagnostic does not fail intermittently on loaded hosts. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
R0Y00 commented 2026-11-24 14:03:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T14:01:47Z.

Code review location: tests/startup_audio_pacing.cpp; line 253

@@ -208,6 +244,23 @@ int run()
         std::printf("FAIL: bursty phase never recovered (recovery not measured)\n");
         return 1;
     }
+    // Sensitivity first: if the metric cannot separate an evenly paced feed from one that withholds
+    // blocks, it cannot speak about the title's stutter either. The steady bound is a few measured timer
+    // ticks, because the feed is scheduled with Sleep(1) and cannot beat the host's tick.
+    const double tick_ms = sleep_granularity_ms();
+    const double steady_limit_ms = 3.0 * tick_ms;
+    std::printf("timer: Sleep(1) median %.1f ms, steady bound %.1f ms\n", tick_ms, steady_limit_ms);
+    if (steady.pacing_error_max_ms > steady_limit_ms) {

Fixed at 15e42bef. The test gates on p95 while keeping maximum and RMS in diagnostics. A deterministic control covers an isolated and a sustained scheduling delay. Two Windows Release runs gave steady p95 14.5 and 14.4 ms, bursty 1691.2 and 1693.7 ms.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4681093901 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1508#discussion_r4681093901). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T14:01:47Z. **Code review location:** `tests/startup_audio_pacing.cpp`; line 253 ~~~~diff @@ -208,6 +244,23 @@ int run() std::printf("FAIL: bursty phase never recovered (recovery not measured)\n"); return 1; } + // Sensitivity first: if the metric cannot separate an evenly paced feed from one that withholds + // blocks, it cannot speak about the title's stutter either. The steady bound is a few measured timer + // ticks, because the feed is scheduled with Sleep(1) and cannot beat the host's tick. + const double tick_ms = sleep_granularity_ms(); + const double steady_limit_ms = 3.0 * tick_ms; + std::printf("timer: Sleep(1) median %.1f ms, steady bound %.1f ms\n", tick_ms, steady_limit_ms); + if (steady.pacing_error_max_ms > steady_limit_ms) { ~~~~ --- Fixed at 15e42bef. The test gates on p95 while keeping maximum and RMS in diagnostics. A deterministic control covers an isolated and a sustained scheduling delay. Two Windows Release runs gave steady p95 14.5 and 14.4 ms, bursty 1691.2 and 1693.7 ms.
upstream-sync closed this pull request 2026-11-24 15:01:47 +00:00
tedin7 commented 2026-11-24 15:01:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T14:09:25Z.

Review: COMMENTED


Technical review of commit 69a3e0ef48a13800dbba8428ecb59d765de35a3d:

Code & fixture audit

  • tests/startup_audio_pacing.cpp adds per-block ideal-cadence pacing error tracking (pacing_error_max_ms, pacing_error_rms_ms) to both run_steady and run_bursty.
  • sleep_granularity_ms() (9-sample Sleep(1) median) and calibrate_scheduler_ms() (120-wake-up dry run matching the steady loop) derive steady_limit_ms = max(3.0 * tick_ms, 2.0 * jitter_ms + 5.0), avoiding brittle fixed-millisecond thresholds on hosts with raised timer resolution, while still enforcing sensitivity (bursty.pacing_error_max_ms > steady.pacing_error_max_ms + 5.0 * tick_ms).

Verification

  • Lint & merge: tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check, and git merge-tree --write-tree origin/main HEAD all pass.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207):
    • Debug (--preset dev): built startup_audio_pacing (4.45s); ctest --preset dev -R '^startup_audio_pacing$' --no-tests=error: skipped (exit 77, capability skip — no audio endpoint on headless VM; not a pass and not a failure).
    • Release /O2 (--preset release): built startup_audio_pacing (1.91s); ctest --preset release -R '^startup_audio_pacing$' --no-tests=error: skipped (exit 77, capability skip — no audio endpoint on headless VM).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6040714895 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1508#pullrequestreview-6040714895). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T14:09:25Z. **Review:** COMMENTED --- Technical review of commit `69a3e0ef48a13800dbba8428ecb59d765de35a3d`: ### Code & fixture audit - `tests/startup_audio_pacing.cpp` adds per-block ideal-cadence pacing error tracking (`pacing_error_max_ms`, `pacing_error_rms_ms`) to both `run_steady` and `run_bursty`. - `sleep_granularity_ms()` (9-sample `Sleep(1)` median) and `calibrate_scheduler_ms()` (120-wake-up dry run matching the steady loop) derive `steady_limit_ms = max(3.0 * tick_ms, 2.0 * jitter_ms + 5.0)`, avoiding brittle fixed-millisecond thresholds on hosts with raised timer resolution, while still enforcing sensitivity (`bursty.pacing_error_max_ms > steady.pacing_error_max_ms + 5.0 * tick_ms`). ### Verification - **Lint & merge**: `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `git diff --check`, and `git merge-tree --write-tree origin/main HEAD` all pass. - **Windows Server 2025 (Build 26100, MSVC 14.44.35207)**: - Debug (`--preset dev`): built `startup_audio_pacing` (`4.45s`); `ctest --preset dev -R '^startup_audio_pacing$' --no-tests=error`: **skipped (exit 77, capability skip — no audio endpoint on headless VM; not a pass and not a failure)**. - Release `/O2` (`--preset release`): built `startup_audio_pacing` (`1.91s`); `ctest --preset release -R '^startup_audio_pacing$' --no-tests=error`: **skipped (exit 77, capability skip — no audio endpoint on headless VM)**.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
R0Y00/Xbox2Windows!1501
No description provided.