Live data from Hacker News

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

sig.gy

21–30 of 51 posts

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

#23
Fun! I like the interface and the URL pattern encoding.

Here's mine: http://wa-101.net/. I used setInterval too, because I found the web audio api docs for the timing functions rather confusing, and I'd set myself a time-limit on getting something "attractive" working.

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

#25

Never use setInterval for audio based applications. It's just totally unreliable. WebAudio has nice built in features for high precision timing.

When the goal is showing off what you can do with 100 lines of code, what's wrong with it?

I doubt high precision timing can be done with the same amount of code.

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

#28
Reminds me of one I made years ago (back before Web Audio, when the HTML5 tag was actually pretty new)[0]. It's not under 100 lines, but it's self-contained and (mostly) readable like this one is. These days I'd definitely go with Web Audio as the playback mechanism, of course.

[0] http://stepheneisenhauer.com/demos/drummachine/

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

#30
I had a go at rewriting this to use requestAnimationFrame, and provide more instruments and some random/clear buttons: https://blog.omgmog.net/beatmaker/

Including whitespace it's 102 lines: https://github.com/omgmog/beatmaker/blob/master/js/index.js

An interesting thing, after a short while the browser unloads the page (Chrome on Mac OS) -- probably due to memory usage, which I think this is down to creating a new Audio element each time, rather than initialising them once and then triggering .play() when needed.

update:

Alright I'm using AudioContext now rather than `new Audio`, seems to be performing a lot better. This puts us at about 144 lines.

Post reply on HN