MP3 Decoder Written in JavaScript

At firest I was a little puzzled by this story to which Slashdot linked last night. HTML5 includes natively capabilities for playing back audio though not all formats are supported equally by all browsers, for reasons similar to the much more visible debates over video formats. A JavaScript powered player on cursory inspection would seem to be yet another front end to this multimedia capability increasingly available in newer browser.

jsmad isn’t a front end, though. Digging into the story a bit more, it is actually a native decoder for several variations of the MP3 format that runs entirely in JavaScript. It has more in common, then, with the the recent x86 emulator and several game emulators that have been ported or written from scratch to execute in the browser without using any plugins or any special multimedia capabilities.

Porting notes

Obviously, porting low-level C code to Javascript isn’t an easy task. Some things had to be adapted pretty heavily. jsmad is not the result of an automatic translation – all 15K+ lines of code were translated by hand by @nddrylliog and @jensnockert during MusicHackDay Berlin. Then, @mgeorgi helped us a lot with the debugging process, and @antoinem did the design of the demo during MusicHackDay Barcelona.

It performs well enough to decode and play MP3s in realtime on Firefox on modern computers, although if you do lots of things at once, Firefox might forget at all about scheduled tasks and let the soundcard underflow. There is a rescue mechanism for that in the demo, which works most of the time.

There is a fully capable demo, written in a very brief amount of time as part of the Music Hackday. I ran into a couple of issues with playback but outside of that, the experience is entirely comparable with the usual Flash players.

If it is possible to run a fixed point, compute and data intensive decoder like this with nothing more than the browser’s JavaScript engine, I have to imagine it should also be possible to port many of the open formats, like Ogg Vorbis and Flac. As a podcaster, the possibilities here are very alluring. jsmad is free software, available under the GPL v2 so it isn’t unreasonable to expect as interest increases, so should performance, accuracy and stability.

JavaScript decoder lets MP3s play in Firefox without Flash, via Slashdot

Leave a Reply

Your email address will not be published. Required fields are marked *