James Le Cuirot to SDL
authorSam Lantinga <slouken@libsdl.org>
Mon, 21 Mar 2011 16:54:59 -0700
changeset 5074b699c9a269d
parent 506 586ae09f8176
child 508 de8e7a4f5936
James Le Cuirot to SDL

Hello everyone,

Attached is a patch to add a FluidSynth backend to SDL_mixer. This
patch has been some time in the making but I now believe it is finally
ready.

If you want to try it, it requires the latest FluidSynth from
Subversion. The patch was created against the latest SDL_mixer from
Mercurial but you can apply it against 1.2.11 while safely ignoring the
Makefile.in conflict. Don't forget to run ./autogen.sh. I have tested
that it works under 64-bit Linux and have tested that it builds under
32-bit MSVC 2010. I wasn't able to actually run it under Windows due to
audio issues I'm having with QEMU at the moment but I'm confident that
it'll work.

Unlike Timidity, FluidSynth isn't usually distributed with any sounds
so you either have to set the SDL_SOUNDFONTS environment variable to
some path or the game can call Mix_SetSoundFonts. The latter takes
priority but if you want to override it, set SDL_FORCE_SOUNDFONTS to 1.

You probably won't need to but you can specify more than one SoundFont
file at a time, concatenating them with ; on Windows or : on Linux. To
prevent confusion, ; will also work on Linux but it needs to be quoted
on the command line, which is why : is preferred.

Since FluidSynth requires some conditions to be met while Timidity
doesn't, FluidSynth is attempted first. It will fall back to Timidity
if no SoundFonts are requested by either method or if the requested
SoundFont files are not accessible.

Because the backend is determined when Mix_OpenAudio is called,
Mix_SetSoundFonts needs to be called before this. You can call it again
to change the SoundFonts later but by this time, it's too late to fall
back to Timidity so if the given SoundFonts don't work for any reason,
you'll just get silence! I have considered whether it would be better
to determine the backend on each song load instead but there doesn't
seem to be a strong need for it.

Mix_SetSoundFonts (as well as Mix_GetSoundFonts and Mix_EachSoundFont)
are intended to be generic functions in case the other MIDI backends
ever add support for SoundFonts. You can therefore use them without
worrying whether the user has enabled FluidSynth support or not.

Like the other external dependencies, I have made it possible to load
FluidSynth dynamically. I was able to use a macro to greatly shorten
the code needed to do this. It works really well and could be applied
to the other dependencies so take a look.

I have included the necessary changes to the project files in the
VisualC directory but I decided not to pollute the patch with the
FluidSynth DLL and headers so these will need to be added in the same
manner as the other dependencies.

Even though the required FluidSynth code hasn't yet been put into a
release, it should be safe to merge this patch now because configure
specifically checks for the new function (fluid_player_add_mem) that
makes this work.

I think that covers everything. Feedback and suggestions welcome. :)

Cheers,
James
CHANGES
     1.1 --- a/CHANGES	Sun Mar 20 14:34:18 2011 +0000
     1.2 +++ b/CHANGES	Mon Mar 21 16:54:59 2011 -0700
     1.3 @@ -1,4 +1,6 @@
     1.4  1.2.12:
     1.5 +James Le Cuirot - Mon Mar 21 16:54:11 PDT 2011
     1.6 + * Added support for FluidSynth
     1.7  Scott MC - Tue Jan 18 11:06:47 PST 2011
     1.8   * Added support for native MIDI on Haiku OS
     1.9  Jon Atkins - Sat Nov 14 13:00:18 PST 2009