mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-10 00:41:26 +12:00
Gracefully fall back to a null renderer if XAudio2 fails to Init
This can happen as a non-error condition if user has no output audio devices enabled.
This commit is contained in:
parent
312fc94daa
commit
e005581dda
4 changed files with 26 additions and 8 deletions
|
@ -34,6 +34,12 @@ public:
|
||||||
virtual bool AddData(const void* src, u32 num_samples) = 0;
|
virtual bool AddData(const void* src, u32 num_samples) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This virtual method should be reimplemented if backend can fail to be initialized under non-error conditions
|
||||||
|
* eg. when there is no audio devices attached
|
||||||
|
*/
|
||||||
|
virtual bool Initialized() const { return true; }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Virtual methods - should be implemented depending on backend capabilities
|
* Virtual methods - should be implemented depending on backend capabilities
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -22,7 +22,6 @@ XAudio2Backend::XAudio2Backend()
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
XAudio.error("XAudio2Create() failed(0x%08x)", (u32)hr);
|
XAudio.error("XAudio2Create() failed(0x%08x)", (u32)hr);
|
||||||
Emu.Pause();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ XAudio2Backend::XAudio2Backend()
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
XAudio.error("CreateMasteringVoice() failed(0x%08x)", (u32)hr);
|
XAudio.error("CreateMasteringVoice() failed(0x%08x)", (u32)hr);
|
||||||
Emu.Pause();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// All succeeded, "commit"
|
// All succeeded, "commit"
|
||||||
|
|
|
@ -26,6 +26,8 @@ public:
|
||||||
static const u32 capabilities = PLAY_PAUSE_FLUSH | IS_PLAYING | GET_NUM_ENQUEUED_SAMPLES | SET_FREQUENCY_RATIO;
|
static const u32 capabilities = PLAY_PAUSE_FLUSH | IS_PLAYING | GET_NUM_ENQUEUED_SAMPLES | SET_FREQUENCY_RATIO;
|
||||||
virtual u32 GetCapabilities() const override { return capabilities; };
|
virtual u32 GetCapabilities() const override { return capabilities; };
|
||||||
|
|
||||||
|
virtual bool Initialized() const override { return m_xaudio2_instance != nullptr; }
|
||||||
|
|
||||||
virtual void Open(u32 /* num_buffers */) override;
|
virtual void Open(u32 /* num_buffers */) override;
|
||||||
virtual void Close() override;
|
virtual void Close() override;
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@
|
||||||
#include "Emu/RSX/VK/VKGSRender.h"
|
#include "Emu/RSX/VK/VKGSRender.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
LOG_CHANNEL(sys_log, "SYS");
|
||||||
|
|
||||||
/** Emu.Init() wrapper for user manager */
|
/** Emu.Init() wrapper for user manager */
|
||||||
bool main_application::InitializeEmulator(const std::string& user, bool force_init, bool show_gui)
|
bool main_application::InitializeEmulator(const std::string& user, bool force_init, bool show_gui)
|
||||||
{
|
{
|
||||||
|
@ -144,25 +146,34 @@ EmuCallbacks main_application::CreateCallbacks()
|
||||||
|
|
||||||
callbacks.get_audio = []() -> std::shared_ptr<AudioBackend>
|
callbacks.get_audio = []() -> std::shared_ptr<AudioBackend>
|
||||||
{
|
{
|
||||||
|
std::shared_ptr<AudioBackend> result;
|
||||||
switch (audio_renderer type = g_cfg.audio.renderer)
|
switch (audio_renderer type = g_cfg.audio.renderer)
|
||||||
{
|
{
|
||||||
case audio_renderer::null: return std::make_shared<NullAudioBackend>();
|
case audio_renderer::null: result = std::make_shared<NullAudioBackend>(); break;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
case audio_renderer::xaudio: return std::make_shared<XAudio2Backend>();
|
case audio_renderer::xaudio: result = std::make_shared<XAudio2Backend>(); break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_ALSA
|
#ifdef HAVE_ALSA
|
||||||
case audio_renderer::alsa: return std::make_shared<ALSABackend>();
|
case audio_renderer::alsa: result = std::make_shared<ALSABackend>(); break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_PULSE
|
#ifdef HAVE_PULSE
|
||||||
case audio_renderer::pulse: return std::make_shared<PulseBackend>();
|
case audio_renderer::pulse: result = std::make_shared<PulseBackend>(); break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case audio_renderer::openal: return std::make_shared<OpenALBackend>();
|
case audio_renderer::openal: result = std::make_shared<OpenALBackend>(); break;
|
||||||
#ifdef HAVE_FAUDIO
|
#ifdef HAVE_FAUDIO
|
||||||
case audio_renderer::faudio: return std::make_shared<FAudioBackend>();
|
case audio_renderer::faudio: result = std::make_shared<FAudioBackend>(); break;
|
||||||
#endif
|
#endif
|
||||||
default: fmt::throw_exception("Invalid audio renderer: %s" HERE, type);
|
default: fmt::throw_exception("Invalid audio renderer: %s" HERE, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!result->Initialized())
|
||||||
|
{
|
||||||
|
// Fall back to a null backend if something went wrong
|
||||||
|
sys_log.error("Audio renderer %s could not be initialized, using a Null renderer instead", result->GetName());
|
||||||
|
result = std::make_shared<NullAudioBackend>();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
return callbacks;
|
return callbacks;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue