Skip to content

Improve audio device management and add fixed-rate mixer with FIR resampling#393

Open
PauloAguiar wants to merge 3 commits into
vE5li:mainfrom
PauloAguiar:pauloaguiar/audio-device-management
Open

Improve audio device management and add fixed-rate mixer with FIR resampling#393
PauloAguiar wants to merge 3 commits into
vE5li:mainfrom
PauloAguiar:pauloaguiar/audio-device-management

Conversation

@PauloAguiar
Copy link
Copy Markdown

@PauloAguiar PauloAguiar commented Mar 21, 2026

The audio mixer now always runs at 48kHz internally. When the output device uses a different sample rate (e.g. 44.1kHz), a FIR resampler (-60dB attenuation) converts the final output. This eliminates sample rate issues on device switch — sounds no longer need to be reloaded or re-resampled when switching devices.

Audio device management: Users can select their preferred output device from a dropdown in the Audio Settings window. The preference is persisted to audio_settings.ron and restored on next launch. If the saved device isn't available, the system default is used without overwriting the saved preference.

Live device list updates: The backend monitoring thread refreshes the available device list every 500ms. Device additions/removals (e.g. plugging in headphones) are reflected in the UI dropdown automatically.
Device identity by ID: Devices are identified by their stable platform ID (e.g. WASAPI endpoint ID) rather than display name, so preferences survive device renames.

Audio backend refactoring: Simplified OutputDevicePreference to only hold the user's preference and available device list. Removed Arc sample rate sharing from track handles — no longer needed with the fixed mixer rate. Cleaned up the Renderer to own its resampling logic entirely.

Debug logging: Added timestamped logging for device selection, BGM loading, ambient sound enter/leave, and device switching.

audio-device

Replace hardcoded audio config with device capability querying:
- Use device default config instead of hardcoded 48kHz/1200-frame buffer
- Read live sample rate at play time for correct resampling after
  device switches
- Detect system default device changes and auto-reconnect
- Support selecting a specific output device via SharedDeviceState
- Extract SharedDeviceState for clean cross-thread device info sharing
- Add device listing and selection API to AudioEngine

A few simplifications in the audio pipeline

let (mut initial_result_producer, mut initial_result_consumer) = RingBuffer::new(1);

std::thread::spawn(move || {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole logic has been pulled up to the backend which also manages device discovery and device preference changes. This is now only responsible for managing the stream.

@PauloAguiar PauloAguiar force-pushed the pauloaguiar/audio-device-management branch from 1ab7372 to 9f3d8e1 Compare March 21, 2026 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant