Created
January 30, 2026 17:08
-
-
Save amiika/64b8a8266bc816d8207b5bec523eb25b to your computer and use it in GitHub Desktop.
Bytebeat in browser console
This file contains hidden or 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
| 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