@@ -72,6 +72,7 @@ typedef struct FLUIDSYNTH_AudioData
7272{
7373 const Uint8 * sfdata ;
7474 size_t sfdatalen ;
75+ SDL_PropertiesID fluidsynth_props ;
7576} FLUIDSYNTH_AudioData ;
7677
7778typedef struct FLUIDSYNTH_TrackData
@@ -170,6 +171,19 @@ static bool SDLCALL FLUIDSYNTH_init_audio(SDL_IOStream *io, SDL_AudioSpec *spec,
170171 * duration_frames = -1 ; // !!! FIXME: fluid_player_get_total_ticks can give us a time duration, but we don't have a player until we set up the track later.
171172 * audio_userdata = adata ;
172173
174+ const SDL_PropertiesID fluidsynth_props = (SDL_PropertiesID ) SDL_GetNumberProperty (props , MIX_PROP_DECODER_FLUIDSYNTH_PROPS_NUMBER , 0 );
175+ if (fluidsynth_props ) {
176+ adata -> fluidsynth_props = SDL_CreateProperties ();
177+ if (!adata -> fluidsynth_props || !SDL_CopyProperties (fluidsynth_props , adata -> fluidsynth_props )) {
178+ if (adata -> fluidsynth_props ) {
179+ SDL_DestroyProperties (adata -> fluidsynth_props );
180+ }
181+ SDL_free (sfdata );
182+ SDL_free (adata );
183+ return false;
184+ }
185+ }
186+
173187 return true;
174188}
175189
@@ -211,6 +225,19 @@ static fluid_long_long_t SoundFontTell(void *handle)
211225 return SDL_TellIO ((SDL_IOStream * ) handle );
212226}
213227
228+ static void SDLCALL SetCustomFluidsynthProperties (void * userdata , SDL_PropertiesID props , const char * name )
229+ {
230+ FLUIDSYNTH_TrackData * tdata = (FLUIDSYNTH_TrackData * ) userdata ;
231+ switch (SDL_GetPropertyType (props , name )) {
232+ case SDL_PROPERTY_TYPE_NUMBER :
233+ fluidsynth .fluid_settings_setint (tdata -> settings , name , (int ) SDL_GetNumberProperty (props , name , 0 ));
234+ break ;
235+ case SDL_PROPERTY_TYPE_FLOAT :
236+ fluidsynth .fluid_settings_setnum (tdata -> settings , name , (double ) SDL_GetFloatProperty (props , name , 0.0f ));
237+ break ;
238+ default : break ; // oh well.
239+ }
240+ }
214241
215242static bool SDLCALL FLUIDSYNTH_init_track (void * audio_userdata , SDL_IOStream * io , const SDL_AudioSpec * spec , SDL_PropertiesID props , void * * track_userdata )
216243{
@@ -236,6 +263,9 @@ static bool SDLCALL FLUIDSYNTH_init_track(void *audio_userdata, SDL_IOStream *io
236263 fluidsynth .fluid_settings_setnum (tdata -> settings , "synth.sample-rate" , (double ) spec -> freq );
237264 fluidsynth .fluid_settings_getnum (tdata -> settings , "synth.sample-rate" , & samplerate );
238265
266+ // let custom properties override anything we already set internally. You break it, you buy it!
267+ SDL_EnumerateProperties (adata -> fluidsynth_props , SetCustomFluidsynthProperties , tdata );
268+
239269 tdata -> synth = fluidsynth .new_fluid_synth (tdata -> settings );
240270 if (!tdata -> synth ) {
241271 SDL_SetError ("Failed to create FluidSynth synthesizer" );
@@ -361,6 +391,7 @@ static void SDLCALL FLUIDSYNTH_quit_track(void *track_userdata)
361391static void SDLCALL FLUIDSYNTH_quit_audio (void * audio_userdata )
362392{
363393 FLUIDSYNTH_AudioData * adata = (FLUIDSYNTH_AudioData * ) audio_userdata ;
394+ SDL_DestroyProperties (adata -> fluidsynth_props );
364395 SDL_free ((void * ) adata -> sfdata );
365396 SDL_free (adata );
366397}
0 commit comments