JavaScript mp2 decoder by @cosinusoidally (Github mp2dec.js)

JavaScript MPEG-1 Audio Layer II decoder. A port of . Playback code based on a Mozilla Audio API example from:


// The decoder lives in an iframe you need to load it into your document.
// load the mp2 decoder (doesn't quite work like this yet, in the source you will see I'm doing foo("exports"))

// create mp2 state
var mp2=mp2_dec.kjmp2_make_mp2_state();

// initialise the decoder

// get your sample rate (frame is an array containing mp2 data)
var samplerate=mp2_dec.kjmp2_get_sample_rate(frame);

// decode your first frame
// l and r are the output arrays (left and right channel)
// pcm is unused (must be set to an empty array, silly bug)
var bytes_read=mp2_dec.kjmp2_decode_frame(mp2,frame,pcm,l,r);


Retrieves whole file, then decodes it in one go. Once it has decoded you can then play the audio (a play button will appear). Should work in Firefox 5,6 , and possibly 4. Decoding is scheduled using setTimeout, so keep this tab focused. Audio file is public domain. ( ... and about 2MB, so be patient).