Last active
April 26, 2023 21:09
-
-
Save speratus/5aa9ec704291ffc6d117b72f80c1ce90 to your computer and use it in GitHub Desktop.
The Main JS file for my Web Synth Prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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