2
votes

As I understand Emscripten worker model, it does not support a shared state. However, I can share global variables between the SDL audio callback and my mainloop, which if I understand this correctly, shouldn't be possible. Does emscripten execute the audio callback on the main thread and therefore this is possible, or am I completely missunderstanding the worker concept and global variable sharing?

(My assumption was the audio-callback is executed in a worker).

Note: I'm referring to emscripten compiled without pthreads support.

1

1 Answers

3
votes

Does emscripten execute the audio callback on the main thread

Yes.

As far as I know there isn't any way for Javascript (be it compiled from C++ or not) in the browser to play audio not from the main thread.

As can be seen at https://github.com/kripken/emscripten/blob/1.36.4/src/library_sdl.js, Emscripten uses AudioContext under the hood, and looking through https://developer.mozilla.org/en/docs/Web/API/AudioContext and https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope, an AudioContext can only be created in the main thread and is not accessible in a Worker scope..

At https://developer.mozilla.org/en/docs/Web/API/AudioContext this is mention of AudioWorker, but it states about createAudioWorker...

Creates an AudioWorkerNode, which can interact with a web worker thread to generate, process, or analyse audio directly. This was added to the spec on August 29 2014, and is not implemented in any browser yet.