19 12 / 2011
Recently, Apple open sourced the original encoder and decoder for the Apple Lossless audio codec which is written in C/C++. ALAC is, as its name implies, a lossless codec, which means that it is compressed but does not lose any quality. When decoded, ALAC audio files are bit-for-bit identical to the original uncompressed audio file.
Besides porting over the decoder (by hand, not with a tool like Emscripten), we have been working on a little framework called Aurora.js, which handles the boilerplate of writing a codec in JS, from actually streaming the file from the server and implementing the bitstream classes, to finding the correct demuxers and decoders and playing back the audio through the browser’s audio API as abstracted by Sink.js. There are currently two competing audio APIs and a third in the works, so an abstraction like Sink.js was necessary.
We couldn’t do anything without a cool demo, so we built a site showcasing our two audio decoders, JSMad and ALAC.js, side-by-side. If you notice your CPU usage a bit higher than expected, that is actually not the audio decoder but the visualizer. You can click on the visualizer to disable it and see for yourself.