Skip to content

Instantly share code, notes, and snippets.

@amiika
Created January 30, 2026 17:08
Show Gist options
  • Select an option

  • Save amiika/64b8a8266bc816d8207b5bec523eb25b to your computer and use it in GitHub Desktop.

Select an option

Save amiika/64b8a8266bc816d8207b5bec523eb25b to your computer and use it in GitHub Desktop.
Bytebeat in browser console
window.bytebeat = async (f, d=0.2) => {
if (!f) return window.ctx?.close().then(() => { delete window.ctx; delete window.bb; });
window.ctx = window.ctx || new AudioContext();
await window.ctx.resume();
if (!window.bb) {
const c = `registerProcessor('bb', class extends AudioWorkletProcessor {
constructor() { super(); this.t = 0; this.f = t => 0; this.d = 0.2;
this.port.onmessage = e => {
this.d=e.data.d;
try {let n=new Function('t','return '+e.data.f); n(0); this.f=n;} catch(x) { console.error(x) }
}
}
process(_, o) {
let l=o[0][0];
for (let i=0; i<l.length; i++) {
l[i] = ((this.f(this.t|0)&255)-128)/128;
this.t += this.d ;
}
return true;
}
})`;
const u = URL.createObjectURL(new Blob([c], {type: 'application/javascript'}));
await window.ctx.audioWorklet.addModule(u);
window.bb = new AudioWorkletNode(window.ctx, 'bb', {outputChannelCount: [1]});
window.bb.connect(window.ctx.destination);
}
window.bb.port.postMessage({f,d});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment