New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SDL_mixer 2? #3985
Comments
Actually you can build SDL2_mixer without the plugins from source just as you would any other library. To support the mp3 or mod plugins you would need support from libmpeg and libmodplug for emscripten (I don't know whether such exist) To add ogg support you can use the ogg and vorbis ports by adding |
You actually may use all SDL_mixer dependencies, it works as expected. Update: the following patches are not needed anymore with SDL 2.0.7 and SDL_mixer 2.0.2. If you want to make MIDI music (internal timidity) and tracker music (libmodplug) work in emscripten, you need to patch SDL2_mixer because timidity and libmodplug drivers in SDL2_mixer don't support 32 bit device mixing (used by Web Audio). Here is the new proposed custom #ifdef EMSCRIPTEN
// Note: this requires a patched SDL_mixer currently
Mix_OpenAudioDevice(NULL, 0, frequency, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE);
#else
Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096)
#endif Another trick: to prevent noise when using wav and ogg, don't use Mix_PlayMus() because it is buggy, use Mix_PlayChannel() in the meanwhile. Final suggestion: to prevent resampling buffering issues (choppy audio) due to another (SDL2?) bug, you should also patch the audio initialization to get the native browser frequency, e.g.: #if EMSCRIPTEN
# include <emscripten.h>
#endif
// (...)
#if EMSCRIPTEN
int const frequency = EM_ASM_INT_V({
var context;
try {
context = new AudioContext();
} catch (e) {
context = new webkitAudioContext();
}
return context.sampleRate;
});
#else
int const frequency = 44100;
#endif |
Thanks for the hints @fdelapena! Do you have SDL2_mixer already compiled? Could you maybe provide the binaries? |
We have an automated toolchain with generated .a static files, you might need to rename needed .a to .bc (bitcode) to make them work with Here is the relevant part of our automated build script of SDL2 and SDL2_mixer for Emscripten. By the way, if you want to play midi files you need to include GUS patches for timidity support and embed them in the dat file. |
SDL_mixer from Hg just added Mix_OpenAudioDevice at https://hg.libsdl.org/SDL_mixer/rev/fb0562cc1559 so you don't need to patch SDL_mixer anymore with the current Mercurial version 👍. |
I tried builidng my game. But when running it, it fails when using Mix_LoadWAV_RW |
@Fighter19 i had the same problem. |
I try to convert the rust application to wasm. Acutually I also want to use the buildscript. |
Hi, |
Sorry. I missed it. |
By the way, with SDL 2.0.7 and SDL_mixer 2.0.2 have been released, the patch I suggested is not needed anymore, the noise resampling issue has been fixed too, it should work nicely out of the box with Update: I've updated the CI link to our toolchain build job. |
So, is there a way to include |
I've made a PR for an initial iteration of SDL2_mixer at #5995 (the test uses the sample detection trick, thanks @fdelapena) It's pretty rough and is intended as a first attempt for people who actually care about audio to create new PRs on top of - I only built mixer in the first place because it was easier than ripping it out of the program I was porting to emscripten :) The PR currently:
|
Fixed by #7599, we now have SDL2_mixer in ports thanks to @aidanhs and @superzazu! |
@kripken I'm still getting an error saying that the include file for
|
@lherman-cs Just copy SDL2/SDL_mixer.h to your include directory. |
@hyp1 yes, I know that I can do that. But, isn't it a lot nicer if the script already provides that automatically, like it does for SDL_image? |
@lherman-cs What script do you mean by install SDL_Image automaticly. |
@hyp1 if you asked which script that caused it, I haven't had a chance to read the code that's responsible for this. So, I can't exactly tell you where. But, if you asked for what script that I ran, it's the I'm using a custom docker image that is based on https://hub.docker.com/r/trzeci/emscripten/ with |
@lherman-cs ah ok. |
Can you post the full compiler command and the full output. Certainly looks like bug but I need more info to reproduce it. |
@sbc100 This is the script for compiling, https://github.com/lherman-cs/cs4160/blob/develop/assignment-4/build-wasm.sh. Note: in This my I'll post the full output as soon as I get home. |
@sbc100 alright, here we go. This is the full output, which is apparently I've posted already... haha
|
Can you post the failing command line? The lines regarding generating the port should only show up the first time its generated.. can you verify that you don't see those lines when you run the command line for a second time? Also it looks like the correct way to include that file is either |
@sbc100 I'm sorry. I was just experimenting with the include path. It should be I'm sorry. I misunderstood what you're asking for before. Following is the output from the first time I ran the script:
|
So it looks like the embuilder command works fine? But your errors seem to be coming from a file called Perhaps I'm misunderstanding and its the embuilder command thats actually failing? |
I'm not sure. I thought that it was coming from embuilder for not properly setting up the sdl2_mixer. As far as I know, there's a system setting that you can set so that, by default, it'll include some folders, like in gcc, you can see the list with Yes, I'm using unity build, which is basically to speed up my compilation time and make it easy to create the makefile (I don't like cmake). This is the script that I run to build my project: #!/bin/bash
SRCS=`ls src/**/unity.cpp`
CXXFLAGS=(-O3 -std=c++17 -Iinclude -I/vendor/include/expat)
LDFLAGS=(-L/vendor/lib/expat -lexpat)
EMFLAGS=(
-s TOTAL_MEMORY=1GB
-s USE_SDL=2
-s USE_SDL_TTF=2
-s USE_SDL_IMAGE=2
-s USE_SDL_MIXER=2
-s SDL2_IMAGE_FORMATS='["bmp","png"]'
--preload-file assets
--closure 1
--shell-file ./wasm-template.html
)
FLAGS="${CXXFLAGS[@]} ${LDFLAGS[@]} ${EMFLAGS[@]}"
CONFIG=./assets/config.xml
# Turn frameCap for wasm because wasm already has its own frameCap
sed -i 's\<frameCapOn>true</frameCapOn>\<frameCapOn>false</frameCapOn>\g' ${CONFIG}
if [[ -z ${CI} ]]; then
docker run -e EMCC_DEBUG=1 --rm -v ${PWD}:/src lherman/sdl emcc -o index.html ${FLAGS[@]} ${SRCS[@]}
else
emcc -o index.html ${FLAGS[@]} ${SRCS[@]}
fi
# Turn the frameCap back on
sed -i 's\<frameCapOn>false</frameCapOn>\<frameCapOn>true</frameCapOn>\g' ${CONFIG}
Here is the output when |
So your sdl2_mixer include path is correctly being passed clang as we can see in your log: Might be worth checking that the headers do actaully exist in: If they don't then perhaps your cache somehow corrupted and that running |
So, as you suggested, I went ahead and cleared the cache by But, this seems strange because I'm using docker and I've tried to recompile my docker image multiple times and still gave the same result. |
In current version of emscripten (using emsdk-portable with 1.38.31), SDL2_mixer build without OGG support.
It seems it needs (It seems the included configure tries to link with |
Hi,
has there been an attempt to port SDL_mixer 2? It seams like SDL_mixer 1.2 is embedded but does rely one the browser to do the decoding (just like SDL 1 is embedded but the SDL 2 port is far more advanced)
-- ooxi
The text was updated successfully, but these errors were encountered: