This message may be relevant:
The bottom line is that you run the function in setInterval()
little faster than your pace, for example, every 100 ms. A short, long example, you can track if the time to play is beat by checking the value of (new Date()).getMilliseconds()
and seeing if the equivalent of one bit has passed in milliseconds instead of relying on the inaccurate accuracy of setTimeout
or setInterval
.
Even so, the music itself, if it is not computer-generated, may not have an ideal or consistent tempo, so accounting for erroneous beats may be an obstacle for you, and this may be the reason for using audio analysis to find where the actual bits may happen, which is the best way .
source share