src/audio/emscripten/SDL_emscriptenaudio.c
changeset 12581 62f26ad46749
parent 12580 e5c1992fcd8b
equal deleted inserted replaced
12580:e5c1992fcd8b 12581:62f26ad46749
   289                 SDL2.capture.scriptProcessorNode = SDL2.audioContext.createScriptProcessor($1, $0, 1);
   289                 SDL2.capture.scriptProcessorNode = SDL2.audioContext.createScriptProcessor($1, $0, 1);
   290                 SDL2.capture.scriptProcessorNode.onaudioprocess = function(audioProcessingEvent) {
   290                 SDL2.capture.scriptProcessorNode.onaudioprocess = function(audioProcessingEvent) {
   291                     if ((SDL2 === undefined) || (SDL2.capture === undefined)) { return; }
   291                     if ((SDL2 === undefined) || (SDL2.capture === undefined)) { return; }
   292                     audioProcessingEvent.outputBuffer.getChannelData(0).fill(0.0);
   292                     audioProcessingEvent.outputBuffer.getChannelData(0).fill(0.0);
   293                     SDL2.capture.currentCaptureBuffer = audioProcessingEvent.inputBuffer;
   293                     SDL2.capture.currentCaptureBuffer = audioProcessingEvent.inputBuffer;
   294                     Runtime.dynCall('vi', $2, [$3]);
   294                     dynCall('vi', $2, [$3]);
   295                 };
   295                 };
   296                 SDL2.capture.mediaStreamNode.connect(SDL2.capture.scriptProcessorNode);
   296                 SDL2.capture.mediaStreamNode.connect(SDL2.capture.scriptProcessorNode);
   297                 SDL2.capture.scriptProcessorNode.connect(SDL2.audioContext.destination);
   297                 SDL2.capture.scriptProcessorNode.connect(SDL2.audioContext.destination);
   298                 SDL2.capture.stream = stream;
   298                 SDL2.capture.stream = stream;
   299             };
   299             };
   305             /* we write silence to the audio callback until the microphone is available (user approves use, etc). */
   305             /* we write silence to the audio callback until the microphone is available (user approves use, etc). */
   306             SDL2.capture.silenceBuffer = SDL2.audioContext.createBuffer($0, $1, SDL2.audioContext.sampleRate);
   306             SDL2.capture.silenceBuffer = SDL2.audioContext.createBuffer($0, $1, SDL2.audioContext.sampleRate);
   307             SDL2.capture.silenceBuffer.getChannelData(0).fill(0.0);
   307             SDL2.capture.silenceBuffer.getChannelData(0).fill(0.0);
   308             var silence_callback = function() {
   308             var silence_callback = function() {
   309                 SDL2.capture.currentCaptureBuffer = SDL2.capture.silenceBuffer;
   309                 SDL2.capture.currentCaptureBuffer = SDL2.capture.silenceBuffer;
   310                 Runtime.dynCall('vi', $2, [$3]);
   310                 dynCall('vi', $2, [$3]);
   311             };
   311             };
   312 
   312 
   313             SDL2.capture.silenceTimer = setTimeout(silence_callback, ($1 / SDL2.audioContext.sampleRate) * 1000);
   313             SDL2.capture.silenceTimer = setTimeout(silence_callback, ($1 / SDL2.audioContext.sampleRate) * 1000);
   314 
   314 
   315             if ((navigator.mediaDevices !== undefined) && (navigator.mediaDevices.getUserMedia !== undefined)) {
   315             if ((navigator.mediaDevices !== undefined) && (navigator.mediaDevices.getUserMedia !== undefined)) {
   324             var SDL2 = Module['SDL2'];
   324             var SDL2 = Module['SDL2'];
   325             SDL2.audio.scriptProcessorNode = SDL2.audioContext['createScriptProcessor']($1, 0, $0);
   325             SDL2.audio.scriptProcessorNode = SDL2.audioContext['createScriptProcessor']($1, 0, $0);
   326             SDL2.audio.scriptProcessorNode['onaudioprocess'] = function (e) {
   326             SDL2.audio.scriptProcessorNode['onaudioprocess'] = function (e) {
   327                 if ((SDL2 === undefined) || (SDL2.audio === undefined)) { return; }
   327                 if ((SDL2 === undefined) || (SDL2.audio === undefined)) { return; }
   328                 SDL2.audio.currentOutputBuffer = e['outputBuffer'];
   328                 SDL2.audio.currentOutputBuffer = e['outputBuffer'];
   329                 Runtime.dynCall('vi', $2, [$3]);
   329                 dynCall('vi', $2, [$3]);
   330             };
   330             };
   331             SDL2.audio.scriptProcessorNode['connect'](SDL2.audioContext['destination']);
   331             SDL2.audio.scriptProcessorNode['connect'](SDL2.audioContext['destination']);
   332         }, this->spec.channels, this->spec.samples, HandleAudioProcess, this);
   332         }, this->spec.channels, this->spec.samples, HandleAudioProcess, this);
   333     }
   333     }
   334 
   334