[PR #5193] [MERGED] Audio: list output devices only when the Core Audio devices change (macOS) #6133

Closed
opened 2026-11-03 06:13:32 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5193
Author: @vivescene
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: audio/macos-device-fingerprint


📝 Commits (2)

  • da185c6 Audio: list output devices only when the ALSA cards change
  • 30365e7 Audio: list output devices only when the Core Audio devices change

📊 Changes

1 file changed (+121 additions, -23 deletions)

View changed files

📝 crates/horizon-client-render/src/audio.rs (+121 -23)

📄 Description

🤖 Opened by vivescene's AI agent (Claude Code, Claude Opus 5.5), not by vivescene personally.

Stacked on #5102: only the last commit (30365e7) is new here. Once #5102 merges, I'll rebase this onto main. If @hauserdew-ui would rather fold the macOS branch into #5102, that's fine too, and this can close.

What and why

On macOS, Audio::should_change_device calls cpal's output_devices() every 20 ticks on the render thread. On Core Audio, cpal checks each device's output by opening it (supports_output → supported_configs → AudioComponentInstanceNew, AudioUnitSetProperty, AudioDeviceCreateIOProcID, all round trips to coreaudiod). With 19 devices (12 outputs, mostly virtual: RØDE Unify, Wave Link, Background Music) that takes about 90 ms, so the game froze once a second (#5192).

#5102 already gates the listing on a cheap fingerprint, and the gate covers Linux only. This fills in the macOS branch of card_fingerprint: every Core Audio device's name from host.devices(), inputs included, which doesn't open anything. The list is then looked at only when a device is added, removed or renamed. The default output is still checked every second (0.05 ms), so switching the system output still reopens audio as before. As on Linux, the device list no longer has to be built at startup.

Measured with cpal 0.16 on the same Mac (Apple M4, macOS 26):

Call Time
host.output_devices() + names 89 ms (2.3 s on the first call)
host.devices() + names (the new fingerprint) 2.4 ms
host.default_output_device() + name 0.05 ms

HORIZON_SPIKES=30, sound on:

Build Slow frames
nightly 9d979ca one every second, 85–120 ms (e.g. slow frame 107.9 ms, cpu 11.4 ms (1 ticks): tick 0.6, renderer 0.5)
this branch, offscreen, ~40 s 2, both in the first second while the world loaded
this branch, in a window, ~1 min of play (tested by vivescene at 2560×1440 and 1920×1080) 0

Fixes #5192.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

None. This is Horizon's own audio backend, and nothing players see changes: the same default output opens, and a device being added, removed or becoming the default is still noticed.

Other projects' code

none

Self-check

**pr_ready** (`tools/pr_ready.py --quick` on macos, against origin/main at c3905131b, 2 min 2 s)

| Check | Result |
| --- | --- |
| Scope | ✅ 1 files, +121 −23 |
| Cargo.lock | ✅ unchanged |
| Public tree | ✅ |
| Python tests | ✅ 495 passed (30 s) |
| rustfmt | ✅ (5 s) |
| clippy | ✅ (1 min 19 s) |
| tests: horizon-client-render | ✅ 708 passed (6 s) |
| doc tests | ✅ 0 passed (1 s) |
| content root tests | ➖ content root untouched |
| tokens.css up to date | ➖ theme untouched |
| launcher rustfmt | ➖ launcher untouched |
| launcher clippy | ➖ launcher untouched |
| launcher tests | ➖ launcher untouched |
| Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses |

(Scope counts #5102's commit too; this commit alone is +24 −10.)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/5193 **Author:** [@vivescene](https://github.com/vivescene) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `audio/macos-device-fingerprint` --- ### 📝 Commits (2) - [`da185c6`](https://github.com/horizon-rust/horizon/commit/da185c6128aedfa7309346ff9947a5b553f07441) Audio: list output devices only when the ALSA cards change - [`30365e7`](https://github.com/horizon-rust/horizon/commit/30365e778a6ebf3f57f5e1e203fba42e93107624) Audio: list output devices only when the Core Audio devices change ### 📊 Changes **1 file changed** (+121 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/audio.rs` (+121 -23) </details> ### 📄 Description > 🤖 Opened by vivescene's AI agent (Claude Code, Claude Opus 5.5), not by vivescene personally. **Stacked on #5102**: only the last commit (`30365e7`) is new here. Once #5102 merges, I'll rebase this onto main. If @hauserdew-ui would rather fold the macOS branch into #5102, that's fine too, and this can close. ## What and why On macOS, `Audio::should_change_device` calls cpal's `output_devices()` every 20 ticks on the render thread. On Core Audio, cpal checks each device's output by opening it (`supports_output` → `supported_configs` → `AudioComponentInstanceNew`, `AudioUnitSetProperty`, `AudioDeviceCreateIOProcID`, all round trips to coreaudiod). With 19 devices (12 outputs, mostly virtual: RØDE Unify, Wave Link, Background Music) that takes about 90 ms, so the game froze once a second (#5192). #5102 already gates the listing on a cheap fingerprint, and the gate covers Linux only. This fills in the macOS branch of `card_fingerprint`: every Core Audio device's name from `host.devices()`, inputs included, which doesn't open anything. The list is then looked at only when a device is added, removed or renamed. The default output is still checked every second (0.05 ms), so switching the system output still reopens audio as before. As on Linux, the device list no longer has to be built at startup. Measured with cpal 0.16 on the same Mac (Apple M4, macOS 26): | Call | Time | | --- | --- | | `host.output_devices()` + names | 89 ms (2.3 s on the first call) | | `host.devices()` + names (the new fingerprint) | 2.4 ms | | `host.default_output_device()` + name | 0.05 ms | `HORIZON_SPIKES=30`, sound on: | Build | Slow frames | | --- | --- | | nightly `9d979ca` | one every second, 85–120 ms (e.g. `slow frame 107.9 ms, cpu 11.4 ms (1 ticks): tick 0.6, renderer 0.5`) | | this branch, offscreen, ~40 s | 2, both in the first second while the world loaded | | this branch, in a window, ~1 min of play (tested by vivescene at 2560×1440 and 1920×1080) | 0 | Fixes #5192. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [x] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference None. This is Horizon's own audio backend, and nothing players see changes: the same default output opens, and a device being added, removed or becoming the default is still noticed. ## Other projects' code none ## Self-check ``` **pr_ready** (`tools/pr_ready.py --quick` on macos, against origin/main at c3905131b, 2 min 2 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +121 −23 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed (30 s) | | rustfmt | ✅ (5 s) | | clippy | ✅ (1 min 19 s) | | tests: horizon-client-render | ✅ 708 passed (6 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | ``` (Scope counts #5102's commit too; this commit alone is +24 −10.) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:13:32 +07:00
Sign in to join this conversation.
No milestone
No project
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.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6133
No description provided.