From 13e2ea708abe4a786604cc39c6e74b6846128f19 Mon Sep 17 00:00:00 2001
From: vicrodh <103399283+vicrodh@users.noreply.github.com>
Date: Fri, 16 Jan 2026 21:57:41 -0600
Subject: [PATCH] Fix critical device selection bug in audio settings
PROBLEM:
When user selected a specific audio device (e.g., Cambridge Audio DAC),
audio would always play through system default device (laptop speakers)
instead of the selected device.
ROOT CAUSE:
All calls to reinit_audio_device() were passing device: null instead of
the actual selected device name. When device: null is passed, the Player
falls back to system default regardless of user selection.
Affected functions:
- handleOutputDeviceChange() - Primary bug, selected device ignored
- handleExclusiveModeChange() - Reset to default when toggling
- handleDacPassthroughChange() - Reset to default when toggling
- handleGaplessPlaybackChange() - Reset to default when auto-disabling DAC
- handleCrossfadeChange() - Reset to default when auto-disabling DAC
FIX:
Created getCurrentDeviceSinkName() helper that:
- Returns the internal sink name for selected device
- Returns null only for "System Default" selection
- Used consistently across all audio setting changes
SECONDARY CHANGES:
Improved DAC Passthrough warning messages in AudioOutputBadges:
- "ERROR: PipeWire is resampling" instead of generic warning
- Clearer tooltip guidance for fixing resampling issues
- Better distinction between active/warning/disabled states
This ensures device selection persists across all audio setting changes
and provides clearer feedback when bit-perfect playback is compromised.
---
src/lib/components/AudioOutputBadges.svelte | 11 ++++----
src/lib/components/views/SettingsView.svelte | 29 ++++++++++++++------
2 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/src/lib/components/AudioOutputBadges.svelte b/src/lib/components/AudioOutputBadges.svelte
index edbaf939a..f87e62f7d 100644
--- a/src/lib/components/AudioOutputBadges.svelte
+++ b/src/lib/components/AudioOutputBadges.svelte
@@ -196,17 +196,18 @@
●
{#if dacBadgeState === 'warning'}
- ⚠ DAC Passthrough: Resampling detected
+ ⚠ ERROR: PipeWire is resampling
{#if hardwareStatus?.hardware_sample_rate && samplingRate}
-
{samplingRate} kHz → {(hardwareStatus.hardware_sample_rate / 1000).toFixed(1)} kHz
+
File: {samplingRate} kHz → Hardware: {(hardwareStatus.hardware_sample_rate / 1000).toFixed(1)} kHz
+
Fix: Configure PipeWire sample rate switching
{/if}
{:else if dacBadgeState === 'active'}
- DAC Passthrough: Bit-perfect
+ ✓ DAC Passthrough: Bit-perfect
{#if hardwareStatus?.hardware_sample_rate}
-
{(hardwareStatus.hardware_sample_rate / 1000).toFixed(1)} kHz
+
{(hardwareStatus.hardware_sample_rate / 1000).toFixed(1)} kHz native
{/if}
{:else}
- DAC Passthrough: Off
+ DAC Passthrough: Disabled
{/if}
diff --git a/src/lib/components/views/SettingsView.svelte b/src/lib/components/views/SettingsView.svelte
index 31c14258b..0ef032565 100644
--- a/src/lib/components/views/SettingsView.svelte
+++ b/src/lib/components/views/SettingsView.svelte
@@ -765,6 +765,14 @@
preferred_sample_rate: number | null;
}
+ // Helper to get the current selected device sink name (or null for system default)
+ function getCurrentDeviceSinkName(): string | null {
+ if (outputDevice === 'System Default') {
+ return null;
+ }
+ return sinkDescriptionToName.get(outputDevice) ?? null;
+ }
+
async function loadAudioDevices() {
try {
// Load PipeWire sinks - these have friendly descriptions already
@@ -828,8 +836,9 @@
await invoke('set_pipewire_default_sink', { sinkName });
}
- // Reinitialize audio to use the new default
- await invoke('reinit_audio_device', { device: null });
+ // Reinitialize audio to use the selected device
+ // IMPORTANT: Pass the actual sink name, not null
+ await invoke('reinit_audio_device', { device: deviceToStore });
console.log('Audio output device changed:', description, '(sink:', sinkName ?? 'default', ')');
} catch (err) {
@@ -841,8 +850,9 @@
exclusiveMode = enabled;
try {
await invoke('set_audio_exclusive_mode', { enabled });
- // Reinitialize audio to apply/release exclusive mode (uses PipeWire default)
- await invoke('reinit_audio_device', { device: null });
+ // Reinitialize audio to apply/release exclusive mode
+ // IMPORTANT: Maintain the currently selected output device
+ await invoke('reinit_audio_device', { device: getCurrentDeviceSinkName() });
console.log('Exclusive mode changed and audio reinitialized:', enabled);
} catch (err) {
console.error('Failed to change exclusive mode:', err);
@@ -861,8 +871,9 @@
try {
await invoke('set_audio_dac_passthrough', { enabled });
- // DAC passthrough may also require reinit for proper effect (uses PipeWire default)
- await invoke('reinit_audio_device', { device: null });
+ // DAC passthrough may also require reinit for proper effect
+ // IMPORTANT: Maintain the currently selected output device
+ await invoke('reinit_audio_device', { device: getCurrentDeviceSinkName() });
console.log('DAC passthrough changed and audio reinitialized:', enabled);
} catch (err) {
console.error('Failed to change DAC passthrough:', err);
@@ -878,7 +889,8 @@
console.log('Gapless playback enabled: disabled DAC passthrough');
try {
await invoke('set_audio_dac_passthrough', { enabled: false });
- await invoke('reinit_audio_device', { device: null });
+ // IMPORTANT: Maintain the currently selected output device
+ await invoke('reinit_audio_device', { device: getCurrentDeviceSinkName() });
} catch (err) {
console.error('Failed to disable DAC passthrough:', err);
}
@@ -894,7 +906,8 @@
console.log('Crossfade enabled: disabled DAC passthrough');
try {
await invoke('set_audio_dac_passthrough', { enabled: false });
- await invoke('reinit_audio_device', { device: null });
+ // IMPORTANT: Maintain the currently selected output device
+ await invoke('reinit_audio_device', { device: getCurrentDeviceSinkName() });
} catch (err) {
console.error('Failed to disable DAC passthrough:', err);
}