Skip to content

[audioworklet] AudioWorklets integration with WebAssembly #2427

Closed
@juj

Description

@juj

Reading the AudioWorklet reference at https://github.com/WebAudio/web-audio-api/wiki/AudioWorklet-Examples and https://github.com/WebAudio/web-audio-api/wiki/AudioWorklet-IDL-Proposal, it looks like code that would utilize WebAssembly to render audio in an AudioWorklet would look something like the following:

registerAudioWorkletProcessor('WasmInAudioWorklet', class extends AudioWorkletProcessor {
  constructor (options) {
    super(options);

    // Compile and Instantiate Wasm Module here, communicate with SharedArrayBuffer with the remaining program
    this.wasmModule = ...;
    this.wasmInstance = ...;
    this.wasmHeap = new Float32Array(...);
  }

  process(inputs, outputs, parameters) {
    for(var i = 0; i < inputs.length; ++i) { // *
      var input = inputs[i]; // *
      for(var j = 0; j < input.length; ++j) this.wasmHeap[... + j] = input[j]; // *
    } // *
    this.wasmInstance.processAudio();

    for(var i = 0; i < outputs.length; ++i) {  // *
      var output = outputs[i]; // *
      for(var j = 0; j < output.length; ++j) { // *
        output[j] = this.wasmHeap[... + j]; // *
      } // *
    } // *
  }
});

Talking with WebAssembly developers and @lukewagner, he is suggesting that it would be made possible to register the WebAssembly heap at AudioWorklet construction time, so that one would be able to optimize away the copies on the lines marked with stars // *.

Would something like this be feasible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: UrgentWG charter deliverables; "need to have". https://speced.github.io/spec-maintenance/about/

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions