Skip to content

Commit 4fd1e33

Browse files
committed
Add FluidSynth backend and generic SoundFont functions. No FluidSynth DLL or headers for MSVC in this commit.
1 parent 30f5df9 commit 4fd1e33

11 files changed

Lines changed: 701 additions & 26 deletions

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ VERSION_OBJECTS = @VERSION_OBJECTS@
3939
PLAYWAVE_OBJECTS = @PLAYWAVE_OBJECTS@
4040
PLAYMUS_OBJECTS = @PLAYMUS_OBJECTS@
4141

42-
DIST = Android.mk CHANGES COPYING CWProjects.sea.bin MPWmake.sea.bin Makefile.in SDL_mixer.pc.in README SDL_mixer.h SDL_mixer.qpg.in SDL_mixer.spec SDL_mixer.spec.in VisualC.zip Watcom-OS2.zip Xcode.tar.gz acinclude autogen.sh build-scripts configure configure.in dynamic_flac.c dynamic_flac.h dynamic_mod.c dynamic_mod.h dynamic_mp3.c dynamic_mp3.h dynamic_ogg.c dynamic_ogg.h effect_position.c effect_stereoreverse.c effects_internal.c effects_internal.h gcc-fat.sh libmikmod-3.1.12.zip load_aiff.c load_aiff.h load_flac.c load_flac.h load_ogg.c load_ogg.h load_voc.c load_voc.h mixer.c music.c music_cmd.c music_cmd.h music_flac.c music_flac.h music_mad.c music_mad.h music_mod.c music_mod.h music_modplug.c music_modplug.h music_ogg.c music_ogg.h native_midi native_midi_gpl playmus.c playwave.c timidity wavestream.c wavestream.h version.rc
42+
DIST = Android.mk CHANGES COPYING CWProjects.sea.bin MPWmake.sea.bin Makefile.in SDL_mixer.pc.in README SDL_mixer.h SDL_mixer.qpg.in SDL_mixer.spec SDL_mixer.spec.in VisualC.zip Watcom-OS2.zip Xcode.tar.gz acinclude autogen.sh build-scripts configure configure.in dynamic_flac.c dynamic_flac.h dynamic_fluidsynth.c dynamic_fluidsynth.h dynamic_mod.c dynamic_mod.h dynamic_mp3.c dynamic_mp3.h dynamic_ogg.c dynamic_ogg.h effect_position.c effect_stereoreverse.c effects_internal.c effects_internal.h fluidsynth.c fluidsynth.h gcc-fat.sh libmikmod-3.1.12.zip load_aiff.c load_aiff.h load_flac.c load_flac.h load_ogg.c load_ogg.h load_voc.c load_voc.h mixer.c music.c music_cmd.c music_cmd.h music_flac.c music_flac.h music_mad.c music_mad.h music_mod.c music_mod.h music_modplug.c music_modplug.h music_ogg.c music_ogg.h native_midi native_midi_gpl playmus.c playwave.c timidity wavestream.c wavestream.h version.rc
4343

4444
LT_AGE = @LT_AGE@
4545
LT_CURRENT = @LT_CURRENT@

SDL_mixer.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ extern DECLSPEC const SDL_version * SDLCALL Mix_Linked_Version(void);
6767

6868
typedef enum
6969
{
70-
MIX_INIT_FLAC = 0x00000001,
71-
MIX_INIT_MOD = 0x00000002,
72-
MIX_INIT_MP3 = 0x00000004,
73-
MIX_INIT_OGG = 0x00000008
70+
MIX_INIT_FLAC = 0x00000001,
71+
MIX_INIT_MOD = 0x00000002,
72+
MIX_INIT_MP3 = 0x00000004,
73+
MIX_INIT_OGG = 0x00000008,
74+
MIX_INIT_FLUIDSYNTH = 0x00000016
7475
} MIX_InitFlags;
7576

7677
/* Loads dynamic libraries and prepares them for use. Flags should be
@@ -605,6 +606,11 @@ extern DECLSPEC int SDLCALL Mix_SetMusicCMD(const char *command);
605606
extern DECLSPEC int SDLCALL Mix_SetSynchroValue(int value);
606607
extern DECLSPEC int SDLCALL Mix_GetSynchroValue(void);
607608

609+
/* Set/Get/Iterate SoundFonts paths to use by supported MIDI backends */
610+
extern DECLSPEC int SDLCALL Mix_SetSoundFonts(const char *paths);
611+
extern DECLSPEC const char* SDLCALL Mix_GetSoundFonts();
612+
extern DECLSPEC int SDLCALL Mix_EachSoundFont(int (*function)(const char*, void*), void *data);
613+
608614
/* Get the Mix_Chunk currently associated with a mixer channel
609615
Returns NULL if it's an invalid channel, or there's no chunk associated.
610616
*/

