startup: add a steady-versus-bursty playback-timing control #1361

Merged
triggered02 merged 3 commits from upstream-pr/1368 into main 2026-11-24 09:50:49 +00:00
triggered02 commented 2026-11-24 09:26:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T09:26:41Z.


Playback-timing slice of #1145, as its own change. Refs #1145, #1250.

What it is

The same sink and the same endpoint as #1250, fed the same total audio two ways:

  • steady: one 10 ms block every 10 ms, paced in real time;
  • bursty: runs of blocks back to back, then a 150 ms withholding gap, repeated.

For each phase it records the first submission, block and frame counts, the endpoint clock, the largest gap between submissions, the drained interval (how long the queue sat empty while the producer withheld data) and the recovery time (producer resuming to consumption advancing).

The sink and endpoint are unmodified — this measures them, and it does not change any provider behaviour. #1250's fixture and NinosTech's decode oracle stay as the independent controls.

Measured here

Shared-mode endpoint, float32, 2 ch, 48 kHz, 24000-frame buffer:

steady: blocks=120 frames=57600 largest_submit_gap=16.5ms drained_ms=0.0   recovery_ms=not measured
bursty: blocks=168 frames=80640 largest_submit_gap=158.9ms drained_ms=740.6 recovery_ms=16.0
comparison: drained steady=0.0 ms bursty=740.6 ms

The control can therefore see a producer-side stutter: bursty input produces a drained interval that steady input does not, and recovery is measured at 16 ms. It skips (77) where no shared-mode endpoint is available.

What it does not do yet

It does not instrument the title's audible path. That is the second half of the slice: record the same fields at the submission boundary the audible stream actually crosses. I would do that as a follow-up on this branch once the control is agreed, with the TSan-free instrumentation switch off by default.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6578674230 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1368). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T09:26:41Z. --- Playback-timing slice of #1145, as its own change. Refs #1145, #1250. ## What it is The same sink and the same endpoint as #1250, fed the same total audio two ways: - **steady**: one 10 ms block every 10 ms, paced in real time; - **bursty**: runs of blocks back to back, then a 150 ms withholding gap, repeated. For each phase it records the first submission, block and frame counts, the endpoint clock, the largest gap between submissions, the **drained interval** (how long the queue sat empty while the producer withheld data) and the **recovery time** (producer resuming to consumption advancing). The sink and endpoint are unmodified — this measures them, and it does not change any provider behaviour. #1250's fixture and NinosTech's decode oracle stay as the independent controls. ## Measured here Shared-mode endpoint, float32, 2 ch, 48 kHz, 24000-frame buffer: ``` steady: blocks=120 frames=57600 largest_submit_gap=16.5ms drained_ms=0.0 recovery_ms=not measured bursty: blocks=168 frames=80640 largest_submit_gap=158.9ms drained_ms=740.6 recovery_ms=16.0 comparison: drained steady=0.0 ms bursty=740.6 ms ``` The control can therefore see a producer-side stutter: bursty input produces a drained interval that steady input does not, and recovery is measured at 16 ms. It skips (77) where no shared-mode endpoint is available. ## What it does not do yet It does not instrument the title's audible path. That is the second half of the slice: record the same fields at the submission boundary the audible stream actually crosses. I would do that as a follow-up on this branch once the control is agreed, with the TSan-free instrumentation switch off by default.
upstream-sync closed this pull request 2026-11-24 10:02:32 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 10:02:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T09:30:18Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8d062f33a7

ℹ️ 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:6036716749 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1368#pullrequestreview-6036716749). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T09:30:18Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `8d062f33a7` <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>
tedin7 commented 2026-11-24 10:02:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:40:08Z.

Review: COMMENTED


Technical peer-review of commit 8d062f33a7d40d0ed7c8aa3bb0c7da5e1180a5cb:

Verification

  • Linux:
    • git diff --check origin/main...HEAD: clean.
    • tests/docs_links_check.py: passed (16 Markdown files, 302 links).
    • tests/bidi_controls_check.py: passed (1,147 files).
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207):
    • Debug (--preset dev): startup_audio_pacing built (4.48s); ctest -R '^startup_audio_pacing$' skipped (return code 77, capability skip on headless node with no default render endpoint; 0/1 passed).
    • Release /O2 (--preset release): startup_audio_pacing built (1.89s); ctest -R '^startup_audio_pacing$' skipped (return code 77; 0/1 passed).

