From 7c0dcea96cef421b6f670cdc5e7b1b3ed63bf939 Mon Sep 17 00:00:00 2001 From: Narr the Reg Date: Thu, 9 Feb 2023 19:38:03 -0600 Subject: audio: cubeb: Fix yuzu crashing when it test for latency --- src/audio_core/sink/cubeb_sink.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/audio_core') diff --git a/src/audio_core/sink/cubeb_sink.cpp b/src/audio_core/sink/cubeb_sink.cpp index 32c1b1cb3..9133f5388 100644 --- a/src/audio_core/sink/cubeb_sink.cpp +++ b/src/audio_core/sink/cubeb_sink.cpp @@ -302,11 +302,21 @@ std::vector ListCubebSinkDevices(bool capture) { std::vector device_list; cubeb* ctx; +#ifdef _WIN32 + auto com_init_result = CoInitializeEx(nullptr, COINIT_MULTITHREADED); +#endif + if (cubeb_init(&ctx, "yuzu Device Enumerator", nullptr) != CUBEB_OK) { LOG_CRITICAL(Audio_Sink, "cubeb_init failed"); return {}; } +#ifdef _WIN32 + if (SUCCEEDED(com_init_result)) { + CoUninitialize(); + } +#endif + auto type{capture ? CUBEB_DEVICE_TYPE_INPUT : CUBEB_DEVICE_TYPE_OUTPUT}; cubeb_device_collection collection; if (cubeb_enumerate_devices(ctx, type, &collection) != CUBEB_OK) { @@ -329,12 +339,22 @@ std::vector ListCubebSinkDevices(bool capture) { u32 GetCubebLatency() { cubeb* ctx; +#ifdef _WIN32 + auto com_init_result = CoInitializeEx(nullptr, COINIT_MULTITHREADED); +#endif + if (cubeb_init(&ctx, "yuzu Latency Getter", nullptr) != CUBEB_OK) { LOG_CRITICAL(Audio_Sink, "cubeb_init failed"); // Return a large latency so we choose SDL instead. return 10000u; } +#ifdef _WIN32 + if (SUCCEEDED(com_init_result)) { + CoUninitialize(); + } +#endif + cubeb_stream_params params{}; params.rate = TargetSampleRate; params.channels = 2; -- cgit v1.2.3