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

Closed
opened 2026-11-27 12:35:39 +00:00 by Sheffy007 · 2 comments
Sheffy007 commented 2026-11-27 12:35:39 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T12:35:39Z.


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.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6646549814 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/336). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T12:35:39Z. --- ## 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 commented 2026-11-27 12:35:41 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T12:35:41Z.


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218439165 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/336#issuecomment-7218439165). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T12:35:41Z. --- /claim
github-actions[bot] commented 2026-11-27 12:35:55 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T12:35:55Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218444896 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/336#issuecomment-7218444896). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-27T12:35:55Z. --- Claimed by @Sheffy007. Open a draft pull request with `Refs #336` in its description within 24 hours, or the claim expires.
Sign in to join this conversation.
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
LakshanSivakumar/Native-Victory-macOS#336
No description provided.