Skip to content

Instantly share code, notes, and snippets.

@hakasenyang
Forked from paceaux/graphicEQUrl.js
Created April 19, 2019 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakasenyang/483a0c99f21368187876d657add37e2a to your computer and use it in GitHub Desktop.
Save hakasenyang/483a0c99f21368187876d657add37e2a to your computer and use it in GitHub Desktop.
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