GME with SDL_mixer?

Issue #3 resolved
Daniël Polders created an issue

Hi! (I have also posted this on the old google-groups forum)

I'm not sure if anyone still reads these posts, but I hope someone can give me some advice on this.

I am trying to implement GME in an SDL progam. Because I rather not mess with resampling, mixing and device selection myself, I was thinking of including SDL_mixer to the program. This will give me MP3, midi, ogg support right out of the box. I am not quite sure how to include GME in this though. SDL_mixer allows an external executable to be called for non-supported music formats, but that will break any filters stuff that SDL_mixer can supply, and probably wont support track selection / information retrieval that GME can give me. So, what would you advice?

Is there a better way to hook GME into SDL_mixer, other than having SDL_mixer call a custom GME excecutable? Alternatively, is is worth it to try and write my own mixer, or should I try and reverse engineer maybe this repo: http://wohlsoft.ru/pgewiki/SDL2_mixer ?

Thanks for any pointers, remarks, comments you might have for me!

Comments (10)

  1. Michael Pyne repo owner

    While I'm not familiar with SDL_mixer itself, I would assume it has some sort of interface that would allow an application to manually stream raw audio data through it.

    That is how I would recommend using GME --> handle files within GME, decode the audio to raw audio data, and then feed those audio samples into SDL_mixer to complete the rest of the audio processing pipeline.

  2. Daniël Polders reporter

    Hey Michael, thanks for taking the time to respond my out-of-the-blue (not-really-an) issue. I think your advice is sound. I will further investigate to see how to make it happen.

    Thanks again, Daniel

  3. Wohlstand Account Deactivated

    Hi, it's my fork of SDL Mixer I made for my game engine project, the GME is added by me, and I also made the libADLMIDI library from the code of ADLMIDI console tool, and also included it into my SDL Mixer fork. Also, I have added loop tags for OGG files support that can be used. Reasons of why I forked it was some weird bugs in it while processing audio, and my wish to extend it with extra codecs and I even have some other features plans in this library, for example, implement multi-music to have ability make streaming SFXes like street wind, together with a music, and have the way to cross-fade.

    Source code of my fork is here: https://github.com/WohlSoft/SDL-Mixer-X/ for now, it's part of my game engine, but to give able use it with other projects, I'll move it with all its dependencies into separated repository as sub-module, and I'll add CMake support (for now QMake is used to build the library)

    So yeah, if you going to implement own codec, you have to implement it into SDL Mixer directly

    EDIT 26 of June, 2018: Long time, SDL Mixer X now have own repository and now is well build-able through CMake (it used AudioCodecs repository as source of dependencies are all building on the fly as static libraries and linking to final SDL Mixer X binary if it is shared library, otherwise if you gonna link SDL Mixer X statically, you also need to link all those dependencies too)

  4. Daniël Polders reporter

    Hi! Talk about a coincidence! I was just re-considering this issue last week, after letting it rest for about 8 months. And now you come with this wonderful reply! I'm afraid I did not understand all you explained, but I am glad to at least get a conversation going on this. Some background, I am working on the EmulationStation frontend for the Retropie project, which turns a Raspberry-pi into a full-fledged retro-gaming computer. Emulationstation is written within the SDL framework, and as you can imagine, to be able to play old-school chiptunes natively would be a match made in heaven.

    In any case, my experience with both SDL and GME is very limited, but I am willing to learn! My next step is to have a look at your repo, to see how much I can grok.

  5. Wohlstand Account Deactivated

    You can even look to my engine yourself, there are examples (a component of my entire project) which are using the library:

    • PGE Editor - to play music and sounds like in game (much better than QMediaPlayer which I had to try in early state)
    • PGE Engine - the game engine part, recently it was a mix Qt and SDL, but I completely removed Qt dependency and had lot of works to make pure-STL app and having some wonderful Qt features in STL: I made IniProcessing, DirMan, Utils:: and SdlFile, and I even ported QtTranslator core into pure STL to be able to use qm-files. It widely used SDL Mixer to play game music (there are also libADLMIDI to play MIDI files through OPL3 emulator, and I even implemented ability to toggle MIDI sequencers in real time (ADLMIDI, Timidity, NativeMidi and FluidSynth) which is impossible from original SDL Mixer, and also I have added ability Timidity to receive custom bank path (for example, application directory or config pack folder) to don't stuck on C:\Timidity)
    • PGE MusPlay - I have made it for a convenient testing of music with it before including them into a game, without necessary to start entire editor or engine.

    In all applications, I have the dedicated CPP file where I in most managing a library's features, but sometimes I can call SDL Mixer's functions in other places. The different is including of SDL_mixer_ext.h instead of SDL_mixer.h, and other ways are same as original library

  6. Wohlstand Account Deactivated

    P.S. GME I used in SDL Mixer X is a bit modified:

    • Added in-memory ZLib decompression to support VGZ in the memory
    • Fixed some warnings in the code I think I'll try to merge that with your latest changes and will try to send pull request to you.
  7. Former user Account Deleted

    You don't need to modify SDL_Mixer or GME to use them together. The SDL music player in the GME repo demonstrates how to get things working using audio callbacks. Using SDL_Mixer it would look a bit different, but the callback itself looks the same. It just needs to be hooked using Mix_HookMusic instead of with SDL_OpenAudio and SDL_AudioSpecs.

    I used GME with SDL_Mixer for a (now cancelled) Mega Man fangame last year. Here's the code I did it with. It's kind of ugly and in Cython rather than C or C++, but I think it gets the point across.

  8. Wohlstand Account Deactivated

    Yeah, I see, that right to use Mix_HookMusic to don't modify SDL Mixer itself, and SDL_OpenAudio just opens separated audio stream that is unneeded.

    I did modify SDL Mixer by reason to make it be more advanced than now and fix existing bugs and disadvantages of it.

  9. Wohlstand Account Deactivated

    I guess, this can be closed, because:
    - Official SDL Mixer accepted the update that adds native support of libGME.
    - My fork of SDL Mixer, called MixerX, uses the libGME for a while.

  10. Log in to comment