From d8efc3e29d07a938fc949b44480d3f0f0db0b708 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Thu, 15 Aug 2024 21:51:59 -0400 Subject: [PATCH] validate the state of the audio device, and attempt to reinit if its not running (and die in a panic if it can't be reinited); --- src/bridge/HostBridge.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/bridge/HostBridge.cpp b/src/bridge/HostBridge.cpp index 17c5def9..eab48252 100644 --- a/src/bridge/HostBridge.cpp +++ b/src/bridge/HostBridge.cpp @@ -487,6 +487,25 @@ int HostBridge::run() ms = stopWatch.elapsed(); stopWatch.start(); + // ------------------------------------------------------ + // -- Audio Device Checking -- + // ------------------------------------------------------ + + if (m_localAudio) { + ma_device_state state = ma_device_get_state(&m_maDevice); + if (state != ma_device_state_started) { + LogError(LOG_HOST, "audio device state invalid, state = %u", state); + + // restart audio device + result = ma_device_start(&m_maDevice); + if (result != MA_SUCCESS) { + ma_device_uninit(&m_maDevice); + ma_context_uninit(&m_maContext); + ::fatal("failed to reinitialize audio device! panic."); + } + } + } + // ------------------------------------------------------ // -- Network Clocking -- // ------------------------------------------------------