coreaudio: mid-run spatial/WASAPI stream re-activations open new AudioQueues and fall back to silence under load #337

Closed
opened 2026-11-27 12:36:36 +00:00 by github-bot · 2 comments
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 12:35 UTC · original

What happens

In world runs on current main (with #288 merged), sound still cuts out when the title repeatedly re-activates its spatial audio stream under world-load pressure:

  • #8 (#issuecomment-7217386312): "The log lines of that stretch are the fence waits above and the title activating its spatial audio stream again. Sound: the audio output fell back to silence (AudioQueueStart failed with OSStatus 2003329396) on 4 of 14 stream activations in the default run and 6 of 32 in the heap run, the first at +188 s and +207 s."
  • #258 (@alicans): "Sound went silent soon after the world began; the audio device kept running."

Why

  1. Every XAudio2 engine, WASAPI IAudioClient::Initialize, and ISpatialAudioClient::ActivateSpatialAudioStream calls coreaudio::open_default(48_000, 2, render), and CoreAudio::open creates and starts a brand-new AudioToolbox AudioQueue (AudioQueueNewOutput + AudioQueueStart) for each one. When the title re-activates its spatial stream 14–32 times during a heavy world load (0–17% free memory), coreaudiod IPC fails AudioQueueStart with 'what' (2003329396), stalling the caller for 500 ms of retries and then permanently binding the new spatial stream to Silent ("no audio device: sound is mixed and dropped") — even while the process's initial 48_000 Hz stereo AudioQueue is still open and running.
  2. When CoreAudio::open does open a hardware AudioQueue and AudioQueueStart fails with 'what', #288 retries AudioQueueStart on the same failed AudioQueueRef instead of disposing it and creating a fresh queue.

Plan

  1. Share one hardware CoreAudio AudioQueue per (rate, channels) across active Output handles, mixing attached Render callbacks in userspace (f32 sum, outputting silence when zero streams are attached) so mid-run spatial/WASAPI/XAudio2 stream activations attach without AudioQueueNewOutput / AudioQueueStart round-trips (reopening only if AudioQueueEnqueueBuffer reports a runtime device error).
  2. Dispose and recreate the AudioQueueRef across AudioQueueStart retry attempts when opening the hardware queue for the first time (or after a runtime device failure).
  3. Add unit tests covering multi-stream mixing across repeated stream tear-down/re-activation, re-entrant Output drop from inside a Render callback, and AudioQueueStart retry recreating the queue handle.
**@⁠Sheffy007** on GitHub · 2026-11-27 12:35 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/336) ## What happens In world runs on current `main` (with #288 merged), sound still cuts out when the title repeatedly re-activates its spatial audio stream under world-load pressure: - #8 (`#issuecomment-7217386312`): *"The log lines of that stretch are the fence waits above and the title activating its spatial audio stream again. Sound: the audio output fell back to silence (`AudioQueueStart failed with OSStatus 2003329396`) on 4 of 14 stream activations in the default run and 6 of 32 in the heap run, the first at +188 s and +207 s."* - #258 (`@alicans`): *"Sound went silent soon after the world began; the audio device kept running."* ## Why 1. Every `XAudio2` engine, WASAPI `IAudioClient::Initialize`, and `ISpatialAudioClient::ActivateSpatialAudioStream` calls `coreaudio::open_default(48_000, 2, render)`, and `CoreAudio::open` creates and starts a brand-new AudioToolbox `AudioQueue` (`AudioQueueNewOutput` + `AudioQueueStart`) for each one. When the title re-activates its spatial stream 14–32 times during a heavy world load (`0–17%` free memory), `coreaudiod` IPC fails `AudioQueueStart` with `'what'` (`2003329396`), stalling the caller for `500 ms` of retries and then permanently binding the new spatial stream to `Silent` ("no audio device: sound is mixed and dropped") — even while the process's initial `48_000 Hz` stereo `AudioQueue` is still open and running. 2. When `CoreAudio::open` does open a hardware `AudioQueue` and `AudioQueueStart` fails with `'what'`, #288 retries `AudioQueueStart` on the same failed `AudioQueueRef` instead of disposing it and creating a fresh queue. ## Plan 1. Share one hardware `CoreAudio` `AudioQueue` per `(rate, channels)` across active `Output` handles, mixing attached `Render` callbacks in userspace (`f32` sum, outputting silence when zero streams are attached) so mid-run spatial/WASAPI/XAudio2 stream activations attach without `AudioQueueNewOutput` / `AudioQueueStart` round-trips (reopening only if `AudioQueueEnqueueBuffer` reports a runtime device error). 2. Dispose and recreate the `AudioQueueRef` across `AudioQueueStart` retry attempts when opening the hardware queue for the first time (or after a runtime device failure). 3. Add unit tests covering multi-stream mixing across repeated stream tear-down/re-activation, re-entrant `Output` drop from inside a `Render` callback, and `AudioQueueStart` retry recreating the queue handle.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 12:36:36 +00:00
Author
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 12:35 UTC · original

/claim

**@⁠Sheffy007** on GitHub · 2026-11-27 12:35 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/336#issuecomment-7218439165) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-27 12:35 UTC · original

Claimed by @⁠Sheffy007. Open a draft pull request with Refs #336 in its description within 24 hours, or the claim expires.

**@⁠github-actions[bot]** on GitHub · 2026-11-27 12:35 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/336#issuecomment-7218444896) Claimed by @⁠Sheffy007. Open a draft pull request with `Refs #336` in its description within 24 hours, or the claim expires.
github-bot referenced this issue from a commit 2026-11-27 16:23:10 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.