Audio : allow XAudio2 to run its own thread (#1980)

This commit is contained in:
raven02 2016-07-25 08:25:02 +08:00 committed by GitHub
parent 132093c80e
commit 53b2e19d96
2 changed files with 14 additions and 0 deletions

View File

@ -62,6 +62,7 @@ void XAudio2Thread::xa27_destroy()
{ {
s_tls_xaudio2_instance->StopEngine(); s_tls_xaudio2_instance->StopEngine();
s_tls_xaudio2_instance->Release(); s_tls_xaudio2_instance->Release();
CoUninitialize();
} }
CoUninitialize(); CoUninitialize();
@ -117,6 +118,8 @@ void XAudio2Thread::xa27_open()
if (FAILED(hr)) if (FAILED(hr))
{ {
LOG_ERROR(GENERAL, "XAudio2Thread : CreateSourceVoice() failed(0x%08x)", (u32)hr); LOG_ERROR(GENERAL, "XAudio2Thread : CreateSourceVoice() failed(0x%08x)", (u32)hr);
s_tls_xaudio2_instance->Release();
CoUninitialize();
Emu.Pause(); Emu.Pause();
return; return;
} }

View File

@ -20,6 +20,14 @@ void XAudio2Thread::xa28_init(void* module)
HRESULT hr = S_OK; HRESULT hr = S_OK;
hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); // allow Xaudio2 run in its own thread
if (FAILED(hr))
{
LOG_ERROR(GENERAL, "XAudio2Thread : CoInitializeEx() failed(0x%08x)", (u32)hr);
Emu.Pause();
return;
}
hr = create(&s_tls_xaudio2_instance, 0, XAUDIO2_DEFAULT_PROCESSOR); hr = create(&s_tls_xaudio2_instance, 0, XAUDIO2_DEFAULT_PROCESSOR);
if (FAILED(hr)) if (FAILED(hr))
{ {
@ -56,6 +64,7 @@ void XAudio2Thread::xa28_destroy()
{ {
s_tls_xaudio2_instance->StopEngine(); s_tls_xaudio2_instance->StopEngine();
s_tls_xaudio2_instance->Release(); s_tls_xaudio2_instance->Release();
CoUninitialize();
} }
} }
@ -109,6 +118,8 @@ void XAudio2Thread::xa28_open()
if (FAILED(hr)) if (FAILED(hr))
{ {
LOG_ERROR(GENERAL, "XAudio2Thread : CreateSourceVoice() failed(0x%08x)", (u32)hr); LOG_ERROR(GENERAL, "XAudio2Thread : CreateSourceVoice() failed(0x%08x)", (u32)hr);
s_tls_xaudio2_instance->Release();
CoUninitialize();
Emu.Pause(); Emu.Pause();
return; return;
} }