Last active
June 28, 2020 15:38
-
-
Save paceaux/3ce829305be255cefd20f9dfabe4ef95 to your computer and use it in GitHub Desktop.
Graphic EQ in a url
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
/* 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