emscriptenaudio: proxy calls to main thread

This commit is contained in:
Connor Clark 2022-03-26 15:31:33 -07:00 committed by Ryan C. Gordon
parent 96be9cddcc
commit aec86ba8bb
1 changed files with 8 additions and 8 deletions

View File

@ -32,7 +32,7 @@ static void
FeedAudioDevice(_THIS, const void *buf, const int buflen) 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({ MAIN_THREAD_EM_ASM({
var SDL2 = Module['SDL2']; 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) {
@ -101,7 +101,7 @@ HandleCaptureProcess(_THIS)
return; return;
} }
EM_ASM_ARGS({ MAIN_THREAD_EM_ASM({
var SDL2 = Module['SDL2']; 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) {
@ -147,7 +147,7 @@ HandleCaptureProcess(_THIS)
static void static void
EMSCRIPTENAUDIO_CloseDevice(_THIS) EMSCRIPTENAUDIO_CloseDevice(_THIS)
{ {
EM_ASM_({ MAIN_THREAD_EM_ASM({
var SDL2 = Module['SDL2']; var SDL2 = Module['SDL2'];
if ($0) { if ($0) {
if (SDL2.capture.silenceTimer !== undefined) { if (SDL2.capture.silenceTimer !== undefined) {
@ -201,7 +201,7 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname)
/* based on parts of library_sdl.js */ /* based on parts of library_sdl.js */
/* create context */ /* create context */
result = EM_ASM_INT({ result = MAIN_THREAD_EM_ASM_INT({
if(typeof(Module['SDL2']) === 'undefined') { if(typeof(Module['SDL2']) === 'undefined') {
Module['SDL2'] = {}; Module['SDL2'] = {};
} }
@ -280,7 +280,7 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname)
feels like it's a pretty inefficient tapdance in similar ways, feels like it's a pretty inefficient tapdance in similar ways,
to be honest. */ to be honest. */
EM_ASM_({ MAIN_THREAD_EM_ASM({
var SDL2 = Module['SDL2']; 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.');
@ -323,7 +323,7 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, const char *devname)
}, this->spec.channels, this->spec.samples, HandleCaptureProcess, this); }, this->spec.channels, this->spec.samples, HandleCaptureProcess, this);
} else { } else {
/* setup a ScriptProcessorNode */ /* setup a ScriptProcessorNode */
EM_ASM_ARGS({ MAIN_THREAD_EM_ASM({
var SDL2 = Module['SDL2']; 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) {
@ -359,7 +359,7 @@ EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
impl->ProvidesOwnCallbackThread = SDL_TRUE; impl->ProvidesOwnCallbackThread = SDL_TRUE;
/* check availability */ /* check availability */
available = EM_ASM_INT_V({ available = MAIN_THREAD_EM_ASM_INT({
if (typeof(AudioContext) !== 'undefined') { if (typeof(AudioContext) !== 'undefined') {
return true; return true;
} else if (typeof(webkitAudioContext) !== 'undefined') { } else if (typeof(webkitAudioContext) !== 'undefined') {
@ -372,7 +372,7 @@ EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
SDL_SetError("No audio context available"); SDL_SetError("No audio context available");
} }
capture_available = available && EM_ASM_INT_V({ capture_available = available && MAIN_THREAD_EM_ASM_INT({
if ((typeof(navigator.mediaDevices) !== 'undefined') && (typeof(navigator.mediaDevices.getUserMedia) !== 'undefined')) { if ((typeof(navigator.mediaDevices) !== 'undefined') && (typeof(navigator.mediaDevices.getUserMedia) !== 'undefined')) {
return true; return true;
} else if (typeof(navigator.webkitGetUserMedia) !== 'undefined') { } else if (typeof(navigator.webkitGetUserMedia) !== 'undefined') {