libgme / game-music-emu

Blargg's video game music emulation library, which allows audio applications to easily add playback support for the music of many classic video game consoles.
GNU Lesser General Public License v2.1
79 stars 16 forks source link

GME with SDL_mixer? #5

Closed Wohlstand closed 1 year ago

Wohlstand commented 8 years ago

Original report by Daniël Polders (Bitbucket: zigurana, GitHub: zigurana).


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!

Wohlstand commented 8 years ago

Original comment by Michael Pyne (Bitbucket: mpyne, GitHub: mpyne).


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.

Wohlstand commented 8 years ago

Original comment by Daniël Polders (Bitbucket: zigurana, GitHub: zigurana).


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

Wohlstand commented 7 years ago

Original comment by Wohlstand (Bitbucket: Wohlstand, GitHub: Wohlstand).


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)

Wohlstand commented 7 years ago

Original comment by Daniël Polders (Bitbucket: zigurana, GitHub: zigurana).


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.

Wohlstand commented 7 years ago

Original comment by Wohlstand (Bitbucket: Wohlstand, GitHub: Wohlstand).


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

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

Wohlstand commented 7 years ago

Original comment by Wohlstand (Bitbucket: Wohlstand, GitHub: Wohlstand).


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

Wohlstand commented 7 years ago

Original comment by Former user (Bitbucket: [Former user](https://bitbucket.org/Former user), ).


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.

Wohlstand commented 7 years ago

Original comment by Wohlstand (Bitbucket: Wohlstand, GitHub: Wohlstand).


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.

Wohlstand commented 1 year ago

I guess, this can be closed, because: