diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2026-11-16 01:13:25 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2026-11-17 13:03:41 -0600 |
| commit | 2e0a63c918aeec3d3a7ffe08cd41ec3ad45ea0f8 (patch) | |
| tree | 9a5da0815b8b1346ba5c5bc2a87c51b287c9b4f0 /Source/Core/AudioCommon/CubebUtils.cpp | |
| parent | eaad965f5785a63112949535ce14798d32dd38bf (diff) | |
CubebUtils: Initialize Cubeb based on the configured audio backend even when it's set to just "Pulse" or "ALSA".
Diffstat (limited to 'Source/Core/AudioCommon/CubebUtils.cpp')
| -rw-r--r-- | Source/Core/AudioCommon/CubebUtils.cpp | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/Source/Core/AudioCommon/CubebUtils.cpp b/Source/Core/AudioCommon/CubebUtils.cpp index ff1a304880..b86283dcdf 100644 --- a/Source/Core/AudioCommon/CubebUtils.cpp +++ b/Source/Core/AudioCommon/CubebUtils.cpp @@ -7,6 +7,7 @@ #include <cstring> #include <string_view> +#include "AudioCommon/AudioCommon.h" #include "Common/Logging/Log.h" #include "Common/Logging/LogManager.h" #include "Common/StringUtil.h" @@ -52,6 +53,30 @@ static void DestroyContext(cubeb* ctx) } } +static std::string GetCubebBackendName() +{ + std::string audio_backend = Config::Get(Config::MAIN_AUDIO_BACKEND); + + if (!AudioCommon::IsCubebBackend(audio_backend)) + { + // A non-Cubeb audio backend is configured. + // A lowercase version of this string will work some of the time. + // e.g. for "Pulse" or "ALSA". + // Cubeb will internally use a fallback if it's not a valid string. + Common::ToLower(&audio_backend); + return audio_backend; + } + + // Cubeb may have its own backend specified after a slash. + // e.g. "Cubeb/wasapi" + const auto cubeb_backend_delimiter_pos = audio_backend.find('/'); + + if (cubeb_backend_delimiter_pos == std::string::npos) + return {}; + + return std::move(audio_backend).substr(cubeb_backend_delimiter_pos + 1); +} + namespace CubebUtils { std::shared_ptr<cubeb> GetContext() @@ -68,13 +93,9 @@ std::shared_ptr<cubeb> GetContext() ERROR_LOG_FMT(AUDIO, "Error setting cubeb log callback"); } - // Cubeb may have its own backend specified after a slash. - // e.g. "Cubeb/wasapi" - const auto audio_backend = Config::Get(Config::MAIN_AUDIO_BACKEND); - const auto cubeb_backend_delimiter_pos = audio_backend.find('/'); - const char* const backend_name = (cubeb_backend_delimiter_pos == std::string::npos) ? - nullptr : - audio_backend.c_str() + cubeb_backend_delimiter_pos + 1; + const auto backend_name_str = GetCubebBackendName(); + const char* const backend_name = backend_name_str.empty() ? nullptr : backend_name_str.c_str(); + cubeb* ctx; if (cubeb_init(&ctx, "Dolphin Emulator", backend_name) != CUBEB_OK) { |
