startup: add a WASAPI render sink and the startup_audio_output fixture #1250

Manually merged
github merged 2 commits from gh-pr/1250/head into gh-pr/1250/base 2026-11-26 22:52:28 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:28 UTC · original
tedin7:x2w-c3-audio-output → main · +564 −1 · 8 files · 2 commits · merged 2026-11-24 05:58 UTC

What

  • src/startup_stubs/audio_sink.{h,cpp}: desktop WASAPI shared-mode render sink. Default endpoint via IMMDeviceEnumerator, mix format from GetMixFormat (32-bit float or 16-bit PCM only, anything else is a skip), IAudioRenderClient to write, GetCurrentPadding and IAudioClock::GetPosition to observe consumption. One call, submit(format, frames, bytes), converts the block to the mix format. It records the first accepted block, submitted format, per-block frame counts and peaks, consumed frames, drained interval, recovery, and a glitch count kept separate (the render API exposes no discontinuity flag, so it reports "not available").
  • tests/startup_audio_output.cpp (CTest startup_audio_output, exit 77 = capability skip): (a) no submission, (b) eight generated 40 ms tone blocks with distinct amplitudes including one all-zero block that must be accepted and counted, (c) producer starvation: drain to padding 0, hold 300 ms, resume, consumption recovers. All waits are bounded; CTest TIMEOUT 60.
  • docs/startup-runtime.md: short "Audio output" section.

Why

First slice of #1145: a real desktop buffer submission and consumption record that separates absent output, valid silent samples and producer starvation. Fixtures are generated tones only.

Tested

Commands on Windows:

ctest --preset release --no-tests=error -R '^startup_audio_output$' -V
ctest --preset dev --no-tests=error -R '^startup_audio_output$' -V

Run here (Linux host): the pure helpers (conversion, silence detection, drained/recovery arithmetic) built with g++ -std=c++17 and -std=c++20 and ran clean; python3 -B tests/docs_links_check.py and tests/bidi_controls_check.py passed.

NOT run: nothing that touches Windows. audio_sink.cpp, tests/startup_audio_output.cpp and the CMake registration were never compiled with MSVC and the fixture was never run against an endpoint. Please treat the Windows results (endpoint, format, build, per-case counters) as still to be reported.

Not included: no capture-path verification of the generated tone, and no decoding of the console audio command queue (xapu.cpp is unchanged; its payload layout is still unknown).

Refs #1145

