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.
main
Ryan C. Gordon 2023-08-23 16:12:30 -04:00
parent 5191b20541
commit fb79211732
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 3 additions and 3 deletions

View File

@ -97,7 +97,7 @@ static void EMSCRIPTENAUDIO_CloseDevice(SDL_AudioDevice *device)
var SDL3 = Module['SDL3']; var SDL3 = Module['SDL3'];
if ($0) { if ($0) {
if (SDL3.capture.silenceTimer !== undefined) { if (SDL3.capture.silenceTimer !== undefined) {
clearTimeout(SDL3.capture.silenceTimer); clearInterval(SDL3.capture.silenceTimer);
} }
if (SDL3.capture.stream !== undefined) { if (SDL3.capture.stream !== undefined) {
var tracks = SDL3.capture.stream.getAudioTracks(); var tracks = SDL3.capture.stream.getAudioTracks();
@ -215,7 +215,7 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device)
var have_microphone = function(stream) { var have_microphone = function(stream) {
//console.log('SDL audio capture: we have a microphone! Replacing silence callback.'); //console.log('SDL audio capture: we have a microphone! Replacing silence callback.');
if (SDL3.capture.silenceTimer !== undefined) { if (SDL3.capture.silenceTimer !== undefined) {
clearTimeout(SDL3.capture.silenceTimer); clearInterval(SDL3.capture.silenceTimer);
SDL3.capture.silenceTimer = undefined; SDL3.capture.silenceTimer = undefined;
SDL3.capture.silenceBuffer = undefined SDL3.capture.silenceBuffer = undefined
} }
@ -244,7 +244,7 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device)
dynCall('vi', $2, [$3]); 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)) { if ((navigator.mediaDevices !== undefined) && (navigator.mediaDevices.getUserMedia !== undefined)) {
navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then(have_microphone).catch(no_microphone); navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then(have_microphone).catch(no_microphone);