VisualC/SDL_mixer.dsp

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VisualC/SDL_mixer.vcproj

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
Name="VCCLCompilerTool"
4949
AdditionalOptions="/D OGG_DYNAMIC=\"libvorbisfile-3.dll\""
5050
Optimization="0"
51-
AdditionalIncludeDirectories="..\timidity;..\native_midi;mikmod\include;smpeg\include;vorbis\include"
52-
PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;WAV_MUSIC;MOD_MUSIC;MOD_DYNAMIC=\"mikmod.dll\";MID_MUSIC;USE_TIMIDITY_MIDI;USE_NATIVE_MIDI;OGG_MUSIC;OGG_DYNAMIC=\"libvorbisfile-3.dll\";MP3_MUSIC;MP3_DYNAMIC=\"smpeg.dll\""
51+
AdditionalIncludeDirectories="..\timidity;..\native_midi;fluidsynth\include;mikmod\include;smpeg\include;vorbis\include"
52+
PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;WAV_MUSIC;MOD_MUSIC;MOD_DYNAMIC=\"mikmod.dll\";MID_MUSIC;USE_TIMIDITY_MIDI;USE_NATIVE_MIDI;USE_FLUIDSYNTH_MIDI;FLUIDSYNTH_DYNAMIC=\"libfluidsynth.dll\";OGG_MUSIC;OGG_DYNAMIC=\"libvorbisfile-3.dll\";MP3_MUSIC;MP3_DYNAMIC=\"smpeg.dll\""
5353
MinimalRebuild="true"
5454
RuntimeLibrary="2"
5555
PrecompiledHeaderFile=".\Debug/SDL_mixer.pch"
@@ -145,8 +145,8 @@
145145
AdditionalOptions="/D OGG_DYNAMIC=\"libvorbisfile-3.dll\""
146146
Optimization="2"
147147
InlineFunctionExpansion="1"
148-
AdditionalIncludeDirectories="..\timidity;..\native_midi;mikmod\include;smpeg\include;vorbis\include"
149-
PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;WAV_MUSIC;MOD_MUSIC;MID_MUSIC;MOD_DYNAMIC=\"mikmod.dll\";USE_TIMIDITY_MIDI;USE_NATIVE_MIDI;OGG_MUSIC;OGG_DYNAMIC=\"libvorbisfile-3.dll\";MP3_MUSIC;MP3_DYNAMIC=\"smpeg.dll\""
148+
AdditionalIncludeDirectories="..\timidity;..\native_midi;fluidsynth/include;mikmod\include;smpeg\include;vorbis\include"
149+
PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;WAV_MUSIC;MOD_MUSIC;MID_MUSIC;MOD_DYNAMIC=\"mikmod.dll\";USE_TIMIDITY_MIDI;USE_NATIVE_MIDI;USE_FLUIDSYNTH_MIDI;FLUIDSYNTH_DYNAMIC=\"libfluidsynth.dll\";OGG_MUSIC;OGG_DYNAMIC=\"libvorbisfile-3.dll\";MP3_MUSIC;MP3_DYNAMIC=\"smpeg.dll\""
150150
StringPooling="true"
151151
RuntimeLibrary="2"
152152
EnableFunctionLevelLinking="true"
@@ -218,6 +218,14 @@
218218
RelativePath="..\dynamic_flac.h"
219219
>
220220
</File>
221+
<File
222+
RelativePath="..\dynamic_fluidsynth.c"
223+
>
224+
</File>
225+
<File
226+
RelativePath="..\dynamic_fluidsynth.h"
227+
>
228+
</File>
221229
<File
222230
RelativePath="..\dynamic_mod.c"
223231
>
@@ -348,6 +356,14 @@
348356
RelativePath="..\effects_internal.h"
349357
>
350358
</File>
359+
<File
360+
RelativePath="..\fluidsynth.c"
361+
>
362+
</File>
363+
<File
364+
RelativePath="..\fluidsynth.h"
365+
>
366+
</File>
351367
<File
352368
RelativePath="..\load_aiff.c"
353369
>