**@⁠tedin7** on GitHub · 2026-11-24 05:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1250) `tedin7:x2w-c3-audio-output` → `main` · +564 −1 · 8 files · 2 commits · merged 2026-11-24 05:58 UTC ## What - `src/startup_stubs/audio_sink.{h,cpp}`: desktop WASAPI shared-mode render sink. Default endpoint via `IMMDeviceEnumerator`, mix format from `GetMixFormat` (32-bit float or 16-bit PCM only, anything else is a skip), `IAudioRenderClient` to write, `GetCurrentPadding` and `IAudioClock::GetPosition` to observe consumption. One call, `submit(format, frames, bytes)`, converts the block to the mix format. It records the first accepted block, submitted format, per-block frame counts and peaks, consumed frames, drained interval, recovery, and a glitch count kept separate (the render API exposes no discontinuity flag, so it reports "not available"). - `tests/startup_audio_output.cpp` (CTest `startup_audio_output`, exit 77 = capability skip): (a) no submission, (b) eight generated 40 ms tone blocks with distinct amplitudes including one all-zero block that must be accepted and counted, (c) producer starvation: drain to padding 0, hold 300 ms, resume, consumption recovers. All waits are bounded; CTest TIMEOUT 60. - `docs/startup-runtime.md`: short "Audio output" section. ## Why First slice of #1145: a real desktop buffer submission and consumption record that separates absent output, valid silent samples and producer starvation. Fixtures are generated tones only. ## Tested Commands on Windows: ```powershell ctest --preset release --no-tests=error -R '^startup_audio_output$' -V ctest --preset dev --no-tests=error -R '^startup_audio_output$' -V ``` Run here (Linux host): the pure helpers (conversion, silence detection, drained/recovery arithmetic) built with `g++ -std=c++17` and `-std=c++20` and ran clean; `python3 -B tests/docs_links_check.py` and `tests/bidi_controls_check.py` passed. NOT run: nothing that touches Windows. `audio_sink.cpp`, `tests/startup_audio_output.cpp` and the CMake registration were never compiled with MSVC and the fixture was never run against an endpoint. Please treat the Windows results (endpoint, format, build, per-case counters) as still to be reported. Not included: no capture-path verification of the generated tone, and no decoding of the console audio command queue (`xapu.cpp` is unchanged; its payload layout is still unknown). Refs #1145
Desktop shared-mode sink under src/startup_stubs/ and a source-built
three-case fixture (no submission, continuous stream with a silent block,
producer starvation). Refs #1145.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:52:26 +00:00
github manually merged commit 16a5a07787 into gh-pr/1250/base 2026-11-26 22:52:28 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:30 UTC · original

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207, AMD Ryzen 5 PRO 5650U) at HEAD 89d860cfeb8097a285d01107e4367b5476e96438:

  • Debug (--preset dev):
    • cmake --build --preset dev --target startup_audio_output -- -j 6: built cleanly ([3/3] Linking CXX executable startup_audio_output.exe).
    • ctest --preset dev --no-tests=error -R "^startup_audio_output$" -V:
      • pure checks: conversion, silence detection and drained/recovery arithmetic ok
      • SKIP (capability): no default render endpoint, hr=-2147023728 (0x80070490, headless VM has no audio render endpoint)
      • windows: 10.0 build 26100
      • Result: 1/1 Test #53: startup_audio_output .............***Skipped 0.05 sec (exit code 0, clean capability skip 77).
  • Release (--preset release):
    • cmake --build --preset release --target startup_audio_output -- -j 6: built cleanly ([3/3] Linking CXX executable startup_audio_output.exe).
    • ctest --preset release --no-tests=error -R "^startup_audio_output$" -V:
      • pure checks: conversion, silence detection and drained/recovery arithmetic ok
      • SKIP (capability): no default render endpoint, hr=-2147023728
      • windows: 10.0 build 26100
      • Result: 1/1 Test #53: startup_audio_output .............***Skipped 0.02 sec (exit code 0, clean capability skip 77).
