From f6b973d384d84933cbee4599831bf39647f6669f Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 21 Jan 2026 12:14:34 +1000 Subject: [PATCH] Allow backends to work without stepping when threading is disabled. This is per-backend. --- miniaudio.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index e9e3a229..29a906fc 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -7297,6 +7297,7 @@ typedef struct ma_device_backend_info const char* pName; ma_bool32 isLoopbackSupported; ma_bool32 noAudioThread; /* When set to true, the backend does not create a miniaudio-managed audio thread. Will be used for backends like Web Audio, or those that run on platforms that do not support multithreading. Depending on the backend, this may force single-threaded mode. Single-threaded mode will not be enforced for the Web Audio backend. */ + ma_bool32 isMultiThreadedModeAllowedWhenThreadingDisabled; /* When set to true, the backend must be 100% thread safe. */ } ma_device_backend_info; @@ -45937,6 +45938,7 @@ static void ma_backend_info__webaudio(ma_device_backend_info* pBackendInfo) MA_ASSERT(pBackendInfo != NULL); pBackendInfo->pName = "Web Audio"; pBackendInfo->noAudioThread = MA_TRUE; /* We don't want to be creating a miniaudio-managed audio thread with Web Audio. */ + pBackendInfo->isMultiThreadedModeAllowedWhenThreadingDisabled = MA_TRUE; } static ma_result ma_context_init__webaudio(ma_context* pContext, const void* pContextBackendConfig, void** ppContextState) @@ -48428,18 +48430,20 @@ MA_API ma_result ma_device_init(ma_context* pContext, const ma_device_config* pC return MA_INVALID_ARGS; } + /* We'll need the backend info to determine whether or not an audio thread can be created. */ + ma_context_get_backend_info(pContext, &backendInfo); + threadingMode = pConfig->threadingMode; /* Force single-threaded mode if threading has been disabled at compile time. */ #ifdef MA_NO_THREADING { - threadingMode = MA_THREADING_MODE_SINGLE_THREADED; + if (!backendInfo.isMultiThreadedModeAllowedWhenThreadingDisabled) { + threadingMode = MA_THREADING_MODE_SINGLE_THREADED; + } } #endif - /* We'll need the backend info to determine whether or not an audio thread can be created. */ - ma_context_get_backend_info(pContext, &backendInfo); - /* Check that we have our callbacks defined. */ if (pContext->pVTable->onDeviceInit == NULL) { return MA_INVALID_OPERATION;