emscripten-core/emscripten

Working with Audio Worklet

Open

#6.230 geöffnet am 12. Feb. 2018

Auf GitHub ansehen
 (35 Kommentare) (6 Reaktionen) (0 zugewiesene Personen)C++ (3.519 Forks)batch import
help wanted

Repository-Metriken

Stars
 (27.361 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 19T 10h) (147 gemergte PRs in 30 T)

Beschreibung

Hey guys, I have a hard time integrating WASM + Emscripten with Audio Worklet. He's how we tried to do it:

  1. We are downloading and compiling .wasm file from the main thread.
  2. We are instantiating Emscripten's WASM module in the main thread
Module.instantiateWasm = (imports, successCallback) => {
       wasm.then((wasmBinary) => {
          WebAssembly.instantiate(new Uint8Array(wasmBinary), imports)
            .then((output) => {
              $window.Module.testWasmInstantiationSucceeded = 1;
              successCallback(output.instance, output.module);
            })
        });
        return {};
      };
  1. We are sending wasmModule and wasmMemory to AudioWorklet, thanks to the patch you did on message port
  2. From AudioWorklet thread we wanted to instantiate it by passing its' memory and module, like that:
AudioWorkletGlobalScope.Module['instantiateWasm'] = function(imports, receiveInstance) {
  AudioWorkletGlobalScope.wasmInstance = new WebAssembly.Instance(module, imports);
  receiveInstance(AudioWorkletGlobalScope.wasmInstance, AudioWorkletGlobalScope.Module.wasmModule);
  return AudioWorkletGlobalScope.wasmInstance.exports;
}

but this is problematic. To do that we need to import Emscripten glue-js output file in AudioWorklet context. So I've tried to do something like that: audioCtx.audioWorklet.addModule('wasm/sndt.js') but it didn't work since Emscripten is not prepared to work in the AudioWorklet context.

Best, Jacek.

Contributor Guide