From 97fb8d332ac914a6dcecbdb25b86ca21644fe85b Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Sat, 17 Jan 2026 19:52:47 -0600 Subject: [PATCH] Fix ALSA device name translation and Auto mode device selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ALSA Device Name Translation: - Added missing patterns: front:CARD=, surround*:CARD=, iec958:CARD= - Now shows "Cambridge Audio USB Front Output" instead of "front CS201 Output 0" - Updated CARD_NAMES: CS201 → "Cambridge Audio USB", C20 → "Cambridge Audio" - Surround patterns: 40→4.0, 41→4.1, 50→5.0, 51→5.1, 71→7.1 - S/PDIF (iec958) pattern added Auto Mode Device Selection Fix (CRITICAL): - Auto mode now only allows "System Default" (no specific device selection) - Fixes device mismatch issue where PipeWire device names fail in ALSA - Previous behavior caused: * User selects DAC in Auto mode (PipeWire device name) * Player uses legacy ALSA path * Device not found → falls back to default * 18+ second delay before playback starts - Auto mode is now truly automatic - always uses System Default This prevents cross-backend device name incompatibility. If user wants to select specific device, they must choose PipeWire, ALSA Direct, or PulseAudio backend explicitly. --- src/lib/components/views/SettingsView.svelte | 32 +++++--------------- src/lib/utils/audioDeviceNames.ts | 26 +++++++++++++++- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/lib/components/views/SettingsView.svelte b/src/lib/components/views/SettingsView.svelte index 6cf2ec2dd..3918dd373 100644 --- a/src/lib/components/views/SettingsView.svelte +++ b/src/lib/components/views/SettingsView.svelte @@ -789,24 +789,10 @@ } } else { selectedBackend = 'Auto'; - // Auto mode: load devices from first available backend - // This allows showing proper device names with translation - if (availableBackends.length > 0) { - const firstBackend = availableBackends.find(b => b.is_available); - if (firstBackend) { - await loadBackendDevices(firstBackend.backend_type); - - // Set selected device from backend devices - if (settings.output_device) { - const device = backendDevices.find(d => d.id === settings.output_device); - if (device) { - outputDevice = needsTranslation(device.name) ? getDevicePrettyName(device.name) : device.name; - } else { - outputDevice = 'System Default'; - } - } - } - } + // Auto mode: always use System Default (no device selection) + // Device names from one backend (e.g., PipeWire) don't work in another (e.g., ALSA) + backendDevices = []; + outputDevice = 'System Default'; } if (settings.alsa_plugin) { @@ -925,13 +911,9 @@ if (backendType) { await loadBackendDevices(backendType); } else { - // Auto mode: load devices from first available backend for device selection - if (availableBackends.length > 0) { - const firstBackend = availableBackends.find(b => b.is_available); - if (firstBackend) { - await loadBackendDevices(firstBackend.backend_type); - } - } + // Auto mode: no device selection (System Default only) + // Device IDs from different backends are incompatible + backendDevices = []; } // Reset to default device when switching backends (always) diff --git a/src/lib/utils/audioDeviceNames.ts b/src/lib/utils/audioDeviceNames.ts index 87a3efac1..35514b744 100644 --- a/src/lib/utils/audioDeviceNames.ts +++ b/src/lib/utils/audioDeviceNames.ts @@ -6,7 +6,8 @@ const CARD_NAMES: Record = { 'sofhdadsp': 'Intel HD Audio', 'NVidia': 'NVIDIA GPU', - 'CS201': 'USB Audio', // Common USB audio chip + 'CS201': 'Cambridge Audio USB', + 'C20': 'Cambridge Audio', 'Generic': 'Generic Audio', 'PCH': 'Onboard Audio', 'HDMI': 'HDMI Audio', @@ -32,6 +33,29 @@ export function getDevicePrettyName(alsaName: string): string { return 'JACK Audio'; } + // Pattern: front:CARD=XXX,DEV=N + const frontMatch = alsaName.match(/^front:CARD=([^,]+),DEV=(\d+)$/); + if (frontMatch) { + const cardName = CARD_NAMES[frontMatch[1]] || frontMatch[1]; + return `${cardName} Front Output`; + } + + // Pattern: surround40, surround41, surround50, surround51, surround71:CARD=XXX,DEV=N + const surroundMatch = alsaName.match(/^surround(\d{2}):CARD=([^,]+),DEV=(\d+)$/); + if (surroundMatch) { + const channels = surroundMatch[1]; + const cardName = CARD_NAMES[surroundMatch[2]] || surroundMatch[2]; + const channelName = channels === '40' ? '4.0' : channels === '41' ? '4.1' : channels === '50' ? '5.0' : channels === '51' ? '5.1' : channels === '71' ? '7.1' : channels; + return `${cardName} Surround ${channelName}`; + } + + // Pattern: iec958:CARD=XXX,DEV=N (S/PDIF) + const iec958Match = alsaName.match(/^iec958:CARD=([^,]+),DEV=(\d+)$/); + if (iec958Match) { + const cardName = CARD_NAMES[iec958Match[1]] || iec958Match[1]; + return `${cardName} S/PDIF`; + } + // Pattern: hdmi:CARD=XXX,DEV=N const hdmiMatch = alsaName.match(/^hdmi:CARD=([^,]+),DEV=(\d+)$/); if (hdmiMatch) {