diff options
| author | Michael M <mchtly@gmail.com> | 2019-09-14 14:16:13 -0700 |
|---|---|---|
| committer | Michael M <mchtly@gmail.com> | 2019-09-14 14:16:13 -0700 |
| commit | 71c3c5626bf8780150449933735d55ecf448d7e0 (patch) | |
| tree | 8e896ef7f0b224cab147dd9e9bebf34a2b0372ed /Source/Core/AudioCommon/AudioCommon.cpp | |
| parent | 0f3695a14b0bc71ba4ab0dc440fc606f14af61c2 (diff) | |
AudioCommon: if backend is unknown, use default backend
Diffstat (limited to 'Source/Core/AudioCommon/AudioCommon.cpp')
| -rw-r--r-- | Source/Core/AudioCommon/AudioCommon.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/Source/Core/AudioCommon/AudioCommon.cpp b/Source/Core/AudioCommon/AudioCommon.cpp index 3019d00505..dd9986077e 100644 --- a/Source/Core/AudioCommon/AudioCommon.cpp +++ b/Source/Core/AudioCommon/AudioCommon.cpp @@ -27,23 +27,37 @@ static bool s_sound_stream_running = false; constexpr int AUDIO_VOLUME_MIN = 0; constexpr int AUDIO_VOLUME_MAX = 100; -void InitSoundStream() +static std::unique_ptr<SoundStream> CreateSoundStreamForBackend(std::string_view backend) { - std::string backend = SConfig::GetInstance().sBackend; if (backend == BACKEND_CUBEB) - g_sound_stream = std::make_unique<CubebStream>(); + return std::make_unique<CubebStream>(); else if (backend == BACKEND_OPENAL && OpenALStream::isValid()) - g_sound_stream = std::make_unique<OpenALStream>(); + return std::make_unique<OpenALStream>(); else if (backend == BACKEND_NULLSOUND) - g_sound_stream = std::make_unique<NullSound>(); + return std::make_unique<NullSound>(); else if (backend == BACKEND_ALSA && AlsaSound::isValid()) - g_sound_stream = std::make_unique<AlsaSound>(); + return std::make_unique<AlsaSound>(); else if (backend == BACKEND_PULSEAUDIO && PulseAudio::isValid()) - g_sound_stream = std::make_unique<PulseAudio>(); + return std::make_unique<PulseAudio>(); else if (backend == BACKEND_OPENSLES && OpenSLESStream::isValid()) - g_sound_stream = std::make_unique<OpenSLESStream>(); + return std::make_unique<OpenSLESStream>(); else if (backend == BACKEND_WASAPI && WASAPIStream::isValid()) - g_sound_stream = std::make_unique<WASAPIStream>(); + return std::make_unique<WASAPIStream>(); + return {}; +} + +void InitSoundStream() +{ + std::string backend = SConfig::GetInstance().sBackend; + g_sound_stream = CreateSoundStreamForBackend(backend); + + if (!g_sound_stream) + { + WARN_LOG(AUDIO, "Unknown backend %s, using %s instead.", backend.c_str(), + GetDefaultSoundBackend().c_str()); + backend = GetDefaultSoundBackend(); + g_sound_stream = CreateSoundStreamForBackend(GetDefaultSoundBackend()); + } if (!g_sound_stream || !g_sound_stream->Init()) { |
