From fb79211732d0cdf17a250a43c619b6938842cfaf Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 23 Aug 2023 16:12:30 -0400 Subject: [PATCH] emscriptenaudio: Fire the capture silence_callback at an interval. Previously it was using setTimeout, not setInterval, so it would only fire once, which was obviously a mistake. --- src/audio/emscripten/SDL_emscriptenaudio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/audio/emscripten/SDL_emscriptenaudio.c b/src/audio/emscripten/SDL_emscriptenaudio.c index dae5d2f7d..408706978 100644 --- a/src/audio/emscripten/SDL_emscriptenaudio.c +++ b/src/audio/emscripten/SDL_emscriptenaudio.c @@ -97,7 +97,7 @@ static void EMSCRIPTENAUDIO_CloseDevice(SDL_AudioDevice *device) var SDL3 = Module['SDL3']; if ($0) { if (SDL3.capture.silenceTimer !== undefined) { - clearTimeout(SDL3.capture.silenceTimer); + clearInterval(SDL3.capture.silenceTimer); } if (SDL3.capture.stream !== undefined) { var tracks = SDL3.capture.stream.getAudioTracks(); @@ -215,7 +215,7 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device) var have_microphone = function(stream) { //console.log('SDL audio capture: we have a microphone! Replacing silence callback.'); if (SDL3.capture.silenceTimer !== undefined) { - clearTimeout(SDL3.capture.silenceTimer); + clearInterval(SDL3.capture.silenceTimer); SDL3.capture.silenceTimer = undefined; SDL3.capture.silenceBuffer = undefined } @@ -244,7 +244,7 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device) dynCall('vi', $2, [$3]); }; - SDL3.capture.silenceTimer = setTimeout(silence_callback, ($1 / SDL3.audioContext.sampleRate) * 1000); + SDL3.capture.silenceTimer = setInterval(silence_callback, ($1 / SDL3.audioContext.sampleRate) * 1000); if ((navigator.mediaDevices !== undefined) && (navigator.mediaDevices.getUserMedia !== undefined)) { navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then(have_microphone).catch(no_microphone);