mirror of https://github.com/encounter/SDL.git
Emscripten: Avoid SDL2 in JS global scope
After this fix, closure works with the LLVM wasm backend on SDL2.
This commit is contained in:
parent
6d89a7bc71
commit
53ead95e1d
|
@ -35,6 +35,7 @@ FeedAudioDevice(_THIS, const void *buf, const int buflen)
|
||||||
{
|
{
|
||||||
const int framelen = (SDL_AUDIO_BITSIZE(this->spec.format) / 8) * this->spec.channels;
|
const int framelen = (SDL_AUDIO_BITSIZE(this->spec.format) / 8) * this->spec.channels;
|
||||||
EM_ASM_ARGS({
|
EM_ASM_ARGS({
|
||||||
|
var SDL2 = Module['SDL2'];
|
||||||
var numChannels = SDL2.audio.currentOutputBuffer['numberOfChannels'];
|
var numChannels = SDL2.audio.currentOutputBuffer['numberOfChannels'];
|
||||||
for (var c = 0; c < numChannels; ++c) {
|
for (var c = 0; c < numChannels; ++c) {
|
||||||
var channelData = SDL2.audio.currentOutputBuffer['getChannelData'](c);
|
var channelData = SDL2.audio.currentOutputBuffer['getChannelData'](c);
|
||||||
|
@ -100,6 +101,7 @@ HandleCaptureProcess(_THIS)
|
||||||
}
|
}
|
||||||
|
|
||||||
EM_ASM_ARGS({
|
EM_ASM_ARGS({
|
||||||
|
var SDL2 = Module['SDL2'];
|
||||||
var numChannels = SDL2.capture.currentCaptureBuffer.numberOfChannels;
|
var numChannels = SDL2.capture.currentCaptureBuffer.numberOfChannels;
|
||||||
for (var c = 0; c < numChannels; ++c) {
|
for (var c = 0; c < numChannels; ++c) {
|
||||||
var channelData = SDL2.capture.currentCaptureBuffer.getChannelData(c);
|
var channelData = SDL2.capture.currentCaptureBuffer.getChannelData(c);
|
||||||
|
@ -145,6 +147,7 @@ static void
|
||||||
EMSCRIPTENAUDIO_CloseDevice(_THIS)
|
EMSCRIPTENAUDIO_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
EM_ASM_({
|
EM_ASM_({
|
||||||
|
var SDL2 = Module['SDL2'];
|
||||||
if ($0) {
|
if ($0) {
|
||||||
if (SDL2.capture.silenceTimer !== undefined) {
|
if (SDL2.capture.silenceTimer !== undefined) {
|
||||||
clearTimeout(SDL2.capture.silenceTimer);
|
clearTimeout(SDL2.capture.silenceTimer);
|
||||||
|
@ -196,11 +199,12 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscaptu
|
||||||
|
|
||||||
/* based on parts of library_sdl.js */
|
/* based on parts of library_sdl.js */
|
||||||
|
|
||||||
/* create context (TODO: this puts stuff in the global namespace...)*/
|
/* create context */
|
||||||
result = EM_ASM_INT({
|
result = EM_ASM_INT({
|
||||||
if(typeof(SDL2) === 'undefined') {
|
if(typeof(Module['SDL2']) === 'undefined') {
|
||||||
SDL2 = {};
|
Module['SDL2'] = {};
|
||||||
}
|
}
|
||||||
|
var SDL2 = Module['SDL2'];
|
||||||
if (!$0) {
|
if (!$0) {
|
||||||
SDL2.audio = {};
|
SDL2.audio = {};
|
||||||
} else {
|
} else {
|
||||||
|
@ -249,7 +253,10 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscaptu
|
||||||
this->hidden = (struct SDL_PrivateAudioData *)0x1;
|
this->hidden = (struct SDL_PrivateAudioData *)0x1;
|
||||||
|
|
||||||
/* limit to native freq */
|
/* limit to native freq */
|
||||||
this->spec.freq = EM_ASM_INT_V({ return SDL2.audioContext.sampleRate; });
|
this->spec.freq = EM_ASM_INT_V({
|
||||||
|
var SDL2 = Module['SDL2'];
|
||||||
|
return SDL2.audioContext.sampleRate;
|
||||||
|
});
|
||||||
|
|
||||||
SDL_CalculateAudioSpec(&this->spec);
|
SDL_CalculateAudioSpec(&this->spec);
|
||||||
|
|
||||||
|
@ -271,6 +278,7 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscaptu
|
||||||
to be honest. */
|
to be honest. */
|
||||||
|
|
||||||
EM_ASM_({
|
EM_ASM_({
|
||||||
|
var SDL2 = Module['SDL2'];
|
||||||
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 (SDL2.capture.silenceTimer !== undefined) {
|
if (SDL2.capture.silenceTimer !== undefined) {
|
||||||
|
@ -313,6 +321,7 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscaptu
|
||||||
} else {
|
} else {
|
||||||
/* setup a ScriptProcessorNode */
|
/* setup a ScriptProcessorNode */
|
||||||
EM_ASM_ARGS({
|
EM_ASM_ARGS({
|
||||||
|
var SDL2 = Module['SDL2'];
|
||||||
SDL2.audio.scriptProcessorNode = SDL2.audioContext['createScriptProcessor']($1, 0, $0);
|
SDL2.audio.scriptProcessorNode = SDL2.audioContext['createScriptProcessor']($1, 0, $0);
|
||||||
SDL2.audio.scriptProcessorNode['onaudioprocess'] = function (e) {
|
SDL2.audio.scriptProcessorNode['onaudioprocess'] = function (e) {
|
||||||
if ((SDL2 === undefined) || (SDL2.audio === undefined)) { return; }
|
if ((SDL2 === undefined) || (SDL2.audio === undefined)) { return; }
|
||||||
|
|
Loading…
Reference in New Issue