Findings (tests/startup_audio_pacing.cpp)

  1. Shared AudioSink across phases: main() passes the same AudioSink instance to both run_steady and run_bursty. Because AudioSink::r_ is cumulative, bursty reports combined counts (120 + 48 = 168 blocks, 80,640 frames) rather than the bursty phase alone. Constructing a fresh AudioSink per phase (or resetting state) would keep the two phase reports independent.
  2. Comment vs. actual audio totals: The header comment states "feeds the sink the same total amount of audio twice", whereas run_steady submits 120 blocks (1,200 ms) and run_bursty submits 8 * 6 = 48 blocks (480 ms).
  3. Minor: CoInitializeEx has no matching CoUninitialize() after sink is destroyed.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6036852025 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1368#pullrequestreview-6036852025). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:40:08Z. **Review:** COMMENTED --- Technical peer-review of commit `8d062f33a7d40d0ed7c8aa3bb0c7da5e1180a5cb`: ### Verification - **Linux**: - `git diff --check origin/main...HEAD`: clean. - `tests/docs_links_check.py`: passed (16 Markdown files, 302 links). - `tests/bidi_controls_check.py`: passed (1,147 files). - **Windows Server 2025 (Build 26100, MSVC 14.44.35207)**: - **Debug (`--preset dev`)**: `startup_audio_pacing` built (`4.48s`); `ctest -R '^startup_audio_pacing$'` **skipped** (return code `77`, capability skip on headless node with no default render endpoint; `0/1` passed). - **Release `/O2` (`--preset release`)**: `startup_audio_pacing` built (`1.89s`); `ctest -R '^startup_audio_pacing$'` **skipped** (return code `77`; `0/1` passed). ### Findings (`tests/startup_audio_pacing.cpp`) 1. **Shared `AudioSink` across phases**: `main()` passes the same `AudioSink` instance to both `run_steady` and `run_bursty`. Because `AudioSink::r_` is cumulative, `bursty` reports combined counts (`120 + 48 = 168` blocks, `80,640` frames) rather than the bursty phase alone. Constructing a fresh `AudioSink` per phase (or resetting state) would keep the two phase reports independent. 2. **Comment vs. actual audio totals**: The header comment states *"feeds the sink the same total amount of audio twice"*, whereas `run_steady` submits `120` blocks (`1,200 ms`) and `run_bursty` submits `8 * 6 = 48` blocks (`480 ms`). 3. **Minor**: `CoInitializeEx` has no matching `CoUninitialize()` after `sink` is destroyed.
tedin7 commented 2026-11-24 10:02:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:53:35Z.

Review: COMMENTED


Technical retest & peer-review at commit 10009a948787e6caeb22aca0328ab2a11878f654:

Verification

  • Linux:
    • git diff --check origin/main...HEAD: clean.
    • tests/docs_links_check.py: passed (16 Markdown files, 302 links).
    • tests/bidi_controls_check.py: passed (1,147 tracked files).
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207):
    • Debug (--preset dev): startup_audio_pacing built in 4.07s; ctest -R '^startup_audio_pacing$' returned capability skip 77 (0/1 passed, 0.02s) on the headless node with no default render endpoint.
    • Release /O2 (--preset release): startup_audio_pacing built in 1.54s; ctest -R '^startup_audio_pacing$' returned capability skip 77 (0/1 passed, 0.02s).

