Closed
Description
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?