**@⁠tedin7** on GitHub · 2026-11-24 05:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1250#issuecomment-7123018347) Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207, AMD Ryzen 5 PRO 5650U) at HEAD `89d860cfeb8097a285d01107e4367b5476e96438`: - **Debug (`--preset dev`)**: - `cmake --build --preset dev --target startup_audio_output -- -j 6`: built cleanly (`[3/3] Linking CXX executable startup_audio_output.exe`). - `ctest --preset dev --no-tests=error -R "^startup_audio_output$" -V`: - `pure checks: conversion, silence detection and drained/recovery arithmetic ok` - `SKIP (capability): no default render endpoint, hr=-2147023728` (`0x80070490`, headless VM has no audio render endpoint) - `windows: 10.0 build 26100` - Result: `1/1 Test #53: startup_audio_output .............***Skipped 0.05 sec` (exit code 0, clean capability skip 77). - **Release (`--preset release`)**: - `cmake --build --preset release --target startup_audio_output -- -j 6`: built cleanly (`[3/3] Linking CXX executable startup_audio_output.exe`). - `ctest --preset release --no-tests=error -R "^startup_audio_output$" -V`: - `pure checks: conversion, silence detection and drained/recovery arithmetic ok` - `SKIP (capability): no default render endpoint, hr=-2147023728` - `windows: 10.0 build 26100` - Result: `1/1 Test #53: startup_audio_output .............***Skipped 0.02 sec` (exit code 0, clean capability skip 77).
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 05:32 UTC · original · edited 2026-11-24 05:38 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-24T05:38:43.593955Z 89d860c Draft marked ready
ℹ️ 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 05:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1250#issuecomment-7123046536) · edited 2026-11-24 05:38 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"89d860cfeb8097a285d01107e4367b5476e96438","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-24T05:38:43.593955Z">2026-11-24T05:38:43.593955Z</relative-time> | `89d860c` | Draft marked ready | <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>
@ -166,0 +179,4 @@
```powershell
cmake --build --preset release --target startup_audio_output
ctest --preset release --no-tests=error -R '^startup_audio_output$' -V
Author
Owner

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

P1 Badge Register the audio fixture in the required experiment docs

This introduces a public render capability and reproduction commands, but the commit updates neither the README experiment table nor docs/experiments.md. AGENTS.md requires updating those entry points when public capabilities or reproduction commands change, and CONTRIBUTING.md specifically requires the README entry and experiment reproduction details. Add the fixture, capability-skip behavior, and limitations there so contributors following the prescribed experiment index can discover and reproduce it.

AGENTS.md reference: AGENTS.md:L176-L177

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1250#discussion_r4675958167) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Register the audio fixture in the required experiment docs** This introduces a public render capability and reproduction commands, but the commit updates neither the README experiment table nor `docs/experiments.md`. `AGENTS.md` requires updating those entry points when public capabilities or reproduction commands change, and `CONTRIBUTING.md` specifically requires the README entry and experiment reproduction details. Add the fixture, capability-skip behavior, and limitations there so contributors following the prescribed experiment index can discover and reproduce it. AGENTS.md reference: [AGENTS.md:L176-L177](https://github.com/R0Y00/Xbox2Windows/blob/89d860cfeb8097a285d01107e4367b5476e96438/AGENTS.md#L176-L177) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -0,0 +102,4 @@
++r_.padding_errors;
return padding_failed;
}
return pad;
Author
Owner

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

P2 Badge Distinguish padding-query failures from an empty queue

If the Windows endpoint is invalidated while audio remains queued, GetCurrentPadding can fail with AUDCLNT_E_DEVICE_INVALIDATED, but its HRESULT is discarded and pad can remain zero. observe() then counts every submitted frame as consumed and can mark recovery complete; an invalidation immediately after case (c)'s resume submission can therefore satisfy its assertions without consuming that block. Propagate the query failure and make the fixture reject the observation instead of advancing consumption and starvation measurements.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1250#discussion_r4675958173) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Distinguish padding-query failures from an empty queue** If the Windows endpoint is invalidated while audio remains queued, `GetCurrentPadding` can fail with `AUDCLNT_E_DEVICE_INVALIDATED`, but its HRESULT is discarded and `pad` can remain zero. `observe()` then counts every submitted frame as consumed and can mark recovery complete; an invalidation immediately after case (c)'s resume submission can therefore satisfy its assertions without consuming that block. Propagate the query failure and make the fixture reject the observation instead of advancing consumption and starvation measurements. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

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

P2 Badge Destroy the audio sinks before uninitializing COM

On the successful Windows path, a, b, and c are still alive when this call uninitializes COM. They are destroyed only as main returns, and AudioSink::~AudioSink() still calls IAudioClient::Stop() before its ComPtr members release the interfaces. Those operations therefore occur after COM teardown and can fail or crash during shutdown despite the fixture having printed PASS. Put the sinks in an inner scope, or use a COM lifetime guard declared before them, so all interfaces are stopped and released before CoUninitialize().

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1250#discussion_r4675958176) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Destroy the audio sinks before uninitializing COM** On the successful Windows path, `a`, `b`, and `c` are still alive when this call uninitializes COM. They are destroyed only as `main` returns, and `AudioSink::~AudioSink()` still calls `IAudioClient::Stop()` before its `ComPtr` members release the interfaces. Those operations therefore occur after COM teardown and can fail or crash during shutdown despite the fixture having printed PASS. Put the sinks in an inner scope, or use a COM lifetime guard declared before them, so all interfaces are stopped and released before `CoUninitialize()`. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -166,0 +179,4 @@
```powershell
cmake --build --preset release --target startup_audio_output
ctest --preset release --no-tests=error -R '^startup_audio_output$' -V
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:39 UTC · original

