Use aplay -L for real ALSA device descriptions instead of hardcoding

ALSA Backend Changes:
- Parse aplay -L output to get real hardware descriptions
- Description from hardware: "Cambridge Audio Cambridge Audio USB Audio 2.0, USB Audio"
- No more hardcoded CARD_NAMES for specific hardware
- Still uses CPAL to verify device exists and get max sample rate
- Blacklist filtering preserved (null, lavrate, samplerate, etc.)

Frontend Changes:
- Prefer device.description (from aplay -L) when available
- Falls back to getDevicePrettyName() translation only if no description
- ALSA Direct shows: "Cambridge Audio ... USB Audio, Front output / input"
- Not: "Cambridge Audio USB Front Output" (hardcoded translation)

Removed Hardcoding:
- Removed CS201 → "Cambridge Audio USB" (was specific to user's DAC)
- Removed C20 → "Cambridge Audio"
- Generic CARD_NAMES remain (NVidia, Intel HD Audio, etc.)

This makes device names work for ANY hardware, not just known cards.
Each backend should use native tools:
- ALSA: aplay -L
- PipeWire: pw-cli/pactl (future)
- PulseAudio: pactl (future)
This commit is contained in:
vicrodh committed 2026-01-17 19:55:22 -06:00
1 parent 97fb8d332a
commit c871f6becd
3 files changed
+110 -59

No files matched your search

+18 -6
View File
@@ -227,11 +227,17 @@
}
// Device options based on selected backend (derived)
// Apply pretty names only to raw ALSA device names (Auto may use ALSA or PipeWire)
// For ALSA: use description from aplay -L if available, otherwise translate
// For PipeWire/PulseAudio: names are already friendly
let deviceOptions = $derived.by(() => {
const names = backendDevices.map(d =>
needsTranslation(d.name) ? getDevicePrettyName(d.name) : d.name
);
const names = backendDevices.map(d => {
// If backend provides description (ALSA via aplay -L), use it
if (d.description && selectedBackend === 'ALSA Direct') {
return d.description;
}
// Otherwise apply translation if needed
return needsTranslation(d.name) ? getDevicePrettyName(d.name) : d.name;
});
return ['System Default', ...names];
});
@@ -239,7 +245,10 @@
let deviceByDisplayName = $derived.by(() => {
const map = new Map<string, AudioDevice>();
for (const device of backendDevices) {
const displayName = needsTranslation(device.name) ? getDevicePrettyName(device.name) : device.name;
// Same logic: prefer description for ALSA
const displayName = (device.description && selectedBackend === 'ALSA Direct')
? device.description
: (needsTranslation(device.name) ? getDevicePrettyName(device.name) : device.name);
map.set(displayName, device);
}
return map;
@@ -782,7 +791,10 @@
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;
// Use description from aplay -L if available (ALSA), otherwise translate
outputDevice = (device.description && settings.backend_type === 'Alsa')
? device.description
: (needsTranslation(device.name) ? getDevicePrettyName(device.name) : device.name);
} else {
outputDevice = 'System Default';
}