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}); | |
| }; |
Author
If you try to run this when github page is open you will get error like "Refused to load the script ...". You need to open some other page and open console there. Either some random webpage (Most webpages do not block external scripts) or something running on localhost that is not blocking the script. Note: Start page will also block scripts, so you need to have some webpage open.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.