Skip to content
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

SDL2_Mixer failed to initialize in MIDI format even has specified SDL2_MIXER_FORMATS=wav,mid #21008

Closed
ChinYikMing opened this issue Jan 4, 2024 · 4 comments

Comments

@ChinYikMing
Copy link

ChinYikMing commented Jan 4, 2024

Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.46 (1960782)

emcc CFLAGS

-sSDL2_MIXER_FORMATS=wav,mid \
-sUSE_SDL_MIXER=2

Error when SDL2_Mixer is initializing in MIDI format

Mix_Init failed: MIDI support not available

Upon examining the SDL2_Mixer source code, I discovered that the primary cause might be that one of the following interfaces is not initialized in array s_music_interfaces(source):

#ifdef MUSIC_MID_FLUIDSYNTH
    &Mix_MusicInterface_FLUIDSYNTH,
#endif
#ifdef MUSIC_MID_TIMIDITY
    &Mix_MusicInterface_TIMIDITY,
#endif
#ifdef MUSIC_MID_NATIVE
    &Mix_MusicInterface_NATIVEMIDI,
#endif

Therefore, the three MIDI music interfaces described above are not accessed when the load_music_type function is executed.

I think defining one of the macros MUSIC_MID_TIMIDITY, MUSIC_MID_NATIVE, or MUSIC_MID_FLUIDSYNTH could be the solution. Since I can't find any documentation about any of them, may I know how to define one of them when building my own project (for example, defined them in emcc's CFLAGS)? Or perhaps there is another way to handle this?

@ChinYikMing
Copy link
Author

ChinYikMing commented Jan 4, 2024

I found this port tool has defined MUSIC_MID_TIMIDITY.

@ChinYikMing
Copy link
Author

ChinYikMing commented Jan 4, 2024

Also, I have mounted the GUS patches mentioned in this README at "/etc/timidity"

emcc's CFLAGS:

--embed-file build/timidity@/etc/timidity

@ChinYikMing
Copy link
Author

I think the issue is related to PR (#16556)

@ChinYikMing ChinYikMing changed the title SDL2_Mixer failed to initialize in MIDI format even has specified SDL2_MIXER_FORMATS=[wav,mid] SDL2_Mixer failed to initialize in MIDI format even has specified SDL2_MIXER_FORMATS=wav,mid Jan 5, 2024
@ChinYikMing
Copy link
Author

I've worked out the solution, which is that the following build flags need to be passed during the executable's linking phase so that the project can link the ported SDL_Mixer library. Originally, the build process of my project involved building many object files and then linking them together, however I missed to link the ported SDL_Mixer library.

emcc build flags:

-sSDL2_MIXER_FORMATS=wav,mid \
-sUSE_SDL_MIXER=2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant