Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Graphic EQ in a url
/* Courtesy of Jake Albaugh: https://twitter.com/jake_albaugh/status/1118611365508337665 */
const bars = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"];
const ctx = new AudioContext();
const analyser = ctx.createAnalyser();
analyser.fftSize = 32;
const uIntArray = new Uint8Array(16);
navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
ctx.createMediaStreamSource(stream).connect(analyser);
updateUrl();
ctx.resume();
});
function updateUrl() {
setTimeout(updateUrl, 40);
analyser.getByteFrequencyData(uIntArray);
const eq = [];
uIntArray.forEach(v => eq.push(bars[Math.floor((v / 255) * 8)]));
location.hash = document.title = eq.join("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.