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.
This commit is contained in:
vicrodh committed 2026-01-16 21:57:41 -06:00
1 parent 40cd6d7303
commit 13e2ea708a
2 files changed
+27 -13

No files matched your search

+6 -5
View File
@@ -196,17 +196,18 @@
<span class="setting-icon" class:active={dacBadgeState === 'active'} class:warning={dacBadgeState === 'warning'}>●</span>
<span class="setting-text">
{#if dacBadgeState === 'warning'}
⚠ DAC Passthrough: Resampling detected
⚠ ERROR: PipeWire is resampling
{#if hardwareStatus?.hardware_sample_rate && samplingRate}
<br><span class="setting-detail">{samplingRate} kHz → {(hardwareStatus.hardware_sample_rate / 1000).toFixed(1)} kHz</span>
<br><span class="setting-detail">File: {samplingRate} kHz → Hardware: {(hardwareStatus.hardware_sample_rate / 1000).toFixed(1)} kHz</span>
<br><span class="setting-help">Fix: Configure PipeWire sample rate switching</span>
{/if}
{:else if dacBadgeState === 'active'}
DAC Passthrough: Bit-perfect
✓ DAC Passthrough: Bit-perfect
{#if hardwareStatus?.hardware_sample_rate}
<br><span class="setting-detail">{(hardwareStatus.hardware_sample_rate / 1000).toFixed(1)} kHz</span>
<br><span class="setting-detail">{(hardwareStatus.hardware_sample_rate / 1000).toFixed(1)} kHz native</span>
{/if}
{:else}
DAC Passthrough: Off
DAC Passthrough: Disabled
{/if}
</span>
</div>
+21 -8
View File
@@ -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);
}