From 41b72f660c9872a721484dd1b69eeaa2330a2ed2 Mon Sep 17 00:00:00 2001 From: David Reid Date: Tue, 20 Apr 2021 17:43:36 +1000 Subject: [PATCH] WASAPI: Attempt to fix a bug with loopback mode. Public issue https://github.com/mackron/miniaudio/issues/298 --- miniaudio.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index 1661c7c7..261ed36f 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -16030,8 +16030,16 @@ static ma_result ma_device_data_loop__wasapi(ma_device* pDevice) /* Wait for data to become available first. */ if (WaitForSingleObject(pDevice->wasapi.hEventCapture, MA_WASAPI_WAIT_TIMEOUT_MILLISECONDS) != WAIT_OBJECT_0) { - exitLoop = MA_TRUE; - break; /* Wait failed. */ + /* + For capture we can terminate here because it probably means the microphone just isn't delivering data for whatever reason, but + for loopback is most likely means nothing is actually playing. We want to keep trying in this situation. + */ + if (pDevice->type == ma_device_type_loopback) { + continue; /* Keep waiting in loopback mode. */ + } else { + exitLoop = MA_TRUE; + break; /* Wait failed. */ + } } /* See how many frames are available. Since we waited at the top, I don't think this should ever return 0. I'm checking for this anyway. */