emscripten audio: check for an "undefined" object, remove some console.log().
authorRyan C. Gordon <icculus@icculus.org>
Fri, 12 Aug 2016 00:03:58 -0400
changeset 10265 1b8594db77f1
parent 10264 8bd5eb9d96c7
child 10266 c09f06c4e8c8
emscripten audio: check for an "undefined" object, remove some console.log().
src/audio/emscripten/SDL_emscriptenaudio.c
--- a/src/audio/emscripten/SDL_emscriptenaudio.c	Thu Aug 11 22:26:58 2016 -0400
+++ b/src/audio/emscripten/SDL_emscriptenaudio.c	Fri Aug 12 00:03:58 2016 -0400
@@ -330,8 +330,11 @@
 
         EM_ASM_({
             var have_microphone = function(stream) {
-                clearTimeout(SDL2.capture.silenceTimer);
-                SDL2.capture.silenceTimer = undefined;
+                //console.log('SDL audio capture: we have a microphone! Replacing silence callback.');
+                if (SDL2.capture.silenceTimer !== undefined) {
+                    clearTimeout(SDL2.capture.silenceTimer);
+                    SDL2.capture.silenceTimer = undefined;
+                }
                 SDL2.capture.mediaStreamNode = SDL2.audioContext.createMediaStreamSource(stream);
                 SDL2.capture.scriptProcessorNode = SDL2.audioContext.createScriptProcessor($1, $0, 1);
                 SDL2.capture.scriptProcessorNode.onaudioprocess = function(audioProcessingEvent) {
@@ -344,13 +347,12 @@
             };
 
             var no_microphone = function(error) {
-                console.log('we DO NOT have a microphone! (' + error.name + ')...leaving silence callback running.');
+                //console.log('SDL audio capture: we DO NOT have a microphone! (' + error.name + ')...leaving silence callback running.');
             };
 
             /* we write silence to the audio callback until the microphone is available (user approves use, etc). */
             SDL2.capture.silenceBuffer = SDL2.audioContext.createBuffer($0, $1, SDL2.audioContext.sampleRate);
             SDL2.capture.silenceBuffer.getChannelData(0).fill(0.0);
-
             var silence_callback = function() {
                 SDL2.capture.currentCaptureBuffer = SDL2.capture.silenceBuffer;
                 Runtime.dynCall('vi', $2, [$3]);