Web Worker to decode MP3 files
Web Audio includes support for decoding audio via decodeAudioData()
; however, this doesn't work for all formats on all operating systems.
In our case, MP3 files failed to decode on the following configurations:
- Opera on Windows Vista and Windows 7 (possibly others)
- Firefox on Linux
- Various Android devices (including all Kindle Fire tablets)
To solve this, we compiled lieff's minimp3 project with Emscripten and added a small abstraction layer. Previous versions of mp3worker used Martin J. Fiedler's minimp3 project.
The source
directory contains a small Xcode project used to build the first abstraction layer. From there:
- We ran
emcc -Oz --memory-init-file 0 -s WASM=0 -s EXPORTED_FUNCTIONS=_mp3_init,_mp3_decode mp3worker.c
- We copied a portion of
a.out.js
intomp3worker.js
- We added an additional abstraction layer for a cleaner interface
See example in index.html.
mp3worker.js
and all files are dedicated to the public domain.
/*
* mp3worker
* https://github.com/musictheory/mp3worker/
*
* Based on minimp3
* https://github.com/lieff/minimp3
*
* Dedicated to the public domain
* https://creativecommons.org/publicdomain/zero/1.0/
*/