This is a minimal drop-in replacement for the music functions of SDL2_mixer to be used with the Emscripten compiler. It uses HTML5 <audio> to render music.
emscripten-ports/SDL2_mixer is a WebAssembly port
that performs all sound decoding in WASM. It pushes samples via emscripten-ports/SDL2
to a Web Audio context for playback.
While this approach ensures the highest parity with native builds, the program is susceptible to dropped samples and playback stutters because music decoding and audio rendering both occur in the main thread.
To reduce processing load, we implement the SDL2_mixer interface to use the browser's native
playback features via
<audio>.
Download this package to a location of your choice.
Specify ./include in your "Include" directories and specify the files within ./src in your sources.
In your compiler and linker flags, specify -s USE_SDL=2. You may use this library concurrently
with SDL Mixer (-s USE_SDL_MIXER=2), but this is not required.
You may shim SDL Mixer's Mix_*() music functions by specifying -DHTML5_MIXER_SHIM_MUSIC in your macro defines.
Support exists to link this library without SDL2, but this is untested. If you wish to try, specify
-DHTML5_MIXER_NO_SDL.
We do not perform any decoding; we merely pass the URL or data buffer to an Audio() instance.
Your audio files must be supported by the user's web browser. For a format compatibility table, see Wikipedia.
Currently, we support a minimal subset of the SDL2_mixer API. See issue #1
for progress.
- Migrate SDL2's sound channel rendering from
ScriptProcessorNodetoAudioWorklet. - Render music via
AudioContext.decodeAudioData(). See:- WebAudio/web-audio-api#1850 -- SharedArrayBuffer source
- WebAudio/web-audio-api#337 -- Streaming partial content
- WebAudio/web-audio-api-v2#61 -- Using WebCodec
- AnthumChris/fetch-stream-audio
- StackOverflow
SDL2_mixerdocumentationSDL_mixer_html5-- Full SDL Mixer with this HTML5 interface
The html5_mixer code is released under MIT License.
This project incorporates code from SDL_mixer_html5 which is released under 3-clause BSD License.