Retest of Earlier Findings

  1. Per-phase counters: Resolved — run_steady and run_bursty now compute delta(before, after, ...) against a sink.report() snapshot taken before each phase, isolating blocks, frames, consumed, clock, drained_ms, rejected_full, and unsupported per phase.
  2. Block counts & header comment: Resolved — both phases now submit 120 blocks (total_blocks = 120, 20 * 6 = 120), matching the header comment, and run() fails if steady.frames != bursty.frames.
  3. CoUninitialize(): Resolved — AudioSink sink; lives inside run(), so it is destroyed before main() calls CoUninitialize().
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6037048836 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1368#pullrequestreview-6037048836). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:53:35Z. **Review:** COMMENTED --- Technical retest & peer-review at commit `10009a948787e6caeb22aca0328ab2a11878f654`: ### Verification - **Linux**: - `git diff --check origin/main...HEAD`: clean. - `tests/docs_links_check.py`: passed (16 Markdown files, 302 links). - `tests/bidi_controls_check.py`: passed (1,147 tracked files). - **Windows Server 2025 (Build 26100, MSVC 14.44.35207)**: - **Debug (`--preset dev`)**: `startup_audio_pacing` built in `4.07s`; `ctest -R '^startup_audio_pacing$'` returned capability skip `77` (`0/1 passed`, `0.02s`) on the headless node with no default render endpoint. - **Release `/O2` (`--preset release`)**: `startup_audio_pacing` built in `1.54s`; `ctest -R '^startup_audio_pacing$'` returned capability skip `77` (`0/1 passed`, `0.02s`). ### Retest of Earlier Findings 1. **Per-phase counters**: Resolved — `run_steady` and `run_bursty` now compute `delta(before, after, ...)` against a `sink.report()` snapshot taken before each phase, isolating `blocks`, `frames`, `consumed`, `clock`, `drained_ms`, `rejected_full`, and `unsupported` per phase. 2. **Block counts & header comment**: Resolved — both phases now submit `120` blocks (`total_blocks = 120`, `20 * 6 = 120`), matching the header comment, and `run()` fails if `steady.frames != bursty.frames`. 3. **`CoUninitialize()`**: Resolved — `AudioSink sink;` lives inside `run()`, so it is destroyed before `main()` calls `CoUninitialize()`.
chatgpt-codex-connector[bot commented 2026-11-24 10:02:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T09:26:53Z.


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-24T09:30:22.439928Z 8d062f3 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:7127424691 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1368#issuecomment-7127424691). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T09:26:53Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"8d062f33a7d40d0ed7c8aa3bb0c7da5e1180a5cb","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-24T09:30:22.439928Z">2026-11-24T09:30:22.439928Z</relative-time> | `8d062f3` | 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 10:02:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T09:38:29Z.


Both findings fixed in 0972768a.

Same total audio (first finding). Both phases now submit 120 blocks of 10 ms — steady paced one per 10 ms, bursty as 20 runs of 6 with a 150 ms withholding gap. The fixture also asserts that the frame totals match (steady.frames != bursty.frames fails), so the control cannot silently drift back into varying amount as well as pacing.

Per-phase counters (second finding). You are right that report() is cumulative for the life of the sink. Every printed number is now a delta against a snapshot taken before the phase, so the bursty line excludes the steady phase, and first_block is no longer reported as a phase figure (it is a sink-lifetime call index).

Re-measured after both fixes, shared-mode endpoint, float32, 2 ch, 48 kHz, 24000-frame buffer:

steady: blocks=120 frames=57600 largest_submit_gap=20.6ms drained_ms=0.0    recovery_ms=not measured
bursty: blocks=120 frames=57600 largest_submit_gap=159.2ms drained_ms=1872.2 recovery_ms=16.6
comparison: blocks 120/120 frames 57600/57600 drained steady=0.0 ms bursty=1872.2 ms

The drained figure grew from 740.6 ms to 1872.2 ms now that it covers only the bursty phase rather than a mixed snapshot — which is the cumulative-counter bug you spotted showing up in the measurement itself.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7127688871 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1368#issuecomment-7127688871). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T09:38:29Z. --- Both findings fixed in `0972768a`. **Same total audio (first finding).** Both phases now submit **120 blocks of 10 ms** — steady paced one per 10 ms, bursty as 20 runs of 6 with a 150 ms withholding gap. The fixture also *asserts* that the frame totals match (`steady.frames != bursty.frames` fails), so the control cannot silently drift back into varying amount as well as pacing. **Per-phase counters (second finding).** You are right that `report()` is cumulative for the life of the sink. Every printed number is now a delta against a snapshot taken before the phase, so the bursty line excludes the steady phase, and `first_block` is no longer reported as a phase figure (it is a sink-lifetime call index). Re-measured after both fixes, shared-mode endpoint, float32, 2 ch, 48 kHz, 24000-frame buffer: ``` steady: blocks=120 frames=57600 largest_submit_gap=20.6ms drained_ms=0.0 recovery_ms=not measured bursty: blocks=120 frames=57600 largest_submit_gap=159.2ms drained_ms=1872.2 recovery_ms=16.6 comparison: blocks 120/120 frames 57600/57600 drained steady=0.0 ms bursty=1872.2 ms ``` The drained figure grew from 740.6 ms to 1872.2 ms now that it covers only the bursty phase rather than a mixed snapshot — which is the cumulative-counter bug you spotted showing up in the measurement itself.
triggered02 commented 2026-11-24 10:02:42 +00:00 (Migrated from github.com)

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


Thanks for the technical review — one useful correction and two notes on what you saw.

Your findings 1 and 2 were already fixed in 0972768a, which landed before your review was posted but after the commit you reviewed (8d062f33). That commit:

  • makes both phases submit 120 blocks (steady paced, bursty as 20 runs of 6), so the header comment and the behaviour agree, and asserts that the frame totals match so it cannot drift again;
  • reports every counter as a per-phase delta against a snapshot taken before the phase, since AudioSink::report() is cumulative for the sink's lifetime.

Re-measured after that fix, which also shows your point in the numbers:

steady: blocks=120 frames=57600 largest_submit_gap=20.6ms  drained_ms=0.0    recovery_ms=not measured
bursty: blocks=120 frames=57600 largest_submit_gap=159.2ms drained_ms=1872.2 recovery_ms=16.6
comparison: blocks 120/120 frames 57600/57600 drained steady=0.0 ms bursty=1872.2 ms

The old mixed snapshot reported drained_ms=740.6; with the phases separated it is 1872.2, i.e. the cumulative counter was diluting the very measurement the control exists to make.

Your finding 3 is fixed in 10009a94: the body moved into run() so the sink is destroyed before main() calls CoUninitialize().

On the skips: 77 with no default render endpoint is the intended capability skip, so a headless Windows Server node reporting 0/1 passed is the expected result there — the check needs a shared-mode endpoint to measure anything.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7127901886 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1368#issuecomment-7127901886). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T09:47:52Z. --- Thanks for the technical review — one useful correction and two notes on what you saw. **Your findings 1 and 2 were already fixed** in `0972768a`, which landed before your review was posted but after the commit you reviewed (`8d062f33`). That commit: - makes both phases submit **120 blocks** (steady paced, bursty as 20 runs of 6), so the header comment and the behaviour agree, and asserts that the frame totals match so it cannot drift again; - reports every counter as a **per-phase delta** against a snapshot taken before the phase, since `AudioSink::report()` is cumulative for the sink's lifetime. Re-measured after that fix, which also shows your point in the numbers: ``` steady: blocks=120 frames=57600 largest_submit_gap=20.6ms drained_ms=0.0 recovery_ms=not measured bursty: blocks=120 frames=57600 largest_submit_gap=159.2ms drained_ms=1872.2 recovery_ms=16.6 comparison: blocks 120/120 frames 57600/57600 drained steady=0.0 ms bursty=1872.2 ms ``` The old mixed snapshot reported `drained_ms=740.6`; with the phases separated it is `1872.2`, i.e. the cumulative counter was diluting the very measurement the control exists to make. **Your finding 3 is fixed in `10009a94`**: the body moved into `run()` so the sink is destroyed before `main()` calls `CoUninitialize()`. On the skips: `77` with no default render endpoint is the intended capability skip, so a headless Windows Server node reporting `0/1 passed` is the expected result there — the check needs a shared-mode endpoint to measure anything.
chatgpt-codex-connector[bot commented 2026-11-24 10:02:43 +00:00 (Migrated from github.com)

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

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

@@ -0,0 +1,165 @@
+// Playback-timing control: the same endpoint and the same sink as #1250, fed two ways.
+//
+// The stutter reported from the title is a pacing symptom, and an audible report cannot say whether
+// the producer fed the endpoint in steady blocks or in bursts with gaps. This fixture feeds the sink
+// the same total amount of audio twice:
+//
+//   steady  - one block every block_period, paced in real time
+//   bursty  - a run of blocks back to back, then a withholding gap with no submission
+//
+// and prints, for each phase, the first submission, the frame counts, the endpoint clock, the drained
+// interval (how long the queue sat empty while the producer withheld data) and the recovery time (from
+// the producer resuming to consumption advancing again). The sink and the endpoint are not modified:
+// this measures them.
+//
+// The check is the difference between the phases, not an absolute number: bursty input must show a
+// drained interval the steady phase does not, otherwise the measurement cannot see a producer-side
+// stutter at all and this fixture is not evidence either way.
+#include "startup_stubs/audio_sink.h"
+
+#define NOMINMAX
+#include <windows.h>
+#include <objbase.h>
+
+#include <algorithm>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
+#include <string>
+#include <vector>
+
+using namespace x2w_audio;
+
+namespace {
+constexpr int skip_no_endpoint = 77;
+
+void print_report(const char* name, const Report& r, const std::vector<double>& starts, double first_ms)
+{
+    double largest_gap = 0;
+    for (size_t i = 1; i < starts.size(); ++i) largest_gap = std::max(largest_gap, starts[i] - starts[i - 1]);
+    std::printf("%s: first_submission_at=%.1fms blocks=%zu first_block=%lld frames=%llu consumed=%llu clock=%llu "
+                "largest_submit_gap=%.1fms drained_ms=%.1f recovery_ms=%.1f rejected_full=%u unsupported=%u\n",
+                name, first_ms, r.frames.size(), static_cast<long long>(r.first_block),
+                static_cast<unsigned long long>(r.submitted_frames), static_cast<unsigned long long>(r.consumed_frames),
+                static_cast<unsigned long long>(r.clock_frames), largest_gap, r.drained_ms, r.recovery_ms, r.rejected_full,
+                r.unsupported);
+}
+
+// Frames of a quiet tone so blocks are valid audio rather than an empty submission.
+std::vector<int16_t> tone(uint32_t rate, uint32_t frames, double hz)
+{
+    std::vector<int16_t> pcm(frames);
+    for (uint32_t i = 0; i < frames; ++i)
+        pcm[i] = static_cast<int16_t>(1200.0 * std::sin(2.0 * 3.14159265358979 * hz * i / rate));
+    return pcm;
+}
+
+Submit submit_with_wait(AudioSink& sink, const BlockFormat& format, const std::vector<int16_t>& pcm)
+{
+    const double end = now_ms() + 500;
+    for (;;) {
+        const Submit r = sink.submit(format, static_cast<uint32_t>(pcm.size()), pcm.data());
+        if (r != Submit::Full || now_ms() > end) return r;
+        Sleep(2);
+        sink.observe(false);
+    }
+}
+
+int run_steady(AudioSink& sink, const BlockFormat& format, uint32_t block_frames, int blocks, Report& report,
+               std::vector<double>& starts, double& first_ms)
+{
+    const auto pcm = tone(format.rate, block_frames, 220.0);
+    const double begin = now_ms();
+    first_ms = -1;
+    for (int i = 0; i < blocks; ++i) {
+        const double want = begin + i * (1000.0 * block_frames / format.rate);
+        while (now_ms() < want) Sleep(1);
+        const double at = now_ms();
+        if (submit_with_wait(sink, format, pcm) != Submit::Accepted) return 1;
+        if (first_ms < 0) first_ms = at - begin;
+        starts.push_back(at - begin);
+        sink.observe(false);
+    }
+    report = sink.report();
+    return 0;
+}
+
+int run_bursty(AudioSink& sink, const BlockFormat& format, uint32_t block_frames, int bursts, int per_burst, int gap_ms,
+               Report& report, std::vector<double>& starts, double& first_ms)
+{
+    const auto pcm = tone(format.rate, block_frames, 220.0);
+    const double begin = now_ms();
+    first_ms = -1;
+    for (int b = 0; b < bursts; ++b) {
+        for (int i = 0; i < per_burst; ++i) {
+            const double at = now_ms();
+            if (submit_with_wait(sink, format, pcm) != Submit::Accepted) return 1;
+            if (first_ms < 0) first_ms = at - begin;
+            starts.push_back(at - begin);
+            sink.observe(false);
+        }
+        // Withhold: keep sampling so the sink can see the queue drain, but submit nothing.
+        const double until = now_ms() + gap_ms;
+        while (now_ms() < until) {
+            sink.observe(true);
+            Sleep(5);
+        }
+    }
+    report = sink.report();
+    return 0;
+}
+}  // namespace
+
+int main()
+{
+    if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED))) {
+        std::printf("skip: COM initialisation failed\n");
+        return skip_no_endpoint;
+    }
+    AudioSink sink;
+    const std::string error = sink.open();
+    if (!error.empty()) {
+        std::printf("skip: no usable endpoint: %s\n", error.c_str());
+        return skip_no_endpoint;
+    }
+    const BlockFormat mix = sink.mix_format();
+    std::printf("endpoint: %s, %s %u ch %u Hz, buffer %u frames\n", sink.endpoint().c_str(),
+                mix.kind == SampleKind::Float32 ? "float32" : "pcm16", mix.channels, mix.rate, sink.buffer_frames());
+
+    const BlockFormat source{SampleKind::Pcm16, 1, mix.rate};
+    const uint32_t block_frames = mix.rate / 100;  // 10 ms
+    if (block_frames == 0) return 2;
+
+    Report steady{}, bursty{};
+    std::vector<double> steady_starts, bursty_starts;
+    double steady_first = -1, bursty_first = -1;
+    if (run_steady(sink, source, block_frames, 120, steady, steady_starts, steady_first)) return 3;
+    if (run_bursty(sink, source, block_frames, 8, 6, 150, bursty, bursty_starts, bursty_first)) return 4;

