From b821ece0527188d51475fdbaa9d8e0d21ccb3d5a Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Sun, 2 Oct 2022 17:09:13 +0200 Subject: [PATCH] alsa: default to 'auto' device if configured one can't be opened Issue #762 --- core/oslib/audiobackend_alsa.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/oslib/audiobackend_alsa.cpp b/core/oslib/audiobackend_alsa.cpp index 414d01317..273a08f5c 100644 --- a/core/oslib/audiobackend_alsa.cpp +++ b/core/oslib/audiobackend_alsa.cpp @@ -16,7 +16,13 @@ static void alsa_init() std::string device = cfgLoadStr("alsa", "device", ""); int rc = -1; - if (device.empty() || device == "auto") + + if (!device.empty() && device != "auto") { + rc = snd_pcm_open(&handle, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0); + if (rc < 0) + WARN_LOG(AUDIO, "ALSA: Cannot open device %s. Trying auto", device.c_str()); + } + if (rc < 0) { INFO_LOG(AUDIO, "ALSA: trying to determine audio device"); @@ -54,13 +60,10 @@ static void alsa_init() if (rc < 0) INFO_LOG(AUDIO, "ALSA: unable to automatically determine audio device."); } - else { - rc = snd_pcm_open(&handle, device.c_str(), SND_PCM_STREAM_PLAYBACK, 0); - } if (rc < 0) { - WARN_LOG(AUDIO, "ALSA: unable to open PCM device %s: %s", device.c_str(), snd_strerror(rc)); + ERROR_LOG(AUDIO, "ALSA: unable to open PCM device %s: %s", device.c_str(), snd_strerror(rc)); return; }