Fixed in 16a5a077: README experiment table row added, and a "Desktop audio render sink" section in docs/experiments.md (fixture, command, capability-skip meaning, what is not covered; no endpoint run is recorded there yet).

**@⁠tedin7** on GitHub · 2026-11-24 05:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1250#discussion_r4675966205) Fixed in 16a5a077: README experiment table row added, and a "Desktop audio render sink" section in docs/experiments.md (fixture, command, capability-skip meaning, what is not covered; no endpoint run is recorded there yet).
@ -0,0 +102,4 @@
++r_.padding_errors;
return padding_failed;
}
return pad;
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:39 UTC · original

Fixed in 16a5a077: padding() now returns padding_failed and counts padding_errors when GetCurrentPadding fails. observe() makes no observation in that case (consumption and the queue timers do not move), submit() refuses the block, and the fixture fails the run if any case has padding_errors. Not compiled or run on Windows by me.

**@⁠tedin7** on GitHub · 2026-11-24 05:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1250#discussion_r4675966376) Fixed in 16a5a077: `padding()` now returns `padding_failed` and counts `padding_errors` when `GetCurrentPadding` fails. `observe()` makes no observation in that case (consumption and the queue timers do not move), `submit()` refuses the block, and the fixture fails the run if any case has `padding_errors`. Not compiled or run on Windows by me.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:40 UTC · original

Fixed in 16a5a077: the three sinks now live in run(), and main() calls CoUninitialize() only after run() has returned, so they stop and release their interfaces first. Not compiled or run on Windows by me.

**@⁠tedin7** on GitHub · 2026-11-24 05:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1250#discussion_r4675966538) Fixed in 16a5a077: the three sinks now live in `run()`, and `main()` calls `CoUninitialize()` only after `run()` has returned, so they stop and release their interfaces first. Not compiled or run on Windows by me.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:43 UTC · original

Verified on Windows Server 2025 (build 26100, MSVC 14.44, sccache) at commit 16a5a077872411f3ccd7418456b9ed72960de78e.

Commands:

  • cmake --preset dev + cmake --build --preset dev --target startup_audio_output (4.3s build, 5.97s dev total)
  • ctest --preset dev -R "^startup_audio_output$" -V
  • cmake --preset release + cmake --build --preset release --target startup_audio_output (1.88s build, 3.44s release total)
  • ctest --preset release -R "^startup_audio_output$" -V

Result (dev and release):

  • pure checks: conversion, silence detection and drained/recovery arithmetic ok
  • SKIP (capability): no default render endpoint, hr=-2147023728
  • CTest exited 0 (100% tests passed out of 1, 1 skipped due to no default render endpoint on this headless Server 2025 VM).
**@⁠tedin7** on GitHub · 2026-11-24 05:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1250#issuecomment-7123215096) Verified on Windows Server 2025 (build 26100, MSVC 14.44, `sccache`) at commit `16a5a077872411f3ccd7418456b9ed72960de78e`. Commands: - `cmake --preset dev` + `cmake --build --preset dev --target startup_audio_output` (4.3s build, 5.97s dev total) - `ctest --preset dev -R "^startup_audio_output$" -V` - `cmake --preset release` + `cmake --build --preset release --target startup_audio_output` (1.88s build, 3.44s release total) - `ctest --preset release -R "^startup_audio_output$" -V` Result (`dev` and `release`): - `pure checks: conversion, silence detection and drained/recovery arithmetic ok` - `SKIP (capability): no default render endpoint, hr=-2147023728` - CTest exited 0 (`100% tests passed out of 1`, 1 skipped due to no default render endpoint on this headless Server 2025 VM).
Author
Owner

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 89d860cfeb

ℹ️ 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 05:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1250#pullrequestreview-6034240257) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `89d860cfeb` <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>
This discussion has been locked. Commenting is limited to contributors.
No description provided.