P2 Badge Match frame counts between the two phases

The steady phase submits 120 10-ms blocks, while this call submits only 8 × 6 = 48. The phases therefore vary the amount of audio as well as its pacing, contrary to the stated same-total-audio control, so the comparison does not isolate pacing. Match the total frame counts, adjusting the burst count or gaps as needed.

AGENTS.md reference: AGENTS.md:L170-L170

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4677961976 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1368#discussion_r4677961976). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T09:30:19Z. **Code review location:** `tests/startup_audio_pacing.cpp`; line 137 ~~~~diff @@ -0,0 +1,165 @@ +// Playback-timing control: the same endpoint and the same sink as #1250, fed two ways. +// +// The stutter reported from the title is a pacing symptom, and an audible report cannot say whether +// the producer fed the endpoint in steady blocks or in bursts with gaps. This fixture feeds the sink +// the same total amount of audio twice: +// +// steady - one block every block_period, paced in real time +// bursty - a run of blocks back to back, then a withholding gap with no submission +// +// and prints, for each phase, the first submission, the frame counts, the endpoint clock, the drained +// interval (how long the queue sat empty while the producer withheld data) and the recovery time (from +// the producer resuming to consumption advancing again). The sink and the endpoint are not modified: +// this measures them. +// +// The check is the difference between the phases, not an absolute number: bursty input must show a +// drained interval the steady phase does not, otherwise the measurement cannot see a producer-side +// stutter at all and this fixture is not evidence either way. +#include "startup_stubs/audio_sink.h" + +#define NOMINMAX +#include <windows.h> +#include <objbase.h> + +#include <algorithm> +#include <cmath> +#include <cstdio> +#include <cstring> +#include <string> +#include <vector> + +using namespace x2w_audio; + +namespace { +constexpr int skip_no_endpoint = 77; + +void print_report(const char* name, const Report& r, const std::vector<double>& starts, double first_ms) +{ + double largest_gap = 0; + for (size_t i = 1; i < starts.size(); ++i) largest_gap = std::max(largest_gap, starts[i] - starts[i - 1]); + std::printf("%s: first_submission_at=%.1fms blocks=%zu first_block=%lld frames=%llu consumed=%llu clock=%llu " + "largest_submit_gap=%.1fms drained_ms=%.1f recovery_ms=%.1f rejected_full=%u unsupported=%u\n", + name, first_ms, r.frames.size(), static_cast<long long>(r.first_block), + static_cast<unsigned long long>(r.submitted_frames), static_cast<unsigned long long>(r.consumed_frames), + static_cast<unsigned long long>(r.clock_frames), largest_gap, r.drained_ms, r.recovery_ms, r.rejected_full, + r.unsupported); +} + +// Frames of a quiet tone so blocks are valid audio rather than an empty submission. +std::vector<int16_t> tone(uint32_t rate, uint32_t frames, double hz) +{ + std::vector<int16_t> pcm(frames); + for (uint32_t i = 0; i < frames; ++i) + pcm[i] = static_cast<int16_t>(1200.0 * std::sin(2.0 * 3.14159265358979 * hz * i / rate)); + return pcm; +} + +Submit submit_with_wait(AudioSink& sink, const BlockFormat& format, const std::vector<int16_t>& pcm) +{ + const double end = now_ms() + 500; + for (;;) { + const Submit r = sink.submit(format, static_cast<uint32_t>(pcm.size()), pcm.data()); + if (r != Submit::Full || now_ms() > end) return r; + Sleep(2); + sink.observe(false); + } +} + +int run_steady(AudioSink& sink, const BlockFormat& format, uint32_t block_frames, int blocks, Report& report, + std::vector<double>& starts, double& first_ms) +{ + const auto pcm = tone(format.rate, block_frames, 220.0); + const double begin = now_ms(); + first_ms = -1; + for (int i = 0; i < blocks; ++i) { + const double want = begin + i * (1000.0 * block_frames / format.rate); + while (now_ms() < want) Sleep(1); + const double at = now_ms(); + if (submit_with_wait(sink, format, pcm) != Submit::Accepted) return 1; + if (first_ms < 0) first_ms = at - begin; + starts.push_back(at - begin); + sink.observe(false); + } + report = sink.report(); + return 0; +} + +int run_bursty(AudioSink& sink, const BlockFormat& format, uint32_t block_frames, int bursts, int per_burst, int gap_ms, + Report& report, std::vector<double>& starts, double& first_ms) +{ + const auto pcm = tone(format.rate, block_frames, 220.0); + const double begin = now_ms(); + first_ms = -1; + for (int b = 0; b < bursts; ++b) { + for (int i = 0; i < per_burst; ++i) { + const double at = now_ms(); + if (submit_with_wait(sink, format, pcm) != Submit::Accepted) return 1; + if (first_ms < 0) first_ms = at - begin; + starts.push_back(at - begin); + sink.observe(false); + } + // Withhold: keep sampling so the sink can see the queue drain, but submit nothing. + const double until = now_ms() + gap_ms; + while (now_ms() < until) { + sink.observe(true); + Sleep(5); + } + } + report = sink.report(); + return 0; +} +} // namespace + +int main() +{ + if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED))) { + std::printf("skip: COM initialisation failed\n"); + return skip_no_endpoint; + } + AudioSink sink; + const std::string error = sink.open(); + if (!error.empty()) { + std::printf("skip: no usable endpoint: %s\n", error.c_str()); + return skip_no_endpoint; + } + const BlockFormat mix = sink.mix_format(); + std::printf("endpoint: %s, %s %u ch %u Hz, buffer %u frames\n", sink.endpoint().c_str(), + mix.kind == SampleKind::Float32 ? "float32" : "pcm16", mix.channels, mix.rate, sink.buffer_frames()); + + const BlockFormat source{SampleKind::Pcm16, 1, mix.rate}; + const uint32_t block_frames = mix.rate / 100; // 10 ms + if (block_frames == 0) return 2; + + Report steady{}, bursty{}; + std::vector<double> steady_starts, bursty_starts; + double steady_first = -1, bursty_first = -1; + if (run_steady(sink, source, block_frames, 120, steady, steady_starts, steady_first)) return 3; + if (run_bursty(sink, source, block_frames, 8, 6, 150, bursty, bursty_starts, bursty_first)) return 4; ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Match frame counts between the two phases** The steady phase submits 120 10-ms blocks, while this call submits only 8 × 6 = 48. The phases therefore vary the amount of audio as well as its pacing, contrary to the stated same-total-audio control, so the comparison does not isolate pacing. Match the total frame counts, adjusting the burst count or gaps as needed. AGENTS.md reference: [AGENTS.md:L170-L170](https://github.com/R0Y00/Xbox2Windows/blob/8d062f33a7d40d0ed7c8aa3bb0c7da5e1180a5cb/AGENTS.md#L170-L170) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 10:02:43 +00:00 (Migrated from github.com)

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

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

