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

Manually merged
github merged 3 commits from gh-pr/1508/head into gh-pr/1508/base 2026-11-26 23:12:45 +00:00
Owner

@⁠triggered02 on GitHub · 2026-11-24 13:18 UTC · original
triggered02:audio/pacing-error → main · +105 −7 · 1 files · 3 commits · merged 2026-11-24 14:08 UTC

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).

**@⁠triggered02** on GitHub · 2026-11-24 13:18 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1508) `triggered02:audio/pacing-error` → `main` · +105 −7 · 1 files · 3 commits · merged 2026-11-24 14:08 UTC 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).
A stutter report is a statement about timing error, and the existing control could not express it: it
records gaps, drained intervals and recovery, so a feed that is late but evenly spaced and a feed that
stumbles look different only through the drained interval. #1368's four numbers say how far behind the
producer fell, not how far each submission drifted from where it should have been.

This adds that number. Each block's submission time is compared with the ideal cadence (the block
duration, counted from the phase start, including the blocks a bursty feed withheld), and the phase
reports the worst and RMS deviation.

Measured on this machine's shared-mode endpoint (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 steady bound is derived from the host's measured Sleep granularity (three ticks) rather than a
fixed number, because a feed scheduled with Sleep(1) cannot beat the tick; #1448 measured the same
overshoot on this host. The fixture fails if the steady feed drifts beyond that bound, and fails if
the bursty feed does not drift further, so the metric has to separate the two feeds to pass.

Does not establish: where the title's stutter comes from. This still measures the desktop sink, not the
audible path, which the title drives through the system XAudio2. It is a sharper instrument for the
same boundary, not a location of the fault.

Refs #1145, follows #1368. AI-assisted (Claude Code).
Codex review on #1508: the steady bound was three timer ticks, but the steady phase checks the worst of
120 wake-ups, and on a host with a raised timer resolution Sleep(1) is ~1 ms, so the bound would be a few
milliseconds and one deschedule would fail the run. Nine calibration sleeps also measure the tick, not
scheduler delays.

The fixture now runs the same wait loop, the same number of times, with nothing submitted, and takes the
larger of three ticks and twice that measured worst plus 5 ms. On this host that is:

  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

On a host with a ~1 ms tick the three-tick term shrinks and the calibrated scheduler term is what the
bound rests on, which is the case the review described. Builds clean; startup_audio_pacing passes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:12:43 +00:00
github manually merged commit 15e42bef3e into gh-pr/1508/base 2026-11-26 23:12:45 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 13:19 UTC · original · edited 2026-11-24 13:21 UTC

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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 13:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1508#issuecomment-7132654968) · edited 2026-11-24 13:21 UTC <!-- 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>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 13:21 UTC · original

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 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 13:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1508#discussion_r4680574146) **<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 -->
Author
Owner

@⁠triggered02 on GitHub · 2026-11-24 13:22 UTC · original

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.

**@⁠triggered02** on GitHub · 2026-11-24 13:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1508#issuecomment-7132745346) 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.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 13:59 UTC · original

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.

**@⁠R0Y00** on GitHub · 2026-11-24 13:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1508#issuecomment-7133658877) 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.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 14:01 UTC · original

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.

**@⁠R0Y00** on GitHub · 2026-11-24 14:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1508#discussion_r4681093901) 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.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 13:21 UTC · original · reviewed

💡 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".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 13:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1508#pullrequestreview-6039924850) · **reviewed** <!-- 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>
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 14:09 UTC · original · reviewed

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).
**@⁠tedin7** on GitHub · 2026-11-24 14:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1508#pullrequestreview-6040714895) · **reviewed** 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)**.
This discussion has been locked. Commenting is limited to contributors.
No description provided.