Tuesday, September 13, 2016

JavaScript says "beep"

UPDATE: it's now a Gist.

Today's snippet: generating a simple musical tone purely from JavaScript. I saw some online samples for doing it on a server (e. g. in PHP) and sending to the client, but that's a waste of bandwidth.

The ingredients are twofold:
  • An <audio> element with a source that's populated from a data: URI
  • An ArrayBuffer object with WAV data inside