From 152fb395f59a8123e4b7febcb59d674f76cdd3ea Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 12:38:44 +0200 Subject: [PATCH 01/17] Optimized fluid_commands[] --- src/bindings/fluid_cmd.c | 155 +++++++++++++++++++++------------------ 1 file changed, 85 insertions(+), 70 deletions(-) diff --git a/src/bindings/fluid_cmd.c b/src/bindings/fluid_cmd.c index 4128f76f..0ea37ae9 100644 --- a/src/bindings/fluid_cmd.c +++ b/src/bindings/fluid_cmd.c @@ -59,6 +59,17 @@ struct _fluid_shell_t { fluid_ostream_t out; }; +/** + * Reduced command information structure for constant data. + * For internal use only. + */ +typedef struct { + const char *name; /**< The name of the command, as typed in the shell */ + const char *topic; /**< The help topic group of this command */ + fluid_cmd_func_t handler; /**< Pointer to the handler for this command */ + const char *help; /**< A help string */ +} fluid_cmd_int_t; + static int fluid_shell_run(fluid_shell_t* shell); static void fluid_shell_init(fluid_shell_t* shell, fluid_settings_t* settings, fluid_cmd_handler_t* handler, @@ -75,122 +86,121 @@ void fluid_shell_settings(fluid_settings_t* settings) /** the table of all handled commands */ -static fluid_cmd_t fluid_commands[] = { - { "help", "general", (fluid_cmd_func_t) fluid_handle_help, NULL, +static const fluid_cmd_int_t fluid_commands[] = { + { "help", "general", (fluid_cmd_func_t) fluid_handle_help, "help Show help topics ('help TOPIC' for more info)" }, - { "quit", "general", (fluid_cmd_func_t) fluid_handle_quit, NULL, + { "quit", "general", (fluid_cmd_func_t) fluid_handle_quit, "quit Quit the synthesizer" }, - { "source", "general", (fluid_cmd_func_t) fluid_handle_source, NULL, + { "source", "general", (fluid_cmd_func_t) fluid_handle_source, "source filename Load a file and parse every line as a command" }, - { "noteon", "event", (fluid_cmd_func_t) fluid_handle_noteon, NULL, + { "noteon", "event", (fluid_cmd_func_t) fluid_handle_noteon, "noteon chan key vel Send noteon" }, - { "noteoff", "event", (fluid_cmd_func_t) fluid_handle_noteoff, NULL, + { "noteoff", "event", (fluid_cmd_func_t) fluid_handle_noteoff, "noteoff chan key Send noteoff" }, - { "pitch_bend", "event", (fluid_cmd_func_t) fluid_handle_pitch_bend, NULL, + { "pitch_bend", "event", (fluid_cmd_func_t) fluid_handle_pitch_bend, "pitch_bend chan offset Bend pitch" }, - { "pitch_bend_range", "event", (fluid_cmd_func_t) fluid_handle_pitch_bend_range, NULL, + { "pitch_bend_range", "event", (fluid_cmd_func_t) fluid_handle_pitch_bend_range, "pitch_bend chan range Set bend pitch range" }, - { "cc", "event", (fluid_cmd_func_t) fluid_handle_cc, NULL, + { "cc", "event", (fluid_cmd_func_t) fluid_handle_cc, "cc chan ctrl value Send control-change message" }, - { "prog", "event", (fluid_cmd_func_t) fluid_handle_prog, NULL, + { "prog", "event", (fluid_cmd_func_t) fluid_handle_prog, "prog chan num Send program-change message" }, - { "select", "event", (fluid_cmd_func_t) fluid_handle_select, NULL, + { "select", "event", (fluid_cmd_func_t) fluid_handle_select, "select chan sfont bank prog Combination of bank-select and program-change" }, - { "load", "general", (fluid_cmd_func_t) fluid_handle_load, NULL, + { "load", "general", (fluid_cmd_func_t) fluid_handle_load, "load file [reset] [bankofs] Load SoundFont (reset=0|1, def 1; bankofs=n, def 0)" }, - { "unload", "general", (fluid_cmd_func_t) fluid_handle_unload, NULL, + { "unload", "general", (fluid_cmd_func_t) fluid_handle_unload, "unload id [reset] Unload SoundFont by ID (reset=0|1, default 1)"}, - { "reload", "general", (fluid_cmd_func_t) fluid_handle_reload, NULL, + { "reload", "general", (fluid_cmd_func_t) fluid_handle_reload, "reload id Reload the SoundFont with the specified ID" }, - { "fonts", "general", (fluid_cmd_func_t) fluid_handle_fonts, NULL, + { "fonts", "general", (fluid_cmd_func_t) fluid_handle_fonts, "fonts Display the list of loaded SoundFonts" }, - { "inst", "general", (fluid_cmd_func_t) fluid_handle_inst, NULL, + { "inst", "general", (fluid_cmd_func_t) fluid_handle_inst, "inst font Print out the available instruments for the font" }, - { "channels", "general", (fluid_cmd_func_t) fluid_handle_channels, NULL, + { "channels", "general", (fluid_cmd_func_t) fluid_handle_channels, "channels [-verbose] Print out preset of all channels" }, - { "interp", "general", (fluid_cmd_func_t) fluid_handle_interp, NULL, + { "interp", "general", (fluid_cmd_func_t) fluid_handle_interp, "interp num Choose interpolation method for all channels" }, - { "interpc", "general", (fluid_cmd_func_t) fluid_handle_interpc, NULL, + { "interpc", "general", (fluid_cmd_func_t) fluid_handle_interpc, "interpc chan num Choose interpolation method for one channel" }, - { "rev_preset", "reverb", (fluid_cmd_func_t) fluid_handle_reverbpreset, NULL, + { "rev_preset", "reverb", (fluid_cmd_func_t) fluid_handle_reverbpreset, "rev_preset num Load preset num into the reverb unit" }, - { "rev_setroomsize", "reverb", (fluid_cmd_func_t) fluid_handle_reverbsetroomsize, NULL, + { "rev_setroomsize", "reverb", (fluid_cmd_func_t) fluid_handle_reverbsetroomsize, "rev_setroomsize num Change reverb room size" }, - { "rev_setdamp", "reverb", (fluid_cmd_func_t) fluid_handle_reverbsetdamp, NULL, + { "rev_setdamp", "reverb", (fluid_cmd_func_t) fluid_handle_reverbsetdamp, "rev_setdamp num Change reverb damping" }, - { "rev_setwidth", "reverb", (fluid_cmd_func_t) fluid_handle_reverbsetwidth, NULL, + { "rev_setwidth", "reverb", (fluid_cmd_func_t) fluid_handle_reverbsetwidth, "rev_setwidth num Change reverb width" }, - { "rev_setlevel", "reverb", (fluid_cmd_func_t) fluid_handle_reverbsetlevel, NULL, + { "rev_setlevel", "reverb", (fluid_cmd_func_t) fluid_handle_reverbsetlevel, "rev_setlevel num Change reverb level" }, - { "reverb", "reverb", (fluid_cmd_func_t) fluid_handle_reverb, NULL, + { "reverb", "reverb", (fluid_cmd_func_t) fluid_handle_reverb, "reverb [0|1|on|off] Turn the reverb on or off" }, - { "cho_set_nr", "chorus", (fluid_cmd_func_t) fluid_handle_chorusnr, NULL, + { "cho_set_nr", "chorus", (fluid_cmd_func_t) fluid_handle_chorusnr, "cho_set_nr n Use n delay lines (default 3)" }, - { "cho_set_level", "chorus", (fluid_cmd_func_t) fluid_handle_choruslevel, NULL, + { "cho_set_level", "chorus", (fluid_cmd_func_t) fluid_handle_choruslevel, "cho_set_level num Set output level of each chorus line to num" }, - { "cho_set_speed", "chorus", (fluid_cmd_func_t) fluid_handle_chorusspeed, NULL, + { "cho_set_speed", "chorus", (fluid_cmd_func_t) fluid_handle_chorusspeed, "cho_set_speed num Set mod speed of chorus to num (Hz)" }, - { "cho_set_depth", "chorus", (fluid_cmd_func_t) fluid_handle_chorusdepth, NULL, + { "cho_set_depth", "chorus", (fluid_cmd_func_t) fluid_handle_chorusdepth, "cho_set_depth num Set chorus modulation depth to num (ms)" }, - { "chorus", "chorus", (fluid_cmd_func_t) fluid_handle_chorus, NULL, + { "chorus", "chorus", (fluid_cmd_func_t) fluid_handle_chorus, "chorus [0|1|on|off] Turn the chorus on or off" }, - { "gain", "general", (fluid_cmd_func_t) fluid_handle_gain, NULL, + { "gain", "general", (fluid_cmd_func_t) fluid_handle_gain, "gain value Set the master gain (0 < gain < 5)" }, - { "voice_count", "general", (fluid_cmd_func_t) fluid_handle_voice_count, NULL, + { "voice_count", "general", (fluid_cmd_func_t) fluid_handle_voice_count, "voice_count Get number of active synthesis voices" }, - { "tuning", "tuning", (fluid_cmd_func_t) fluid_handle_tuning, NULL, + { "tuning", "tuning", (fluid_cmd_func_t) fluid_handle_tuning, "tuning name bank prog Create a tuning with name, bank number, \n" " and program number (0 <= bank,prog <= 127)" }, - { "tune", "tuning", (fluid_cmd_func_t) fluid_handle_tune, NULL, + { "tune", "tuning", (fluid_cmd_func_t) fluid_handle_tune, "tune bank prog key pitch Tune a key" }, - { "settuning", "tuning", (fluid_cmd_func_t) fluid_handle_settuning, NULL, + { "settuning", "tuning", (fluid_cmd_func_t) fluid_handle_settuning, "settuning chan bank prog Set the tuning for a MIDI channel" }, - { "resettuning", "tuning", (fluid_cmd_func_t) fluid_handle_resettuning, NULL, + { "resettuning", "tuning", (fluid_cmd_func_t) fluid_handle_resettuning, "resettuning chan Restore the default tuning of a MIDI channel" }, - { "tunings", "tuning", (fluid_cmd_func_t) fluid_handle_tunings, NULL, + { "tunings", "tuning", (fluid_cmd_func_t) fluid_handle_tunings, "tunings Print the list of available tunings" }, - { "dumptuning", "tuning", (fluid_cmd_func_t) fluid_handle_dumptuning, NULL, + { "dumptuning", "tuning", (fluid_cmd_func_t) fluid_handle_dumptuning, "dumptuning bank prog Print the pitch details of the tuning" }, - { "reset", "general", (fluid_cmd_func_t) fluid_handle_reset, NULL, + { "reset", "general", (fluid_cmd_func_t) fluid_handle_reset, "reset System reset (all notes off, reset controllers)" }, - { "set", "settings", (fluid_cmd_func_t) fluid_handle_set, NULL, + { "set", "settings", (fluid_cmd_func_t) fluid_handle_set, "set name value Set the value of a controller or settings" }, - { "get", "settings", (fluid_cmd_func_t) fluid_handle_get, NULL, + { "get", "settings", (fluid_cmd_func_t) fluid_handle_get, "get name Get the value of a controller or settings" }, - { "info", "settings", (fluid_cmd_func_t) fluid_handle_info, NULL, + { "info", "settings", (fluid_cmd_func_t) fluid_handle_info, "info name Get information about a controller or settings" }, - { "settings", "settings", (fluid_cmd_func_t) fluid_handle_settings, NULL, + { "settings", "settings", (fluid_cmd_func_t) fluid_handle_settings, "settings Print out all settings" }, - { "echo", "general", (fluid_cmd_func_t) fluid_handle_echo, NULL, + { "echo", "general", (fluid_cmd_func_t) fluid_handle_echo, "echo arg Print arg" }, /* LADSPA-related commands */ #ifdef LADSPA - { "ladspa_clear", "ladspa", (fluid_cmd_func_t) fluid_LADSPA_handle_clear, NULL, + { "ladspa_clear", "ladspa", (fluid_cmd_func_t) fluid_LADSPA_handle_clear, "ladspa_clear Resets LADSPA effect unit to bypass state"}, - { "ladspa_add", "ladspa", (fluid_cmd_func_t) fluid_LADSPA_handle_add, NULL, + { "ladspa_add", "ladspa", (fluid_cmd_func_t) fluid_LADSPA_handle_add, "ladspa_add lib plugin n1 <- p1 n2 -> p2 ... Loads and connects LADSPA plugin"}, - { "ladspa_start", "ladspa", (fluid_cmd_func_t) fluid_LADSPA_handle_start, NULL, + { "ladspa_start", "ladspa", (fluid_cmd_func_t) fluid_LADSPA_handle_start, "ladspa_start Starts LADSPA effect unit"}, - { "ladspa_declnode", "ladspa", (fluid_cmd_func_t) fluid_LADSPA_handle_declnode, NULL, + { "ladspa_declnode", "ladspa", (fluid_cmd_func_t) fluid_LADSPA_handle_declnode, "ladspa_declnode node value Declares control node `node' with value `value'"}, - { "ladspa_setnode", "ladspa", (fluid_cmd_func_t) fluid_LADSPA_handle_setnode, NULL, + { "ladspa_setnode", "ladspa", (fluid_cmd_func_t) fluid_LADSPA_handle_setnode, "ladspa_setnode node value Assigns `value' to `node'"}, #endif - { "router_clear", "router", (fluid_cmd_func_t) fluid_handle_router_clear, NULL, + { "router_clear", "router", (fluid_cmd_func_t) fluid_handle_router_clear, "router_clear Clears all routing rules from the midi router"}, - { "router_default", "router", (fluid_cmd_func_t) fluid_handle_router_default, NULL, + { "router_default", "router", (fluid_cmd_func_t) fluid_handle_router_default, "router_default Resets the midi router to default state"}, - { "router_begin", "router", (fluid_cmd_func_t) fluid_handle_router_begin, NULL, + { "router_begin", "router", (fluid_cmd_func_t) fluid_handle_router_begin, "router_begin [note|cc|prog|pbend|cpress|kpress]: Starts a new routing rule"}, - { "router_chan", "router", (fluid_cmd_func_t) fluid_handle_router_chan, NULL, + { "router_chan", "router", (fluid_cmd_func_t) fluid_handle_router_chan, "router_chan min max mul add filters and maps midi channels on current rule"}, - { "router_par1", "router", (fluid_cmd_func_t) fluid_handle_router_par1, NULL, + { "router_par1", "router", (fluid_cmd_func_t) fluid_handle_router_par1, "router_par1 min max mul add filters and maps parameter 1 (key/ctrl nr)"}, - { "router_par2", "router", (fluid_cmd_func_t) fluid_handle_router_par2, NULL, + { "router_par2", "router", (fluid_cmd_func_t) fluid_handle_router_par2, "router_par2 min max mul add filters and maps parameter 2 (vel/cc val)"}, - { "router_end", "router", (fluid_cmd_func_t) fluid_handle_router_end, NULL, - "router_end closes and commits the current routing rule"}, - { NULL, NULL, NULL, NULL, NULL } + { "router_end", "router", (fluid_cmd_func_t) fluid_handle_router_end, + "router_end closes and commits the current routing rule"} }; /** @@ -1598,7 +1608,7 @@ fluid_handle_help(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream char* topic = "help"; /* default, if no topic is given */ int count = 0; - int i; + unsigned int i; fluid_ostream_printf(out, "\n"); /* 1st argument (optional): help topic */ @@ -1610,9 +1620,9 @@ fluid_handle_help(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream fluid_ostream_printf(out, "*** Help topics:***\n" "help all (prints all topics)\n"); - for (i = 0; fluid_commands[i].name != NULL; i++) { + for (i = 0; i < FLUID_N_ELEMENTS(fluid_commands); i++) { int listed_first_time = 1; - int ii; + unsigned int ii; for (ii = 0; ii < i; ii++){ if (strcmp(fluid_commands[i].topic, fluid_commands[ii].topic) == 0){ listed_first_time = 0; @@ -1624,10 +1634,9 @@ fluid_handle_help(fluid_cmd_handler_t* handler, int ac, char** av, fluid_ostream }; /* for all topics (outer loop) */ } else { /* help (arbitrary topic or "all") */ - for (i = 0; fluid_commands[i].name != NULL; i++) { - fluid_cmd_t cmd = fluid_commands[i]; - if (cmd.help != NULL) { - if (strcmp(topic,"all") == 0 || strcmp(topic,cmd.topic) == 0){ + for (i = 0; FLUID_N_ELEMENTS(fluid_commands); i++) { + if (fluid_commands[i].help != NULL) { + if (strcmp(topic,"all") == 0 || strcmp(topic,fluid_commands[i].topic) == 0){ fluid_ostream_printf(out, "%s\n", fluid_commands[i].help); count++; }; /* if it matches the topic */ @@ -1917,7 +1926,7 @@ fluid_cmd_handler_destroy_hash_value (void *value) */ fluid_cmd_handler_t* new_fluid_cmd_handler(fluid_synth_t* synth, fluid_midi_router_t* router) { - int i; + unsigned int i; fluid_cmd_handler_t* handler; handler = FLUID_NEW(fluid_cmd_handler_t); @@ -1935,11 +1944,17 @@ fluid_cmd_handler_t* new_fluid_cmd_handler(fluid_synth_t* synth, fluid_midi_rout handler->router = router; if (synth != NULL) { - for (i = 0; fluid_commands[i].name != NULL; i++) + for (i = 0; i < FLUID_N_ELEMENTS(fluid_commands); i++) { - fluid_commands[i].data = handler; - fluid_cmd_handler_register(handler, &fluid_commands[i]); - fluid_commands[i].data = NULL; + fluid_cmd_t cmd = { + (char *)fluid_commands[i].name, + (char *)fluid_commands[i].topic, + fluid_commands[i].handler, + handler, + (char *)fluid_commands[i].help + }; + + fluid_cmd_handler_register(handler, &cmd); } } From a10662e8976f1174047609dce9b65cb0574e9d4e Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 12:40:38 +0200 Subject: [PATCH 02/17] Optimized fluid_audio_drivers[] --- src/drivers/fluid_adriver.c | 13 ++++++------- src/drivers/fluid_adriver.h | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/drivers/fluid_adriver.c b/src/drivers/fluid_adriver.c index 3bfdc135..9b855610 100644 --- a/src/drivers/fluid_adriver.c +++ b/src/drivers/fluid_adriver.c @@ -27,7 +27,7 @@ typedef struct _fluid_audriver_definition_t { - char* name; + const char* name; fluid_audio_driver_t* (*new)(fluid_settings_t* settings, fluid_synth_t* synth); fluid_audio_driver_t* (*new2)(fluid_settings_t* settings, fluid_audio_func_t func, @@ -119,7 +119,7 @@ int delete_fluid_file_audio_driver(fluid_audio_driver_t* p); #endif /* Available audio drivers, listed in order of preference */ -fluid_audriver_definition_t fluid_audio_drivers[] = { +static const fluid_audriver_definition_t fluid_audio_drivers[] = { #if JACK_SUPPORT { "jack", new_fluid_jack_audio_driver, @@ -190,7 +190,6 @@ fluid_audriver_definition_t fluid_audio_drivers[] = { delete_fluid_file_audio_driver, NULL }, #endif - { NULL, NULL, NULL, NULL, NULL } }; @@ -198,7 +197,7 @@ fluid_audriver_definition_t fluid_audio_drivers[] = { void fluid_audio_driver_settings(fluid_settings_t* settings) { - int i; + unsigned int i; fluid_settings_register_str(settings, "audio.sample-format", "16bits", 0, NULL, NULL); fluid_settings_add_option(settings, "audio.sample-format", "16bits"); @@ -275,7 +274,7 @@ void fluid_audio_driver_settings(fluid_settings_t* settings) fluid_settings_add_option(settings, "audio.driver", "file"); #endif - for (i = 0; fluid_audio_drivers[i].name != NULL; i++) { + for (i = 0; i < FLUID_N_ELEMENTS(fluid_audio_drivers); i++) { if (fluid_audio_drivers[i].settings != NULL) { fluid_audio_drivers[i].settings(settings); } @@ -295,12 +294,12 @@ void fluid_audio_driver_settings(fluid_settings_t* settings) fluid_audio_driver_t* new_fluid_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth) { - int i; + unsigned int i; fluid_audio_driver_t* driver = NULL; char* name; char *allnames; - for (i = 0; fluid_audio_drivers[i].name != NULL; i++) { + for (i = 0; i < FLUID_N_ELEMENTS(fluid_audio_drivers); i++) { if (fluid_settings_str_equal(settings, "audio.driver", fluid_audio_drivers[i].name)) { FLUID_LOG(FLUID_DBG, "Using '%s' audio driver", fluid_audio_drivers[i].name); driver = (*fluid_audio_drivers[i].new)(settings, synth); diff --git a/src/drivers/fluid_adriver.h b/src/drivers/fluid_adriver.h index 58b60adc..ae12001c 100644 --- a/src/drivers/fluid_adriver.h +++ b/src/drivers/fluid_adriver.h @@ -21,7 +21,7 @@ #ifndef _FLUID_AUDRIVER_H #define _FLUID_AUDRIVER_H -#include "fluidsynth_priv.h" +#include "fluid_sys.h" void fluid_audio_driver_settings(fluid_settings_t* settings); @@ -32,7 +32,7 @@ void fluid_audio_driver_settings(fluid_settings_t* settings); struct _fluid_audio_driver_t { - char* name; + const char* name; }; From 5e0bc7c143c4cd008c9597b68fab2fe6dfa35f0f Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 12:41:42 +0200 Subject: [PATCH 03/17] Optimized fluid_midi_drivers[] --- src/drivers/fluid_mdriver.c | 9 ++++----- src/drivers/fluid_mdriver.h | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/drivers/fluid_mdriver.c b/src/drivers/fluid_mdriver.c index 54049205..a0449db2 100644 --- a/src/drivers/fluid_mdriver.c +++ b/src/drivers/fluid_mdriver.c @@ -86,7 +86,7 @@ void fluid_coremidi_driver_settings(fluid_settings_t* settings); * fluid_mdriver_definition */ struct fluid_mdriver_definition_t { - char* name; + const char* name; fluid_midi_driver_t* (*new)(fluid_settings_t* settings, handle_midi_event_func_t event_handler, void* event_handler_data); @@ -95,7 +95,7 @@ struct fluid_mdriver_definition_t { }; -struct fluid_mdriver_definition_t fluid_midi_drivers[] = { +static const struct fluid_mdriver_definition_t fluid_midi_drivers[] = { #if JACK_SUPPORT { "jack", new_fluid_jack_midi_driver, @@ -136,14 +136,13 @@ struct fluid_mdriver_definition_t fluid_midi_drivers[] = { delete_fluid_coremidi_driver, fluid_coremidi_driver_settings }, #endif - { NULL, NULL, NULL, NULL } }; void fluid_midi_driver_settings(fluid_settings_t* settings) { - int i; + unsigned int i; fluid_settings_register_int (settings, "midi.realtime-prio", FLUID_DEFAULT_MIDI_RT_PRIO, 0, 99, 0, NULL, NULL); @@ -186,7 +185,7 @@ void fluid_midi_driver_settings(fluid_settings_t* settings) fluid_settings_add_option(settings, "midi.driver", "coremidi"); #endif - for (i = 0; fluid_midi_drivers[i].name != NULL; i++) { + for (i = 0; i < FLUID_N_ELEMENTS(fluid_midi_drivers); i++) { if (fluid_midi_drivers[i].settings != NULL) { fluid_midi_drivers[i].settings(settings); } diff --git a/src/drivers/fluid_mdriver.h b/src/drivers/fluid_mdriver.h index 335dcfb6..fdb96944 100644 --- a/src/drivers/fluid_mdriver.h +++ b/src/drivers/fluid_mdriver.h @@ -21,7 +21,7 @@ #ifndef _FLUID_MDRIVER_H #define _FLUID_MDRIVER_H -#include "fluidsynth_priv.h" +#include "fluid_sys.h" void fluid_midi_driver_settings(fluid_settings_t* settings); @@ -32,7 +32,7 @@ void fluid_midi_driver_settings(fluid_settings_t* settings); struct _fluid_midi_driver_t { - char* name; + const char* name; handle_midi_event_func_t handler; void* data; }; From 87bff4d3efa15dbc685e9bbb3d9692b7bc8a8320 Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 12:43:59 +0200 Subject: [PATCH 04/17] Optimized arrays to be fully const and FLUID_N_ELEMENTS() support. --- src/bindings/fluid_filerenderer.c | 49 ++++++++++++++----------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/src/bindings/fluid_filerenderer.c b/src/bindings/fluid_filerenderer.c index fd0208c2..9db93ac1 100644 --- a/src/bindings/fluid_filerenderer.c +++ b/src/bindings/fluid_filerenderer.c @@ -54,21 +54,20 @@ struct _fluid_file_renderer_t { /* File audio format names. * !! Keep in sync with format_ids[] */ -const char *format_names[] = { +static const char * const format_names[] = { "s8", "s16", "s24", "s32", "u8", "float", - "double", - NULL /* Terminator */ + "double" }; /* File audio format IDs. * !! Keep in sync with format_names[] */ -const int format_ids[] = { +static const int format_ids[] = { SF_FORMAT_PCM_S8, SF_FORMAT_PCM_16, SF_FORMAT_PCM_24, @@ -80,17 +79,16 @@ const int format_ids[] = { /* File endian byte order names. * !! Keep in sync with endian_ids[] */ -const char *endian_names[] = { +static const char * const endian_names[] = { "auto", "little", "big", - "cpu", - NULL + "cpu" }; /* File endian byte order ids. * !! Keep in sync with endian_names[] */ -const int endian_ids[] = { +static const int endian_ids[] = { SF_ENDIAN_FILE, SF_ENDIAN_LITTLE, SF_ENDIAN_BIG, @@ -107,21 +105,18 @@ static int fluid_file_renderer_find_valid_format (SF_INFO *info); /* File type names. */ -const char *type_names[] = { - "raw", - NULL /* Terminator */ +static const char * const type_names[] = { + "raw" }; /* File audio format names. */ -const char *format_names[] = { - "s16", - NULL /* Terminator */ +static const char * const format_names[] = { + "s16" }; /* File endian byte order names. */ -const char *endian_names[] = { - "cpu", - NULL +static const char * const endian_names[] = { + "cpu" }; #endif @@ -134,7 +129,7 @@ fluid_file_renderer_settings (fluid_settings_t* settings) SF_FORMAT_INFO finfo, cmpinfo; int major_count; int i, i2; - const char **np; + unsigned int n; fluid_settings_register_str(settings, "audio.file.name", "fluidsynth.wav", FLUID_HINT_FILENAME, NULL, NULL); @@ -165,11 +160,11 @@ fluid_file_renderer_settings (fluid_settings_t* settings) fluid_settings_add_option (settings, "audio.file.type", finfo.extension); } - for (np = format_names; *np; np++) - fluid_settings_add_option (settings, "audio.file.format", *np); + for (n = 0; n < FLUID_N_ELEMENTS(format_names); n++) + fluid_settings_add_option (settings, "audio.file.format", format_names[n]); - for (np = endian_names; *np; np++) - fluid_settings_add_option (settings, "audio.file.endian", *np); + for (n = 0; n < FLUID_N_ELEMENTS(endian_names); n++) + fluid_settings_add_option (settings, "audio.file.endian", endian_names[n]); #else @@ -417,7 +412,7 @@ fluid_file_renderer_parse_options (char *filetype, char *format, char *endian, { int type = -1; /* -1 indicates "auto" type */ char *s; - int i; + unsigned int i; /* If "auto" type, then use extension to search for a match */ if (!filetype || FLUID_STRCMP (filetype, "auto") == 0) @@ -443,11 +438,11 @@ fluid_file_renderer_parse_options (char *filetype, char *format, char *endian, /* Look for subtype */ if (format) { - for (i = 0; format_names[i]; i++) + for (i = 0; i < FLUID_N_ELEMENTS(format_names); i++) if (FLUID_STRCMP (format, format_names[i]) == 0) break; - if (!format_names[i]) + if (i >= FLUID_N_ELEMENTS(format_names)) { FLUID_LOG (FLUID_ERR, "Invalid or unsupported file audio format '%s'", format); return FALSE; @@ -466,11 +461,11 @@ fluid_file_renderer_parse_options (char *filetype, char *format, char *endian, /* Look for endian */ if (endian) { - for (i = 0; endian_names[i]; i++) + for (i = 0; i < FLUID_N_ELEMENTS(endian_names); i++) if (FLUID_STRCMP (endian, endian_names[i]) == 0) break; - if (!endian_names[i]) + if (i >= FLUID_N_ELEMENTS(endian_names)) { FLUID_LOG (FLUID_ERR, "Invalid or unsupported endian byte order '%s'", endian); return FALSE; From 4f8ab20355140a0d009fc487cd60abf80ff2bb5c Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 12:46:13 +0200 Subject: [PATCH 05/17] fluid_gen_info[] made as a const object --- bindings/fluidmax/fluidmax.c | 2 +- src/synth/fluid_gen.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/fluidmax/fluidmax.c b/bindings/fluidmax/fluidmax.c index 0651f99f..66556dd7 100644 --- a/bindings/fluidmax/fluidmax.c +++ b/bindings/fluidmax/fluidmax.c @@ -1065,7 +1065,7 @@ fluidmax_version(t_object *o) post(" Max/MSP integration by Norbert Schnell IMTR IRCAM - Centre Pompidou"); } -extern fluid_gen_info_t fluid_gen_info[]; +extern const fluid_gen_info_t fluid_gen_info[]; static void fluidmax_print(t_object *o, Symbol *s, short ac, Atom *at) diff --git a/src/synth/fluid_gen.c b/src/synth/fluid_gen.c index 3d8d4759..0da90eb3 100644 --- a/src/synth/fluid_gen.c +++ b/src/synth/fluid_gen.c @@ -24,7 +24,7 @@ /* See SFSpec21 $8.1.3 */ -fluid_gen_info_t fluid_gen_info[] = { +const fluid_gen_info_t fluid_gen_info[] = { /* number/name init scale min max def */ { GEN_STARTADDROFS, 1, 1, 0.0f, 1e10f, 0.0f }, { GEN_ENDADDROFS, 1, 1, -1e10f, 0.0f, 0.0f }, From 95ea3c0fbabcb279e1a732ada4ac39f4b7f71d10 Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 12:47:59 +0200 Subject: [PATCH 06/17] idlist[], badgen[] and badpgen[] made static const --- src/sfloader/fluid_defsfont.c | 10 ++++++---- src/sfloader/fluid_defsfont.h | 8 -------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/sfloader/fluid_defsfont.c b/src/sfloader/fluid_defsfont.c index 1580eeb3..9ba05380 100644 --- a/src/sfloader/fluid_defsfont.c +++ b/src/sfloader/fluid_defsfont.c @@ -2132,7 +2132,7 @@ static int fixup_pgen (SFData * sf); static int fixup_igen (SFData * sf); static int fixup_sample (SFData * sf); -char idlist[] = { +static const char idlist[] = { "RIFFLISTsfbkINFOsdtapdtaifilisngINAMiromiverICRDIENGIPRD" "ICOPICMTISFTsnamsmplphdrpbagpmodpgeninstibagimodigenshdr" }; @@ -2421,7 +2421,7 @@ pdtahelper (unsigned int expid, unsigned int reclen, SFChunk * chunk, int * size, FILE * fd) { unsigned int id; - char *expstr; + const char *expstr; expstr = CHNKIDSTR (expid); /* in case we need it */ @@ -3429,11 +3429,13 @@ fixup_sample (SFData * sf) #define MOD_CHUNK_OPTIMUM_AREA 256 #define GEN_CHUNK_OPTIMUM_AREA 256 -unsigned short badgen[] = { Gen_Unused1, Gen_Unused2, Gen_Unused3, Gen_Unused4, +static const unsigned short badgen[] = { + Gen_Unused1, Gen_Unused2, Gen_Unused3, Gen_Unused4, Gen_Reserved1, Gen_Reserved2, Gen_Reserved3, 0 }; -unsigned short badpgen[] = { Gen_StartAddrOfs, Gen_EndAddrOfs, Gen_StartLoopAddrOfs, +static const unsigned short badpgen[] = { + Gen_StartAddrOfs, Gen_EndAddrOfs, Gen_StartLoopAddrOfs, Gen_EndLoopAddrOfs, Gen_StartAddrCoarseOfs, Gen_EndAddrCoarseOfs, Gen_StartLoopAddrCoarseOfs, Gen_Keynum, Gen_Velocity, Gen_EndLoopAddrCoarseOfs, Gen_SampleModes, Gen_ExclusiveClass, diff --git a/src/sfloader/fluid_defsfont.h b/src/sfloader/fluid_defsfont.h index 56f87dd5..6c2757d4 100644 --- a/src/sfloader/fluid_defsfont.h +++ b/src/sfloader/fluid_defsfont.h @@ -212,11 +212,6 @@ typedef enum } Gen_Unit; -/* global data */ - -extern unsigned short badgen[]; /* list of bad generators */ -extern unsigned short badpgen[]; /* list of bad preset generators */ - /* functions */ void sfont_init_chunks (void); @@ -295,9 +290,6 @@ typedef struct _SFShdr } SFShdr; -/* data */ -extern char idlist[]; - /* functions */ SFData *sfload_file (const char * fname); From 0722ab3ab4a6f05c2b5f5b5382f91910e09830d8 Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 12:50:52 +0200 Subject: [PATCH 07/17] Optimized revmodel_preset[] as const and rewritten fluid_synth_set_reverb_preset() --- src/rvoice/fluid_rev.h | 2 +- src/synth/fluid_synth.c | 25 ++++++++++--------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/rvoice/fluid_rev.h b/src/rvoice/fluid_rev.h index 009f39e7..120fe880 100644 --- a/src/rvoice/fluid_rev.h +++ b/src/rvoice/fluid_rev.h @@ -46,7 +46,7 @@ typedef enum * reverb preset */ typedef struct _fluid_revmodel_presets_t { - char* name; + const char* name; fluid_real_t roomsize; fluid_real_t damp; fluid_real_t width; diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index f18fe56e..fa637d61 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -139,14 +139,13 @@ fluid_mod_t default_chorus_mod; /* SF2.01 section 8.4.9 */ fluid_mod_t default_pitch_bend_mod; /* SF2.01 section 8.4.10 */ /* reverb presets */ -static fluid_revmodel_presets_t revmodel_preset[] = { +static const fluid_revmodel_presets_t revmodel_preset[] = { /* name */ /* roomsize */ /* damp */ /* width */ /* level */ { "Test 1", 0.2f, 0.0f, 0.5f, 0.9f }, { "Test 2", 0.4f, 0.2f, 0.5f, 0.8f }, { "Test 3", 0.6f, 0.4f, 0.5f, 0.7f }, { "Test 4", 0.8f, 0.7f, 0.5f, 0.6f }, { "Test 5", 0.8f, 1.0f, 0.5f, 0.5f }, - { NULL, 0.0f, 0.0f, 0.0f, 0.0f } }; @@ -3799,7 +3798,7 @@ fluid_synth_get_channel_info (fluid_synth_t *synth, int chan, { fluid_channel_t *channel; fluid_preset_t *preset; - char *name; + const char *name; if (info) { @@ -3897,19 +3896,15 @@ fluid_synth_set_reverb_on(fluid_synth_t* synth, int on) * @note Currently private to libfluidsynth. */ int -fluid_synth_set_reverb_preset(fluid_synth_t* synth, int num) +fluid_synth_set_reverb_preset(fluid_synth_t* synth, unsigned int num) { - int i = 0; - while (revmodel_preset[i].name != NULL) { - if (i == num) { - fluid_synth_set_reverb (synth, revmodel_preset[i].roomsize, - revmodel_preset[i].damp, revmodel_preset[i].width, - revmodel_preset[i].level); - return FLUID_OK; - } - i++; - } - return FLUID_FAILED; + if (num >= FLUID_N_ELEMENTS(revmodel_preset)) + return FLUID_FAILED; + + fluid_synth_set_reverb (synth, revmodel_preset[num].roomsize, + revmodel_preset[num].damp, revmodel_preset[num].width, + revmodel_preset[num].level); + return FLUID_OK; } /** From 48936975e785cbbe60f7f13bdc101d691e05cba0 Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 12:52:03 +0200 Subject: [PATCH 08/17] Fixed prototype for fluid_synth_set_reverb_preset() --- src/synth/fluid_synth.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/synth/fluid_synth.h b/src/synth/fluid_synth.h index 476b006b..72ae713d 100644 --- a/src/synth/fluid_synth.h +++ b/src/synth/fluid_synth.h @@ -191,7 +191,7 @@ void fluid_synth_dither_s16(int *dither_index, int len, float* lin, float* rin, void* rout, int roff, int rincr); int fluid_synth_reset_reverb(fluid_synth_t* synth); -int fluid_synth_set_reverb_preset(fluid_synth_t* synth, int num); +int fluid_synth_set_reverb_preset(fluid_synth_t* synth, unsigned int num); int fluid_synth_set_reverb_full(fluid_synth_t* synth, int set, double roomsize, double damping, double width, double level); From 4293fddc055ad18dec87b39c2fbe1d400d9218c3 Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 12:54:00 +0200 Subject: [PATCH 09/17] Fixes for using standard math constants --- src/utils/fluid_conv.c | 4 ++-- src/utils/fluidsynth_priv.h | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/utils/fluid_conv.c b/src/utils/fluid_conv.c index 13ea6b5e..ea4f0310 100644 --- a/src/utils/fluid_conv.c +++ b/src/utils/fluid_conv.c @@ -86,7 +86,7 @@ fluid_conversion_config(void) implemented according to the pictures on SF2.01 page 73. */ for (i = 1; i < 127; i++) { - x = -20.0 / 96.0 * log((i * i) / (127.0 * 127.0)) / log(10.0); + x = -20.0 / 96.0 * log((i * i) / (127.0 * 127.0)) / M_LN10; fluid_convex_tab[i] = (fluid_real_t) (1.0 - x); fluid_concave_tab[127 - i] = (fluid_real_t) x; } @@ -281,7 +281,7 @@ fluid_act2hz(fluid_real_t c) fluid_real_t fluid_hz2ct(fluid_real_t f) { - return (fluid_real_t) (6900 + 1200 * log(f / 440.0) / log(2.0)); + return (fluid_real_t) (6900 + 1200 * log(f / 440.0) / M_LN2); } /* diff --git a/src/utils/fluidsynth_priv.h b/src/utils/fluidsynth_priv.h index 7289c413..ae134b74 100644 --- a/src/utils/fluidsynth_priv.h +++ b/src/utils/fluidsynth_priv.h @@ -206,10 +206,6 @@ typedef struct _fluid_sample_timer_t fluid_sample_timer_t; #define FLUID_DEFAULT_AUDIO_RT_PRIO 60 /**< Default setting for audio.realtime-prio */ #define FLUID_DEFAULT_MIDI_RT_PRIO 50 /**< Default setting for midi.realtime-prio */ -#ifndef PI -#define PI 3.141592654 -#endif - /*************************************************************** * * SYSTEM INTERFACE @@ -280,6 +276,13 @@ typedef FILE* fluid_file; #define M_PI 3.1415926535897932384626433832795 #endif +#ifndef M_LN2 +#define M_LN2 0.69314718055994530941723212145818 +#endif + +#ifndef M_LN10 +#define M_LN10 2.3025850929940456840179914546844 +#endif #define FLUID_ASSERT(a,b) #define FLUID_ASSERT_P(a,b) From 94b752f433c18942984c2912d017cc96dd761264 Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 12:54:53 +0200 Subject: [PATCH 10/17] Made fluid_libname[] to be const. --- src/utils/fluid_sys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/fluid_sys.c b/src/utils/fluid_sys.c index a1f720b6..5fb8e840 100644 --- a/src/utils/fluid_sys.c +++ b/src/utils/fluid_sys.c @@ -74,7 +74,7 @@ static fluid_log_function_t fluid_log_function[LAST_LOG_LEVEL]; static void* fluid_log_user_data[LAST_LOG_LEVEL]; static int fluid_log_initialized = 0; -static char* fluid_libname = "fluidsynth"; +static const char fluid_libname[] = "fluidsynth"; void fluid_sys_config() From be8acf4e27a381f98bed619d6827e87507c29bd8 Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 13:15:57 +0200 Subject: [PATCH 11/17] Replace PI with standard M_PI. --- src/utils/fluid_conv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/fluid_conv.c b/src/utils/fluid_conv.c index ea4f0310..315cfb56 100644 --- a/src/utils/fluid_conv.c +++ b/src/utils/fluid_conv.c @@ -92,7 +92,7 @@ fluid_conversion_config(void) } /* initialize the pan conversion table */ - x = PI / 2.0 / (FLUID_PAN_SIZE - 1.0); + x = M_PI / 2.0 / (FLUID_PAN_SIZE - 1.0); for (i = 0; i < FLUID_PAN_SIZE; i++) { fluid_pan_tab[i] = (fluid_real_t) sin(i * x); } From fceeffa8de368ab78ffd3d30b5a28382edf285fa Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 13:33:28 +0200 Subject: [PATCH 12/17] Remove unused variable. --- src/synth/fluid_synth.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index fa637d61..c24f42b2 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -1738,7 +1738,6 @@ fluid_synth_system_reset(fluid_synth_t* synth) static int fluid_synth_system_reset_LOCAL(fluid_synth_t* synth) { - fluid_voice_t* voice; int i; fluid_synth_all_sounds_off_LOCAL(synth, -1); From 6b3ec2624254a0a57ae76d4291e15aaf9b835e47 Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 13:56:48 +0200 Subject: [PATCH 13/17] Added 2 missing tests with FLUID_N_ELEMENTS() --- src/drivers/fluid_mdriver.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/drivers/fluid_mdriver.c b/src/drivers/fluid_mdriver.c index a0449db2..ee459dc1 100644 --- a/src/drivers/fluid_mdriver.c +++ b/src/drivers/fluid_mdriver.c @@ -204,9 +204,9 @@ fluid_midi_driver_t* new_fluid_midi_driver(fluid_settings_t* settings, handle_mi { fluid_midi_driver_t* driver = NULL; char *allnames; - int i; + unsigned int i; - for (i = 0; fluid_midi_drivers[i].name != NULL; i++) { + for (i = 0; i < FLUID_N_ELEMENTS(fluid_midi_drivers); i++) { if (fluid_settings_str_equal(settings, "midi.driver", fluid_midi_drivers[i].name)) { FLUID_LOG(FLUID_DBG, "Using '%s' midi driver", fluid_midi_drivers[i].name); driver = fluid_midi_drivers[i].new(settings, handler, event_handler_data); @@ -231,9 +231,9 @@ fluid_midi_driver_t* new_fluid_midi_driver(fluid_settings_t* settings, handle_mi */ void delete_fluid_midi_driver(fluid_midi_driver_t* driver) { - int i; + unsigned int i; - for (i = 0; fluid_midi_drivers[i].name != NULL; i++) { + for (i = 0; i < FLUID_N_ELEMENTS(fluid_midi_drivers); i++) { if (fluid_midi_drivers[i].name == driver->name) { fluid_midi_drivers[i].free(driver); return; From 6f51fca0227a4542b5b04edfafd602d56d046370 Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 14:01:22 +0200 Subject: [PATCH 14/17] Same fix for fluid_adriver.c --- src/drivers/fluid_adriver.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/drivers/fluid_adriver.c b/src/drivers/fluid_adriver.c index 9b855610..bcd8f58e 100644 --- a/src/drivers/fluid_adriver.c +++ b/src/drivers/fluid_adriver.c @@ -336,11 +336,11 @@ new_fluid_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth) fluid_audio_driver_t* new_fluid_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, void* data) { - int i; + unsigned int i; fluid_audio_driver_t* driver = NULL; char* name; - for (i = 0; fluid_audio_drivers[i].name != NULL; i++) { + for (i = 0; i < FLUID_N_ELEMENTS(fluid_audio_drivers); i++) { if (fluid_settings_str_equal(settings, "audio.driver", fluid_audio_drivers[i].name) && (fluid_audio_drivers[i].new2 != NULL)) { FLUID_LOG(FLUID_DBG, "Using '%s' audio driver", fluid_audio_drivers[i].name); @@ -368,9 +368,9 @@ new_fluid_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, voi void delete_fluid_audio_driver(fluid_audio_driver_t* driver) { - int i; + unsigned int i; - for (i = 0; fluid_audio_drivers[i].name != NULL; i++) { + for (i = 0; i < FLUID_N_ELEMENTS(fluid_audio_drivers); i++) { if (fluid_audio_drivers[i].name == driver->name) { fluid_audio_drivers[i].free(driver); return; From ae041fdcec3f9d0b26673c35dd33450602a1e16f Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 16:41:03 +0200 Subject: [PATCH 15/17] Made fluid_gen_info[] static --- src/synth/fluid_gen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/synth/fluid_gen.c b/src/synth/fluid_gen.c index 0da90eb3..a3efcb2a 100644 --- a/src/synth/fluid_gen.c +++ b/src/synth/fluid_gen.c @@ -24,7 +24,7 @@ /* See SFSpec21 $8.1.3 */ -const fluid_gen_info_t fluid_gen_info[] = { +static const fluid_gen_info_t fluid_gen_info[] = { /* number/name init scale min max def */ { GEN_STARTADDROFS, 1, 1, 0.0f, 1e10f, 0.0f }, { GEN_ENDADDROFS, 1, 1, -1e10f, 0.0f, 0.0f }, From b15f6c4b2ad716508131c4092e804bdc7a114225 Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 16:49:07 +0200 Subject: [PATCH 16/17] Reverted change to unsigned type on fluid_synth_set_reverb_preset(), used fluid_return_val_if_fail() for consistency. --- src/synth/fluid_synth.c | 8 +++++--- src/synth/fluid_synth.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index c24f42b2..f9e85f06 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -3895,10 +3895,12 @@ fluid_synth_set_reverb_on(fluid_synth_t* synth, int on) * @note Currently private to libfluidsynth. */ int -fluid_synth_set_reverb_preset(fluid_synth_t* synth, unsigned int num) +fluid_synth_set_reverb_preset(fluid_synth_t* synth, int num) { - if (num >= FLUID_N_ELEMENTS(revmodel_preset)) - return FLUID_FAILED; + fluid_return_val_if_fail ( + num < 0 || num >= (int)FLUID_N_ELEMENTS(revmodel_preset), + FLUID_FAILED + ); fluid_synth_set_reverb (synth, revmodel_preset[num].roomsize, revmodel_preset[num].damp, revmodel_preset[num].width, diff --git a/src/synth/fluid_synth.h b/src/synth/fluid_synth.h index 72ae713d..476b006b 100644 --- a/src/synth/fluid_synth.h +++ b/src/synth/fluid_synth.h @@ -191,7 +191,7 @@ void fluid_synth_dither_s16(int *dither_index, int len, float* lin, float* rin, void* rout, int roff, int rincr); int fluid_synth_reset_reverb(fluid_synth_t* synth); -int fluid_synth_set_reverb_preset(fluid_synth_t* synth, unsigned int num); +int fluid_synth_set_reverb_preset(fluid_synth_t* synth, int num); int fluid_synth_set_reverb_full(fluid_synth_t* synth, int set, double roomsize, double damping, double width, double level); From 931e4349a6138bb83aa09b23987f75f1e0d529f1 Mon Sep 17 00:00:00 2001 From: carlo-bramini Date: Sat, 21 Oct 2017 17:13:02 +0200 Subject: [PATCH 17/17] Reverted again to unsigned type on fluid_synth_set_reverb_preset(), fixed error on fluid_return_val_if_fail() usage. --- src/synth/fluid_synth.c | 4 ++-- src/synth/fluid_synth.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index f9e85f06..add29541 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -3895,10 +3895,10 @@ fluid_synth_set_reverb_on(fluid_synth_t* synth, int on) * @note Currently private to libfluidsynth. */ int -fluid_synth_set_reverb_preset(fluid_synth_t* synth, int num) +fluid_synth_set_reverb_preset(fluid_synth_t* synth, unsigned int num) { fluid_return_val_if_fail ( - num < 0 || num >= (int)FLUID_N_ELEMENTS(revmodel_preset), + num < FLUID_N_ELEMENTS(revmodel_preset), FLUID_FAILED ); diff --git a/src/synth/fluid_synth.h b/src/synth/fluid_synth.h index 476b006b..72ae713d 100644 --- a/src/synth/fluid_synth.h +++ b/src/synth/fluid_synth.h @@ -191,7 +191,7 @@ void fluid_synth_dither_s16(int *dither_index, int len, float* lin, float* rin, void* rout, int roff, int rincr); int fluid_synth_reset_reverb(fluid_synth_t* synth); -int fluid_synth_set_reverb_preset(fluid_synth_t* synth, int num); +int fluid_synth_set_reverb_preset(fluid_synth_t* synth, unsigned int num); int fluid_synth_set_reverb_full(fluid_synth_t* synth, int set, double roomsize, double damping, double width, double level);