From my basic understanding, JavaScript audio visualizers are reflecting the music based on the actual sound waves. I would like to build something like a metronome (http://bl.ocks.org/1399233), where I animate some DOM element every x
beats.
The way I'm doing this now is I manually figure out the tempo of the song, say it's 120bpm, then I convert that to milliseconds to run a setInterval
callback. But that doesn't seem to work because the browser performance causes it to be imprecise. Is there a better way to make sure a callback is executed exactly at the same tempo a song is in?
If not, what are some other strategies to sync JavaScript animations with a song's tempo that's not an audio visualizer?
Update: something like this it looks like? https://github.com/bestiejs/benchmark.js/blob/master/benchmark.js#L1606