From 909cf03568b2b9ca62cd72a7d20e494fac21be66 Mon Sep 17 00:00:00 2001 From: Marcelo Fernandez Date: Wed, 25 Jul 2018 17:58:56 -0300 Subject: [PATCH] Fixed device capture switching for WASAPI driver --- drivers/wasapi/audio_driver_wasapi.cpp | 30 ++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/wasapi/audio_driver_wasapi.cpp b/drivers/wasapi/audio_driver_wasapi.cpp index 7113a777355..a01d991450a 100644 --- a/drivers/wasapi/audio_driver_wasapi.cpp +++ b/drivers/wasapi/audio_driver_wasapi.cpp @@ -699,6 +699,32 @@ void AudioDriverWASAPI::thread_func(void *p_udata) { ERR_BREAK(hr != S_OK); } } + + // If we're using the Default device and it changed finish it so we'll re-init the device + if (ad->audio_input.device_name == "Default" && default_capture_device_changed) { + Error err = ad->finish_capture_device(); + if (err != OK) { + ERR_PRINT("WASAPI: finish_capture_device error"); + } + + default_capture_device_changed = false; + } + + // User selected a new device, finish the current one so we'll init the new device + if (ad->audio_input.device_name != ad->audio_input.new_device) { + ad->audio_input.device_name = ad->audio_input.new_device; + Error err = ad->finish_capture_device(); + if (err != OK) { + ERR_PRINT("WASAPI: finish_capture_device error"); + } + } + + if (!ad->audio_input.audio_client) { + Error err = ad->init_capture_device(true); + if (err == OK) { + ad->capture_start(); + } + } } ad->stop_counting_ticks(); @@ -798,10 +824,10 @@ Array AudioDriverWASAPI::capture_get_device_list() { return audio_device_get_list(true); } -StringName AudioDriverWASAPI::capture_get_device() { +String AudioDriverWASAPI::capture_get_device() { lock(); - StringName name = audio_input.device_name; + String name = audio_input.device_name; unlock(); return name;