configure.in

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,49 @@ AC_HELP_STRING([--enable-music-native-midi-gpl], [enable native MIDI on UNIX usi
387387
SOURCES="$SOURCES $srcdir/native_midi_gpl/*.c"
388388
fi
389389
fi
390+
AC_ARG_ENABLE([music-fluidsynth-midi],
391+
AC_HELP_STRING([--enable-music-fluidsynth-midi], [enable FluidSynth MIDI output [[default=yes]]]),
392+
[], [enable_music_fluidsynth_midi=yes])
393+
AC_ARG_ENABLE([music-fluidsynth-shared],
394+
AC_HELP_STRING([--enable-music-fluidsynth-shared], [dynamically load FluidSynth support [[default=yes]]]),
395+
[], [enable_music_fluidsynth_shared=yes])
396+
if test x$enable_music_fluidsynth_midi = xyes; then
397+
AC_CHECK_HEADER([fluidsynth.h], [have_fluidsynth_hdr=yes])
398+
AC_CHECK_LIB([fluidsynth], [fluid_player_add_mem], [have_fluidsynth_lib=yes])
399+
if test x$have_fluidsynth_hdr = xyes -a x$have_fluidsynth_lib = xyes; then
400+
case "$host" in
401+
*-*-darwin*)
402+
fluidsynth_lib=[`find_lib libfluidsynth.dylib`]
403+
if test x$fluidsynth_lib = x; then
404+
fluidsynth_lib=[`find_lib libfluidsynth.[0-9]`]
405+
fi
406+
if test x$fluidsynth_lib = x; then
407+
fluidsynth_lib=[`find_lib libfluidsynth.[0-9]*`]
408+
fi
409+
;;
410+
*-*-cygwin* | *-*-mingw32*)
411+
fluidsynth_lib=[`find_lib "fluidsynth*.dll"`]
412+
;;
413+
*)
414+
fluidsynth_lib=[`find_lib "libfluidsynth.so.[0-9]"`]
415+
if test x$fluidsynth_lib = x; then
416+
fluidsynth_lib=[`find_lib "libfluidsynth.so.[0-9]*"`]
417+
fi
418+
;;
419+
esac
420+
SOURCES="$SOURCES $srcdir/dynamic_fluidsynth.c $srcdir/fluidsynth.c"
421+
EXTRA_CFLAGS="$EXTRA_CFLAGS -DUSE_FLUIDSYNTH_MIDI"
422+
if test x$enable_music_fluidsynth_shared = xyes && test x$fluidsynth_lib != x; then
423+
echo "-- dynamic libfluidsyth -> $fluidsynth_lib"
424+
EXTRA_CFLAGS="$EXTRA_CFLAGS -DFLUIDSYNTH_DYNAMIC=\\\"$fluidsynth_lib\\\""
425+
else
426+
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lfluidsynth"
427+
fi
428+
else
429+
AC_MSG_WARN([*** Unable to find FluidSynth library (http://www.fluidsynth.org/)])
430+
AC_MSG_WARN([FluidSynth support disabled])
431+
fi
432+
fi
390433
fi
391434

392435
AC_ARG_ENABLE([music-ogg],

dynamic_fluidsynth.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
SDL_mixer: An audio mixer library based on the SDL library
3+
Copyright (C) 1997-2011 Sam Lantinga
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Library General Public
7+
License as published by the Free Software Foundation; either
8+
version 2 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Library General Public License for more details.
14+
15+
You should have received a copy of the GNU Library General Public
16+
License along with this library; if not, write to the Free
17+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
19+
James Le Cuirot
20+
chewi@aura-online.co.uk
21+
*/
22+
23+
#ifdef USE_FLUIDSYNTH_MIDI
24+
25+
#include "SDL_loadso.h"
26+
#include "dynamic_fluidsynth.h"
27+
28+
fluidsynth_loader fluidsynth = {
29+
0, NULL
30+
};
31+
32+
#ifdef FLUIDSYNTH_DYNAMIC
33+
#define FLUIDSYNTH_LOADER(FUNC, SIG) \
34+
fluidsynth.FUNC = (SIG) SDL_LoadFunction(fluidsynth.handle, #FUNC); \
35+
if (fluidsynth.FUNC == NULL) { SDL_UnloadObject(fluidsynth.handle); return -1; }
36+
#else
37+
#define FLUIDSYNTH_LOADER(FUNC, SIG) \
38+
fluidsynth.FUNC = FUNC;
39+
#endif
40+
41+
int Mix_InitFluidSynth()
42+
{
43+
if ( fluidsynth.loaded == 0 ) {
44+
#ifdef FLUIDSYNTH_DYNAMIC
45+
fluidsynth.handle = SDL_LoadObject(FLUIDSYNTH_DYNAMIC);
46+
if ( fluidsynth.handle == NULL ) return -1;
47+
#endif
48+
49+
FLUIDSYNTH_LOADER(delete_fluid_player, int (*)(fluid_player_t*));
50+
FLUIDSYNTH_LOADER(delete_fluid_settings, void (*)(fluid_settings_t*));
51+
FLUIDSYNTH_LOADER(delete_fluid_synth, int (*)(fluid_synth_t*));
52+
FLUIDSYNTH_LOADER(fluid_player_add, int (*)(fluid_player_t*, const char*));
53+
FLUIDSYNTH_LOADER(fluid_player_add_mem, int (*)(fluid_player_t*, const void*, size_t));
54+
FLUIDSYNTH_LOADER(fluid_player_get_status, int (*)(fluid_player_t*));
55+
FLUIDSYNTH_LOADER(fluid_player_play, int (*)(fluid_player_t*));
56+
FLUIDSYNTH_LOADER(fluid_player_set_loop, int (*)(fluid_player_t*, int));
57+
FLUIDSYNTH_LOADER(fluid_player_stop, int (*)(fluid_player_t*));
58+
FLUIDSYNTH_LOADER(fluid_settings_setnum, int (*)(fluid_settings_t*, const char*, double));
59+
FLUIDSYNTH_LOADER(fluid_synth_get_settings, fluid_settings_t* (*)(fluid_synth_t*));
60+
FLUIDSYNTH_LOADER(fluid_synth_set_gain, void (*)(fluid_synth_t*, float));
61+
FLUIDSYNTH_LOADER(fluid_synth_sfload, int(*)(fluid_synth_t*, const char*, int));
62+
FLUIDSYNTH_LOADER(fluid_synth_write_s16, int(*)(fluid_synth_t*, int, void*, int, int, void*, int, int));
63+
FLUIDSYNTH_LOADER(new_fluid_player, fluid_player_t* (*)(fluid_synth_t*));
64+
FLUIDSYNTH_LOADER(new_fluid_settings, fluid_settings_t* (*)(void));
65+
FLUIDSYNTH_LOADER(new_fluid_synth, fluid_synth_t* (*)(fluid_settings_t*));
66+
}
67+
++fluidsynth.loaded;
68+
69+
return 0;
70+
}
71+
72+
void Mix_QuitFluidSynth()
73+
{
74+
if ( fluidsynth.loaded == 0 ) {
75+
return;
76+
}
77+
if ( fluidsynth.loaded == 1 ) {
78+
#ifdef FLUIDSYNTH_DYNAMIC
79+
SDL_UnloadObject(fluidsynth.handle);
80+
#endif
81+
}
82+
--fluidsynth.loaded;
83+
}
84+
85+
#endif /* USE_FLUIDSYNTH_MIDI */

dynamic_fluidsynth.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
SDL_mixer: An audio mixer library based on the SDL library
3+
Copyright (C) 1997-2011 Sam Lantinga
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Library General Public
7+
License as published by the Free Software Foundation; either
8+
version 2 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Library General Public License for more details.
14+
15+
You should have received a copy of the GNU Library General Public
16+
License along with this library; if not, write to the Free
17+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
19+
James Le Cuirot
20+
chewi@aura-online.co.uk
21+
*/
22+
23+
#ifdef USE_FLUIDSYNTH_MIDI
24+
25+
#include <fluidsynth.h>
26+
27+
typedef struct {
28+
int loaded;
29+
void *handle;
30+
31+
int (*delete_fluid_player)(fluid_player_t*);
32+
void (*delete_fluid_settings)(fluid_settings_t*);
33+
int (*delete_fluid_synth)(fluid_synth_t*);
34+
int (*fluid_player_add)(fluid_player_t*, const char*);
35+
int (*fluid_player_add_mem)(fluid_player_t*, const void*, size_t);
36+
int (*fluid_player_get_status)(fluid_player_t*);
37+
int (*fluid_player_play)(fluid_player_t*);
38+
int (*fluid_player_set_loop)(fluid_player_t*, int);
39+
int (*fluid_player_stop)(fluid_player_t*);
40+
int (*fluid_settings_setnum)(fluid_settings_t*, const char*, double);
41+
fluid_settings_t* (*fluid_synth_get_settings)(fluid_synth_t*);
42+
void (*fluid_synth_set_gain)(fluid_synth_t*, float);
43+
int (*fluid_synth_sfload)(fluid_synth_t*, const char*, int);
44+
int (*fluid_synth_write_s16)(fluid_synth_t*, int, void*, int, int, void*, int, int);
45+
fluid_player_t* (*new_fluid_player)(fluid_synth_t*);
46+
fluid_settings_t* (*new_fluid_settings)(void);
47+
fluid_synth_t* (*new_fluid_synth)(fluid_settings_t*);
48+
} fluidsynth_loader;
49+
50+
extern fluidsynth_loader fluidsynth;
51+
52+
#endif /* USE_FLUIDSYNTH_MIDI */
53+
54+
extern int Mix_InitFluidSynth();
55+
extern void Mix_QuitFluidSynth();

0 commit comments

Comments
 (0)