src/audio/emscripten/SDL_emscriptenaudio.c
changeset 12580 e5c1992fcd8b
parent 12503 806492103856
child 12581 62f26ad46749
     1.1 --- a/src/audio/emscripten/SDL_emscriptenaudio.c	Tue Jan 29 12:19:32 2019 +0000
     1.2 +++ b/src/audio/emscripten/SDL_emscriptenaudio.c	Tue Jan 29 12:19:36 2019 +0000
     1.3 @@ -35,6 +35,7 @@
     1.4  {
     1.5      const int framelen = (SDL_AUDIO_BITSIZE(this->spec.format) / 8) * this->spec.channels;
     1.6      EM_ASM_ARGS({
     1.7 +        var SDL2 = Module['SDL2'];
     1.8          var numChannels = SDL2.audio.currentOutputBuffer['numberOfChannels'];
     1.9          for (var c = 0; c < numChannels; ++c) {
    1.10              var channelData = SDL2.audio.currentOutputBuffer['getChannelData'](c);
    1.11 @@ -100,6 +101,7 @@
    1.12      }
    1.13  
    1.14      EM_ASM_ARGS({
    1.15 +        var SDL2 = Module['SDL2'];
    1.16          var numChannels = SDL2.capture.currentCaptureBuffer.numberOfChannels;
    1.17          for (var c = 0; c < numChannels; ++c) {
    1.18              var channelData = SDL2.capture.currentCaptureBuffer.getChannelData(c);
    1.19 @@ -145,6 +147,7 @@
    1.20  EMSCRIPTENAUDIO_CloseDevice(_THIS)
    1.21  {
    1.22      EM_ASM_({
    1.23 +        var SDL2 = Module['SDL2'];
    1.24          if ($0) {
    1.25              if (SDL2.capture.silenceTimer !== undefined) {
    1.26                  clearTimeout(SDL2.capture.silenceTimer);
    1.27 @@ -196,11 +199,12 @@
    1.28  
    1.29      /* based on parts of library_sdl.js */
    1.30  
    1.31 -    /* create context (TODO: this puts stuff in the global namespace...)*/
    1.32 +    /* create context */
    1.33      result = EM_ASM_INT({
    1.34 -        if(typeof(SDL2) === 'undefined') {
    1.35 -            SDL2 = {};
    1.36 +        if(typeof(Module['SDL2']) === 'undefined') {
    1.37 +            Module['SDL2'] = {};
    1.38          }
    1.39 +        var SDL2 = Module['SDL2'];
    1.40          if (!$0) {
    1.41              SDL2.audio = {};
    1.42          } else {
    1.43 @@ -249,7 +253,10 @@
    1.44      this->hidden = (struct SDL_PrivateAudioData *)0x1;
    1.45  
    1.46      /* limit to native freq */
    1.47 -    this->spec.freq = EM_ASM_INT_V({ return SDL2.audioContext.sampleRate; });
    1.48 +    this->spec.freq = EM_ASM_INT_V({
    1.49 +      var SDL2 = Module['SDL2'];
    1.50 +      return SDL2.audioContext.sampleRate;
    1.51 +    });
    1.52  
    1.53      SDL_CalculateAudioSpec(&this->spec);
    1.54  
    1.55 @@ -271,6 +278,7 @@
    1.56             to be honest. */
    1.57  
    1.58          EM_ASM_({
    1.59 +            var SDL2 = Module['SDL2'];
    1.60              var have_microphone = function(stream) {
    1.61                  //console.log('SDL audio capture: we have a microphone! Replacing silence callback.');
    1.62                  if (SDL2.capture.silenceTimer !== undefined) {
    1.63 @@ -313,6 +321,7 @@
    1.64      } else {
    1.65          /* setup a ScriptProcessorNode */
    1.66          EM_ASM_ARGS({
    1.67 +            var SDL2 = Module['SDL2'];
    1.68              SDL2.audio.scriptProcessorNode = SDL2.audioContext['createScriptProcessor']($1, 0, $0);
    1.69              SDL2.audio.scriptProcessorNode['onaudioprocess'] = function (e) {
    1.70                  if ((SDL2 === undefined) || (SDL2.audio === undefined)) { return; }