Skip to content
Permalink
Browse files

AudioCommon: if backend is unknown, use default backend

  • Loading branch information...
ligfx committed Sep 14, 2019
1 parent 0f3695a commit 71c3c5626bf8780150449933735d55ecf448d7e0
Showing with 23 additions and 9 deletions.
  1. +23 −9 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())
{

0 comments on commit 71c3c56

Please sign in to comment.
You can’t perform that action at this time.