Live data from Hacker News

Show HN: Drum machine in 100 lines of HTML/JS

sig.gy

1–10 of 51 posts

Re: Show HN: Drum machine in 100 lines of HTML/JS

#8
post #7

Cool! when tab is not active, the rhythm slows down in Chrome/win7.

This is due to a step taken by the browser to improve performance, namely, timers in Chrome are limited to 'ticking' at most once a second when a tab is backgrounded. The drum loop is at its core:

    setInterval(function() {...}, 1 / (4*BPM/(60*1000)));
https://codereview.chromium.org/6577021

Re: Show HN: Drum machine in 100 lines of HTML/JS

#9
Nice work! Although from my experience with audio programming in the browser, setInterval() is always fraught with timing danger and inconsistencies.

Have you considered using WebAudio's streaming functionality to tighten up the timing to something more rock solid? Probably a bit more setup in the first part, but for a drum machine especially, you get much better control over timing and playback note length.

I wrote an Ionic specific example of using the browser's WebAudio functionality to write a metronome app here: https://www.airpair.com/ionic-framework/posts/using-web-audi...

Post reply on HN