@@ -0,0 +1,165 @@
+// Playback-timing control: the same endpoint and the same sink as #1250, fed two ways.
+//
+// The stutter reported from the title is a pacing symptom, and an audible report cannot say whether
+// the producer fed the endpoint in steady blocks or in bursts with gaps. This fixture feeds the sink
+// the same total amount of audio twice:
+//
+//   steady  - one block every block_period, paced in real time
+//   bursty  - a run of blocks back to back, then a withholding gap with no submission
+//
+// and prints, for each phase, the first submission, the frame counts, the endpoint clock, the drained
+// interval (how long the queue sat empty while the producer withheld data) and the recovery time (from
+// the producer resuming to consumption advancing again). The sink and the endpoint are not modified:
+// this measures them.
+//
+// The check is the difference between the phases, not an absolute number: bursty input must show a
+// drained interval the steady phase does not, otherwise the measurement cannot see a producer-side
+// stutter at all and this fixture is not evidence either way.
+#include "startup_stubs/audio_sink.h"
+
+#define NOMINMAX
+#include <windows.h>
+#include <objbase.h>
+
+#include <algorithm>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
+#include <string>
+#include <vector>
+
+using namespace x2w_audio;
+
+namespace {
+constexpr int skip_no_endpoint = 77;
+
+void print_report(const char* name, const Report& r, const std::vector<double>& starts, double first_ms)
+{
+    double largest_gap = 0;
+    for (size_t i = 1; i < starts.size(); ++i) largest_gap = std::max(largest_gap, starts[i] - starts[i - 1]);
+    std::printf("%s: first_submission_at=%.1fms blocks=%zu first_block=%lld frames=%llu consumed=%llu clock=%llu "
+                "largest_submit_gap=%.1fms drained_ms=%.1f recovery_ms=%.1f rejected_full=%u unsupported=%u\n",
+                name, first_ms, r.frames.size(), static_cast<long long>(r.first_block),
+                static_cast<unsigned long long>(r.submitted_frames), static_cast<unsigned long long>(r.consumed_frames),
+                static_cast<unsigned long long>(r.clock_frames), largest_gap, r.drained_ms, r.recovery_ms, r.rejected_full,
+                r.unsupported);
+}
+
+// Frames of a quiet tone so blocks are valid audio rather than an empty submission.
+std::vector<int16_t> tone(uint32_t rate, uint32_t frames, double hz)
+{
+    std::vector<int16_t> pcm(frames);
+    for (uint32_t i = 0; i < frames; ++i)
+        pcm[i] = static_cast<int16_t>(1200.0 * std::sin(2.0 * 3.14159265358979 * hz * i / rate));
+    return pcm;
+}
+
+Submit submit_with_wait(AudioSink& sink, const BlockFormat& format, const std::vector<int16_t>& pcm)
+{
+    const double end = now_ms() + 500;
+    for (;;) {
+        const Submit r = sink.submit(format, static_cast<uint32_t>(pcm.size()), pcm.data());
+        if (r != Submit::Full || now_ms() > end) return r;
+        Sleep(2);
+        sink.observe(false);
+    }
+}
+
+int run_steady(AudioSink& sink, const BlockFormat& format, uint32_t block_frames, int blocks, Report& report,
+               std::vector<double>& starts, double& first_ms)
+{
+    const auto pcm = tone(format.rate, block_frames, 220.0);
+    const double begin = now_ms();
+    first_ms = -1;
+    for (int i = 0; i < blocks; ++i) {
+        const double want = begin + i * (1000.0 * block_frames / format.rate);
+        while (now_ms() < want) Sleep(1);
+        const double at = now_ms();
+        if (submit_with_wait(sink, format, pcm) != Submit::Accepted) return 1;
+        if (first_ms < 0) first_ms = at - begin;
+        starts.push_back(at - begin);
+        sink.observe(false);
+    }
+    report = sink.report();
+    return 0;
+}
+
+int run_bursty(AudioSink& sink, const BlockFormat& format, uint32_t block_frames, int bursts, int per_burst, int gap_ms,
+               Report& report, std::vector<double>& starts, double& first_ms)
+{
+    const auto pcm = tone(format.rate, block_frames, 220.0);
+    const double begin = now_ms();
+    first_ms = -1;
+    for (int b = 0; b < bursts; ++b) {
+        for (int i = 0; i < per_burst; ++i) {
+            const double at = now_ms();
+            if (submit_with_wait(sink, format, pcm) != Submit::Accepted) return 1;
+            if (first_ms < 0) first_ms = at - begin;
+            starts.push_back(at - begin);
+            sink.observe(false);
+        }
+        // Withhold: keep sampling so the sink can see the queue drain, but submit nothing.
+        const double until = now_ms() + gap_ms;
+        while (now_ms() < until) {
+            sink.observe(true);
+            Sleep(5);
+        }
+    }
+    report = sink.report();

P2 Badge Report bursty-phase counters instead of sink-lifetime totals

run_bursty uses the same sink as run_steady, and AudioSink::report() returns cumulative counters. This snapshot therefore includes both phases: the printed bursty block and frame counts include the 120 steady blocks, and first_block still refers to the steady phase. The bursty report mislabels sink-lifetime consumption and clock data as phase-specific; report per-phase deltas or reset the report state.

AGENTS.md reference: AGENTS.md:L170-L170

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4677961998 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1368#discussion_r4677961998). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T09:30:19Z. **Code review location:** `tests/startup_audio_pacing.cpp`; line 108 ~~~~diff @@ -0,0 +1,165 @@ +// Playback-timing control: the same endpoint and the same sink as #1250, fed two ways. +// +// The stutter reported from the title is a pacing symptom, and an audible report cannot say whether +// the producer fed the endpoint in steady blocks or in bursts with gaps. This fixture feeds the sink +// the same total amount of audio twice: +// +// steady - one block every block_period, paced in real time +// bursty - a run of blocks back to back, then a withholding gap with no submission +// +// and prints, for each phase, the first submission, the frame counts, the endpoint clock, the drained +// interval (how long the queue sat empty while the producer withheld data) and the recovery time (from +// the producer resuming to consumption advancing again). The sink and the endpoint are not modified: +// this measures them. +// +// The check is the difference between the phases, not an absolute number: bursty input must show a +// drained interval the steady phase does not, otherwise the measurement cannot see a producer-side +// stutter at all and this fixture is not evidence either way. +#include "startup_stubs/audio_sink.h" + +#define NOMINMAX +#include <windows.h> +#include <objbase.h> + +#include <algorithm> +#include <cmath> +#include <cstdio> +#include <cstring> +#include <string> +#include <vector> + +using namespace x2w_audio; + +namespace { +constexpr int skip_no_endpoint = 77; + +void print_report(const char* name, const Report& r, const std::vector<double>& starts, double first_ms) +{ + double largest_gap = 0; + for (size_t i = 1; i < starts.size(); ++i) largest_gap = std::max(largest_gap, starts[i] - starts[i - 1]); + std::printf("%s: first_submission_at=%.1fms blocks=%zu first_block=%lld frames=%llu consumed=%llu clock=%llu " + "largest_submit_gap=%.1fms drained_ms=%.1f recovery_ms=%.1f rejected_full=%u unsupported=%u\n", + name, first_ms, r.frames.size(), static_cast<long long>(r.first_block), + static_cast<unsigned long long>(r.submitted_frames), static_cast<unsigned long long>(r.consumed_frames), + static_cast<unsigned long long>(r.clock_frames), largest_gap, r.drained_ms, r.recovery_ms, r.rejected_full, + r.unsupported); +} + +// Frames of a quiet tone so blocks are valid audio rather than an empty submission. +std::vector<int16_t> tone(uint32_t rate, uint32_t frames, double hz) +{ + std::vector<int16_t> pcm(frames); + for (uint32_t i = 0; i < frames; ++i) + pcm[i] = static_cast<int16_t>(1200.0 * std::sin(2.0 * 3.14159265358979 * hz * i / rate)); + return pcm; +} + +Submit submit_with_wait(AudioSink& sink, const BlockFormat& format, const std::vector<int16_t>& pcm) +{ + const double end = now_ms() + 500; + for (;;) { + const Submit r = sink.submit(format, static_cast<uint32_t>(pcm.size()), pcm.data()); + if (r != Submit::Full || now_ms() > end) return r; + Sleep(2); + sink.observe(false); + } +} + +int run_steady(AudioSink& sink, const BlockFormat& format, uint32_t block_frames, int blocks, Report& report, + std::vector<double>& starts, double& first_ms) +{ + const auto pcm = tone(format.rate, block_frames, 220.0); + const double begin = now_ms(); + first_ms = -1; + for (int i = 0; i < blocks; ++i) { + const double want = begin + i * (1000.0 * block_frames / format.rate); + while (now_ms() < want) Sleep(1); + const double at = now_ms(); + if (submit_with_wait(sink, format, pcm) != Submit::Accepted) return 1; + if (first_ms < 0) first_ms = at - begin; + starts.push_back(at - begin); + sink.observe(false); + } + report = sink.report(); + return 0; +} + +int run_bursty(AudioSink& sink, const BlockFormat& format, uint32_t block_frames, int bursts, int per_burst, int gap_ms, + Report& report, std::vector<double>& starts, double& first_ms) +{ + const auto pcm = tone(format.rate, block_frames, 220.0); + const double begin = now_ms(); + first_ms = -1; + for (int b = 0; b < bursts; ++b) { + for (int i = 0; i < per_burst; ++i) { + const double at = now_ms(); + if (submit_with_wait(sink, format, pcm) != Submit::Accepted) return 1; + if (first_ms < 0) first_ms = at - begin; + starts.push_back(at - begin); + sink.observe(false); + } + // Withhold: keep sampling so the sink can see the queue drain, but submit nothing. + const double until = now_ms() + gap_ms; + while (now_ms() < until) { + sink.observe(true); + Sleep(5); + } + } + report = sink.report(); ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Report bursty-phase counters instead of sink-lifetime totals** `run_bursty` uses the same `sink` as `run_steady`, and `AudioSink::report()` returns cumulative counters. This snapshot therefore includes both phases: the printed bursty block and frame counts include the 120 steady blocks, and `first_block` still refers to the steady phase. The bursty report mislabels sink-lifetime consumption and clock data as phase-specific; report per-phase deltas or reset the report state. AGENTS.md reference: [AGENTS.md:L170-L170](https://github.com/R0Y00/Xbox2Windows/blob/8d062f33a7d40d0ed7c8aa3bb0c7da5e1180a5cb/AGENTS.md#L170-L170) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
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!1361
No description provided.