21 comments

[ 3.4 ms ] story [ 29.6 ms ] thread
That's very funny. You should do a Mario theme song also :)
Nifty! I'd love to be able to specify tone (sine wave, square wave, triangle wave).
I'd love to specify wave types or even more advanced stuff such as FM synthesis. With a little work, modules such as this one may enable a whole new category of innovative/strange browser apps.
A friend recently created something similar, and he ended up transcribing the full-length Super Mario theme song! http://eshiota.github.io/retro-audio-js/

Presentation here: http://www.slideshare.net/eshiota/web-audio-band-playing-wit...

Very awesome! Interestingly, in both Chrome and Firefox, the song stops playing ("mostly") if you switch to a different tab. I say "mostly" because Chrome seems to play a single note every 10-20 seconds even with the tab backgrounded.
Yeap, both setTimeout and setInterval are being sacrificed for performance. Alternatively you could use WebWorkers to offload the timers for precision.
I remember making these kinds of songs in BASIC. Very fun!
I remember in PASCAL with the sound() function:

  sound(100);
  delay(3000);
  nosound;
very nice, although the text shadow on the code makes it a bit hard to read
I would love to see a MIDI interpreter for something like this. MIDI is already a series of note events (among other weird things like pitchbend and sustain, so it couldn't be too hard.
If play returned a reference to the play function you could chain them like

    .play('D#5', 1/4)('E5', 1/4)
Just a thought on cleaning up the syntax a bit.
A cleaner way may be to allow the play() method to accept a plain JS array of notes:

  var notes = ['D#5', 1/4, 'E5', 1/4];
             or
  var notes = [['D#5', 1/4], ['E5', 1/4]];

  beeplay().play(notes);
I plan to do it! A 'toJSON()' method is only for that.