Skip to content

Instantly share code, notes, and snippets.

@speratus
Last active April 26, 2023 21:09
Show Gist options
  • Save speratus/5aa9ec704291ffc6d117b72f80c1ce90 to your computer and use it in GitHub Desktop.
Save speratus/5aa9ec704291ffc6d117b72f80c1ce90 to your computer and use it in GitHub Desktop.
The Main JS file for my Web Synth Prototype
let startBtn = document.getElementById('start-sound');
async function setup() {
const bin = await WebAssembly.compileStreaming(await fetch('/www/wasm_demo.wasm'));
// const buf = await bin.arrayBuffer();
let context = new AudioContext();
console.log("adding module");
await context.audioWorklet.addModule('processor.js');
let node = new AudioWorkletNode(context, 'web-synth-proto');
node.port.postMessage({type: 'init-wasm', wasmData: bin});
node.connect(context.destination);
let stopBtn = document.getElementById('stop-sound');
stopBtn.addEventListener('click', () => {
context.close();
});
}
startBtn.addEventListener('click', () => {
setup();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment