带有 SDL 音频的 Emscripten worker-model

Emscripten worker-model with SDL audio

据我了解,Emscripten 工作模型不支持共享状态。但是,我可以在 SDL 音频回调和我的主循环之间共享全局变量,如果我理解正确的话,这应该是不可能的。 emscripten 是否在主线程上执行音频回调,因此这是可能的,还是我完全误解了 worker 概念和全局变量共享?

(我的假设是音频回调是在 worker 中执行的)。

注意:我指的是在没有 pthreads 支持的情况下编译的 emscripten。

Does emscripten execute the audio callback on the main thread

是的。

据我所知,Javascript(无论是否从 C++ 编译)在浏览器中无法播放音频 not主线程。

正如在 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 中看到的那样,AudioContext 只能在主线程中创建,在 Worker 作用域中是不可访问的..

https://developer.mozilla.org/en/docs/Web/API/AudioContext 中提到了 AudioWorker,但它说明了 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.