From cb5858305092a23de1fba18b82332039eca93f76 Mon Sep 17 00:00:00 2001 From: derselbst Date: Wed, 9 May 2018 22:09:23 +0200 Subject: [PATCH 1/9] add a unit test for reverb and chorus settings --- test/CMakeLists.txt | 1 + test/test_synth_chorus_reverb.c | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/test_synth_chorus_reverb.c diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3952b27c..0b663de0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,6 +14,7 @@ ADD_FLUID_TEST(test_sfont_loading) ADD_FLUID_TEST(test_sample_rate_change) ADD_FLUID_TEST(test_preset_sample_loading) ADD_FLUID_TEST(test_seqbind_unregister) +ADD_FLUID_TEST(test_synth_chorus_reverb) if ( LIBSNDFILE_HASVORBIS ) ADD_FLUID_TEST(test_sf3_sfont_loading) diff --git a/test/test_synth_chorus_reverb.c b/test/test_synth_chorus_reverb.c new file mode 100644 index 00000000..14906ea3 --- /dev/null +++ b/test/test_synth_chorus_reverb.c @@ -0,0 +1,39 @@ + +#include "test.h" +#include "fluidsynth.h" + +// this test should make sure that sample rate changed are handled correctly +int main(void) +{ + fluid_synth_t *synth; + fluid_settings_t *settings = new_fluid_settings(); + TEST_ASSERT(settings != NULL); + + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.roomsize", 1.0)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.damp", 1.0)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.width", 1.0)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.level", 1.0)); + + TEST_SUCCESS(fluid_settings_setint(settings, "synth.chorus.nr", 99)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.chorus.level", 1.0)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.chorus.speed", 1.0)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.chorus.depth", 1.0)); + + synth = new_fluid_synth(settings); + TEST_ASSERT(synth != NULL); + + TEST_ASSERT(fluid_synth_get_reverb_roomsize(synth) == 1.0); + TEST_ASSERT(fluid_synth_get_reverb_damp(synth) == 1.0); + TEST_ASSERT(fluid_synth_get_reverb_width(synth) == 1.0); + TEST_ASSERT(fluid_synth_get_reverb_level(synth) == 1.0); + + TEST_ASSERT(fluid_synth_get_chorus_nr(synth) == 99); + TEST_ASSERT(fluid_synth_get_chorus_level(synth) == 1.0); + TEST_ASSERT(fluid_synth_get_chorus_speed_Hz(synth) == 1.0); + TEST_ASSERT(fluid_synth_get_chorus_depth_ms(synth) == 1.0); + + delete_fluid_synth(synth); + delete_fluid_settings(settings); + + return EXIT_SUCCESS; +} From 4f2be1050722c952a54e687ebf369205f7e80f01 Mon Sep 17 00:00:00 2001 From: derselbst Date: Wed, 9 May 2018 22:10:07 +0200 Subject: [PATCH 2/9] add reverb and chorus settings as suggested by #49 --- src/rvoice/fluid_chorus.c | 6 +--- src/rvoice/fluid_rev.c | 6 ---- src/synth/fluid_synth.c | 64 ++++++++++++++++++++++++++++++++++----- 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/src/rvoice/fluid_chorus.c b/src/rvoice/fluid_chorus.c index 053ceac1..06799644 100644 --- a/src/rvoice/fluid_chorus.c +++ b/src/rvoice/fluid_chorus.c @@ -220,11 +220,7 @@ fluid_chorus_init(fluid_chorus_t* chorus) for (i = 0; i < MAX_SAMPLES; i++) { chorus->chorusbuf[i] = 0.0; } - - /* initialize the chorus with the default settings */ - fluid_chorus_set (chorus, FLUID_CHORUS_SET_ALL, FLUID_CHORUS_DEFAULT_N, - FLUID_CHORUS_DEFAULT_LEVEL, FLUID_CHORUS_DEFAULT_SPEED, - FLUID_CHORUS_DEFAULT_DEPTH, FLUID_CHORUS_DEFAULT_TYPE); + return FLUID_OK; } diff --git a/src/rvoice/fluid_rev.c b/src/rvoice/fluid_rev.c index 5dc0b03a..dc784fe1 100644 --- a/src/rvoice/fluid_rev.c +++ b/src/rvoice/fluid_rev.c @@ -195,11 +195,6 @@ fluid_comb_getfeedback(fluid_comb* comb) #define scaledamp 1.0f #define scaleroom 0.28f #define offsetroom 0.7f -#define initialroom 0.5f -#define initialdamp 0.2f -#define initialwet 1 -#define initialdry 0 -#define initialwidth 1 #define stereospread 23 /* @@ -278,7 +273,6 @@ new_fluid_revmodel(fluid_real_t sample_rate) fluid_allpass_setfeedback(&rev->allpassR[3], 0.5f); rev->gain = fixedgain; - fluid_revmodel_set(rev,FLUID_REVMODEL_SET_ALL,initialroom,initialdamp,initialwidth,initialwet); return rev; } diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index b2e66d1f..afb33df8 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -134,6 +134,8 @@ static void fluid_synth_set_basic_channel_LOCAL(fluid_synth_t* synth, int basicc static int fluid_synth_set_reverb_full_LOCAL(fluid_synth_t* synth, int set, double roomsize, double damping, double width, double level); +static int fluid_synth_set_chorus_full_LOCAL(fluid_synth_t* synth, int set, int nr, double level, + double speed, double depth_ms, int type); /*************************************************************** * @@ -191,8 +193,19 @@ static const fluid_revmodel_presets_t revmodel_preset[] = { void fluid_synth_settings(fluid_settings_t* settings) { fluid_settings_register_int(settings, "synth.verbose", 0, 0, 1, FLUID_HINT_TOGGLED); + fluid_settings_register_int(settings, "synth.reverb.active", 1, 0, 1, FLUID_HINT_TOGGLED); + fluid_settings_register_num(settings, "synth.reverb.roomsize", FLUID_REVERB_DEFAULT_ROOMSIZE, 0.0f, 1.0f, 0); + fluid_settings_register_num(settings, "synth.reverb.damp", FLUID_REVERB_DEFAULT_DAMP, 0.0f, 1.0f, 0); + fluid_settings_register_num(settings, "synth.reverb.width", FLUID_REVERB_DEFAULT_WIDTH, 0.0f, 100.0f, 0); + fluid_settings_register_num(settings, "synth.reverb.level", FLUID_REVERB_DEFAULT_LEVEL, 0.0f, 1.0f, 0); + fluid_settings_register_int(settings, "synth.chorus.active", 1, 0, 1, FLUID_HINT_TOGGLED); + fluid_settings_register_int(settings, "synth.chorus.nr", FLUID_CHORUS_DEFAULT_N, 0, 99, 0); + fluid_settings_register_num(settings, "synth.chorus.level", FLUID_CHORUS_DEFAULT_LEVEL, 0.0f, 10.0f, 0); + fluid_settings_register_num(settings, "synth.chorus.speed", FLUID_CHORUS_DEFAULT_SPEED, 0.29f, 5.0f, 0); + fluid_settings_register_num(settings, "synth.chorus.depth", FLUID_CHORUS_DEFAULT_DEPTH, 0.0f, 21.0f, 0); + fluid_settings_register_int(settings, "synth.ladspa.active", 0, 0, 1, FLUID_HINT_TOGGLED); fluid_settings_register_int(settings, "synth.lock-memory", 1, 0, 1, FLUID_HINT_TOGGLED); fluid_settings_register_str(settings, "midi.portname", "", 0); @@ -797,12 +810,38 @@ new_fluid_synth(fluid_settings_t *settings) synth->curmax = 0; synth->dither_index = 0; - fluid_synth_set_reverb_full_LOCAL(synth, + { + double room, damp, width, level; + + fluid_settings_getnum(settings, "synth.reverb.roomsize", &room); + fluid_settings_getnum(settings, "synth.reverb.damp", &damp); + fluid_settings_getnum(settings, "synth.reverb.width", &width); + fluid_settings_getnum(settings, "synth.reverb.level", &level); + + fluid_synth_set_reverb_full_LOCAL(synth, FLUID_REVMODEL_SET_ALL, - FLUID_REVERB_DEFAULT_ROOMSIZE, - FLUID_REVERB_DEFAULT_DAMP, - FLUID_REVERB_DEFAULT_WIDTH, - FLUID_REVERB_DEFAULT_LEVEL); + room, + damp, + width, + level); + } + + { + double level, speed, depth; + + fluid_settings_getint(settings, "synth.chorus.nr", &i); + fluid_settings_getnum(settings, "synth.chorus.level", &level); + fluid_settings_getnum(settings, "synth.chorus.speed", &speed); + fluid_settings_getnum(settings, "synth.chorus.depth", &depth); + + fluid_synth_set_chorus_full_LOCAL(synth, + FLUID_CHORUS_SET_ALL, + i, + level, + speed, + depth, + FLUID_CHORUS_DEFAULT_TYPE); + } /* Initialize multi-core variables if multiple cores enabled */ if (synth->cores > 1) @@ -4367,7 +4406,6 @@ fluid_synth_set_chorus_full(fluid_synth_t* synth, int set, int nr, double level, double speed, double depth_ms, int type) { int ret; - fluid_rvoice_param_t param[MAX_EVENT_PARAMS]; fluid_return_val_if_fail (synth != NULL, FLUID_FAILED); /* if non of the flags is set, fail */ @@ -4376,6 +4414,18 @@ fluid_synth_set_chorus_full(fluid_synth_t* synth, int set, int nr, double level, /* Synth shadow values are set here so that they will be returned if queried */ fluid_synth_api_enter(synth); + ret = fluid_synth_set_chorus_full_LOCAL(synth, set, nr, level, speed, depth_ms, type); + + FLUID_API_RETURN(ret); +} + +static int +fluid_synth_set_chorus_full_LOCAL(fluid_synth_t* synth, int set, int nr, double level, + double speed, double depth_ms, int type) +{ + int ret; + fluid_rvoice_param_t param[MAX_EVENT_PARAMS]; + if (set & FLUID_CHORUS_SET_NR) synth->chorus_nr = nr; @@ -4402,7 +4452,7 @@ fluid_synth_set_chorus_full(fluid_synth_t* synth, int set, int nr, double level, synth->eventhandler->mixer, param); - FLUID_API_RETURN(ret); + return (ret); } /** From 8690b4dbdad3634457307536394aa4d70faf46ff Mon Sep 17 00:00:00 2001 From: derselbst Date: Wed, 9 May 2018 22:10:31 +0200 Subject: [PATCH 3/9] remove default reverb and chorus macros from public API should now be fetched through a settings instance --- include/fluidsynth/synth.h | 11 ----------- src/synth/fluid_synth.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/fluidsynth/synth.h b/include/fluidsynth/synth.h index b8ea684f..7359a88c 100644 --- a/include/fluidsynth/synth.h +++ b/include/fluidsynth/synth.h @@ -137,11 +137,6 @@ FLUIDSYNTH_API double fluid_synth_get_reverb_damp(fluid_synth_t* synth); FLUIDSYNTH_API double fluid_synth_get_reverb_level(fluid_synth_t* synth); FLUIDSYNTH_API double fluid_synth_get_reverb_width(fluid_synth_t* synth); -#define FLUID_REVERB_DEFAULT_ROOMSIZE 0.2f /**< Default reverb room size */ -#define FLUID_REVERB_DEFAULT_DAMP 0.0f /**< Default reverb damping */ -#define FLUID_REVERB_DEFAULT_WIDTH 0.5f /**< Default reverb width */ -#define FLUID_REVERB_DEFAULT_LEVEL 0.9f /**< Default reverb level */ - /* Chorus */ @@ -168,12 +163,6 @@ FLUIDSYNTH_API double fluid_synth_get_chorus_speed_Hz(fluid_synth_t* synth); FLUIDSYNTH_API double fluid_synth_get_chorus_depth_ms(fluid_synth_t* synth); FLUIDSYNTH_API int fluid_synth_get_chorus_type(fluid_synth_t* synth); /* see fluid_chorus_mod */ -#define FLUID_CHORUS_DEFAULT_N 3 /**< Default chorus voice count */ -#define FLUID_CHORUS_DEFAULT_LEVEL 2.0f /**< Default chorus level */ -#define FLUID_CHORUS_DEFAULT_SPEED 0.3f /**< Default chorus speed */ -#define FLUID_CHORUS_DEFAULT_DEPTH 8.0f /**< Default chorus depth */ -#define FLUID_CHORUS_DEFAULT_TYPE FLUID_CHORUS_MOD_SINE /**< Default chorus waveform type */ - /* Audio and MIDI channels */ diff --git a/src/synth/fluid_synth.h b/src/synth/fluid_synth.h index 2b2d9b31..30ebb4b1 100644 --- a/src/synth/fluid_synth.h +++ b/src/synth/fluid_synth.h @@ -46,6 +46,17 @@ #define FLUID_UNSET_PROGRAM 128 /* Program number used to unset a preset */ +#define FLUID_REVERB_DEFAULT_ROOMSIZE 0.2f /**< Default reverb room size */ +#define FLUID_REVERB_DEFAULT_DAMP 0.0f /**< Default reverb damping */ +#define FLUID_REVERB_DEFAULT_WIDTH 0.5f /**< Default reverb width */ +#define FLUID_REVERB_DEFAULT_LEVEL 0.9f /**< Default reverb level */ + +#define FLUID_CHORUS_DEFAULT_N 3 /**< Default chorus voice count */ +#define FLUID_CHORUS_DEFAULT_LEVEL 2.0f /**< Default chorus level */ +#define FLUID_CHORUS_DEFAULT_SPEED 0.3f /**< Default chorus speed */ +#define FLUID_CHORUS_DEFAULT_DEPTH 8.0f /**< Default chorus depth */ +#define FLUID_CHORUS_DEFAULT_TYPE FLUID_CHORUS_MOD_SINE /**< Default chorus waveform type */ + /*************************************************************** * * ENUM From b9ffd8f58724a98cac037709b3a0457e3b387653 Mon Sep 17 00:00:00 2001 From: derselbst Date: Thu, 10 May 2018 21:26:08 +0200 Subject: [PATCH 4/9] deprecate reverb and chorus shell commands --- src/bindings/fluid_cmd.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/bindings/fluid_cmd.c b/src/bindings/fluid_cmd.c index 12dfa49c..3f1ef62a 100644 --- a/src/bindings/fluid_cmd.c +++ b/src/bindings/fluid_cmd.c @@ -803,6 +803,9 @@ fluid_handle_reverbpreset(void* data, int ac, char** av, fluid_ostream_t out) { FLUID_ENTRY_COMMAND(data); int reverb_preset_number; + + fluid_ostream_printf(out, "rev_preset is deprecated and will be removed in a future release!\n"); + if (ac < 1) { fluid_ostream_printf(out, "rev_preset: too few arguments\n"); return FLUID_FAILED; @@ -823,10 +826,14 @@ fluid_handle_reverbsetroomsize(void* data, int ac, char** av, fluid_ostream_t ou { FLUID_ENTRY_COMMAND(data); fluid_real_t room_size; + if (ac < 1) { fluid_ostream_printf(out, "rev_setroomsize: too few arguments.\n"); return FLUID_FAILED; } + + fluid_ostream_printf(out, "rev_setroomsize is deprecated! Use 'set synth.reverb.roomsize %s' instead.\n", av[0]); + room_size = atof(av[0]); if (room_size < 0){ fluid_ostream_printf(out, "rev_setroomsize: Room size must be positive!\n"); @@ -852,6 +859,9 @@ fluid_handle_reverbsetdamp(void* data, int ac, char** av, fluid_ostream_t out) fluid_ostream_printf(out, "rev_setdamp: too few arguments.\n"); return FLUID_FAILED; } + + fluid_ostream_printf(out, "rev_setdamp is deprecated! Use 'set synth.reverb.damp %s' instead.\n", av[0]); + damp = atof(av[0]); if ((damp < 0.0f) || (damp > 1)){ fluid_ostream_printf(out, "rev_setdamp: damp must be between 0 and 1!\n"); @@ -873,6 +883,9 @@ fluid_handle_reverbsetwidth(void* data, int ac, char** av, fluid_ostream_t out) fluid_ostream_printf(out, "rev_setwidth: too few arguments.\n"); return FLUID_FAILED; } + + fluid_ostream_printf(out, "rev_setroomsize is deprecated! Use 'set synth.reverb.width %s' instead.\n", av[0]); + width = atof(av[0]); if ((width < 0) || (width > 100)){ fluid_ostream_printf(out, "rev_setroomsize: Too wide! (0..100)\n"); @@ -894,6 +907,9 @@ fluid_handle_reverbsetlevel(void* data, int ac, char** av, fluid_ostream_t out) fluid_ostream_printf(out, "rev_setlevel: too few arguments.\n"); return FLUID_FAILED; } + + fluid_ostream_printf(out, "rev_setlevel is deprecated! Use 'set synth.reverb.level %s' instead.\n", av[0]); + level = atof(av[0]); if (fabs(level) > 30){ fluid_ostream_printf(out, "rev_setlevel: Value too high! (Value of 10 =+20 dB)\n"); @@ -914,7 +930,9 @@ fluid_handle_reverb(void* data, int ac, char** av, fluid_ostream_t out) fluid_ostream_printf(out, "reverb: too few arguments.\n"); return FLUID_FAILED; } - + + fluid_ostream_printf(out, "reverb is deprecated! Use 'set synth.reverb.active %s' instead.\n", av[0]); + if ((FLUID_STRCMP(av[0], "0") == 0) || (FLUID_STRCMP(av[0], "off") == 0)) { fluid_synth_set_reverb_on(handler->synth,0); } else if ((FLUID_STRCMP(av[0], "1") == 0) || (FLUID_STRCMP(av[0], "on") == 0)) { @@ -939,6 +957,9 @@ fluid_handle_chorusnr(void* data, int ac, char** av, fluid_ostream_t out) fluid_ostream_printf(out, "cho_set_nr: too few arguments.\n"); return FLUID_FAILED; } + + fluid_ostream_printf(out, "cho_set_nr is deprecated! Use 'set synth.chorus.nr %s' instead.\n", av[0]); + nr = atoi(av[0]); fluid_synth_set_chorus_nr(handler->synth, nr); return FLUID_OK; @@ -955,6 +976,9 @@ fluid_handle_choruslevel(void* data, int ac, char** av, fluid_ostream_t out) fluid_ostream_printf(out, "cho_set_level: too few arguments.\n"); return FLUID_FAILED; } + + fluid_ostream_printf(out, "cho_set_level is deprecated! Use 'set synth.chorus.level %s' instead.\n", av[0]); + level = atof(av[0]); fluid_synth_set_chorus_level(handler->synth, level); return FLUID_OK; @@ -972,6 +996,9 @@ fluid_handle_chorusspeed(void* data, int ac, char** av, fluid_ostream_t out) fluid_ostream_printf(out, "cho_set_speed: too few arguments.\n"); return FLUID_FAILED; } + + fluid_ostream_printf(out, "cho_set_speed is deprecated! Use 'set synth.chorus.speed %s' instead.\n", av[0]); + speed = atof(av[0]); fluid_synth_set_chorus_speed(handler->synth, speed); return FLUID_OK; @@ -988,6 +1015,9 @@ fluid_handle_chorusdepth(void* data, int ac, char** av, fluid_ostream_t out) fluid_ostream_printf(out, "cho_set_depth: too few arguments.\n"); return FLUID_FAILED; } + + fluid_ostream_printf(out, "cho_set_depth is deprecated! Use 'set synth.chorus.depth %s' instead.\n", av[0]); + depth = atof(av[0]); fluid_synth_set_chorus_depth(handler->synth, depth); return FLUID_OK; @@ -1001,7 +1031,9 @@ fluid_handle_chorus(void* data, int ac, char** av, fluid_ostream_t out) fluid_ostream_printf(out, "chorus: too few arguments\n"); return FLUID_FAILED; } - + + fluid_ostream_printf(out, "chorus is deprecated! Use 'set synth.chorus.active %s' instead.\n", av[0]); + if ((FLUID_STRCMP(av[0], "0") == 0) || (FLUID_STRCMP(av[0], "off") == 0)) { fluid_synth_set_chorus_on(handler->synth,0); } else if ((FLUID_STRCMP(av[0], "1") == 0) || (FLUID_STRCMP(av[0], "on") == 0)) { From 70837ce8fc9b7574507e47ebc51f18ddd1dd67dc Mon Sep 17 00:00:00 2001 From: derselbst Date: Mon, 14 May 2018 14:56:34 +0200 Subject: [PATCH 5/9] turn reverb and chorus settings into realtime settings --- src/synth/fluid_synth.c | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index afb33df8..4bcabce5 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -126,6 +126,8 @@ static void fluid_synth_handle_device_id(void *data, const char *name, int value static void fluid_synth_handle_overflow(void *data, const char *name, double value); static void fluid_synth_handle_important_channels(void *data, const char *name, const char *value); +static void fluid_synth_handle_reverb_chorus_num (void *data, const char *name, double value); +static void fluid_synth_handle_reverb_chorus_int (void *data, const char *name, int value); static void fluid_synth_reset_basic_channel_LOCAL(fluid_synth_t* synth, int chan, int nbr_chan); @@ -652,6 +654,26 @@ new_fluid_synth(fluid_settings_t *settings) fluid_synth_handle_overflow, synth); fluid_settings_callback_str(settings, "synth.overflow.important-channels", fluid_synth_handle_important_channels, synth); + fluid_settings_callback_num(settings, "synth.reverb.roomsize", + fluid_synth_handle_reverb_chorus_num, synth); + fluid_settings_callback_num(settings, "synth.reverb.damp", + fluid_synth_handle_reverb_chorus_num, synth); + fluid_settings_callback_num(settings, "synth.reverb.width", + fluid_synth_handle_reverb_chorus_num, synth); + fluid_settings_callback_num(settings, "synth.reverb.level", + fluid_synth_handle_reverb_chorus_num, synth); + fluid_settings_callback_int(settings, "synth.reverb.active", + fluid_synth_handle_reverb_chorus_int, synth); + fluid_settings_callback_int(settings, "synth.chorus.active", + fluid_synth_handle_reverb_chorus_int, synth); + fluid_settings_callback_int(settings, "synth.chorus.nr", + fluid_synth_handle_reverb_chorus_int, synth); + fluid_settings_callback_num(settings, "synth.chorus.level", + fluid_synth_handle_reverb_chorus_num, synth); + fluid_settings_callback_num(settings, "synth.chorus.depth", + fluid_synth_handle_reverb_chorus_num, synth); + fluid_settings_callback_num(settings, "synth.chorus.speed", + fluid_synth_handle_reverb_chorus_num, synth); /* do some basic sanity checking on the settings */ @@ -3406,6 +3428,53 @@ fluid_synth_render_blocks(fluid_synth_t* synth, int blockcount) return blockcount; } +/* + * Handler for synth.reverb.* settings. + */ +static void fluid_synth_handle_reverb_chorus_num (void *data, const char *name, double value) +{ + fluid_synth_t *synth = (fluid_synth_t *)data; + fluid_return_if_fail(synth != NULL); + + if (FLUID_STRCMP(name, "synth.reverb.roomsize") == 0) { + fluid_synth_set_reverb_roomsize(synth, value); + } + else if (FLUID_STRCMP(name, "synth.reverb.damp") == 0) { + fluid_synth_set_reverb_damp(synth, value); + } + else if (FLUID_STRCMP(name, "synth.reverb.width") == 0) { + fluid_synth_set_reverb_width(synth, value); + } + else if (FLUID_STRCMP(name, "synth.reverb.level") == 0) { + fluid_synth_set_reverb_level(synth, value); + } + else if (FLUID_STRCMP(name, "synth.chorus.depth") == 0) { + fluid_synth_set_chorus_depth(synth, value); + } + else if (FLUID_STRCMP(name, "synth.chorus.speed") == 0) { + fluid_synth_set_chorus_speed(synth, value); + } + else if (FLUID_STRCMP(name, "synth.chorus.level") == 0) { + fluid_synth_set_chorus_level(synth, value); + } +} + + +static void fluid_synth_handle_reverb_chorus_int (void *data, const char *name, int value) +{ + fluid_synth_t *synth = (fluid_synth_t *)data; + fluid_return_if_fail(synth != NULL); + + if (FLUID_STRCMP(name, "synth.reverb.active") == 0) { + fluid_synth_set_reverb_on(synth, value); + } + else if (FLUID_STRCMP(name, "synth.chorus.active") == 0) { + fluid_synth_set_chorus_on(synth, value); + } + else if (FLUID_STRCMP(name, "synth.chorus.nr") == 0) { + fluid_synth_set_chorus_nr(synth, value); + } +} /* * Handler for synth.overflow.* settings. From 57abab0a31415a210828a515226dab39b1b7c683 Mon Sep 17 00:00:00 2001 From: derselbst Date: Thu, 17 May 2018 19:59:34 +0200 Subject: [PATCH 6/9] document reverb and chorus settings --- doc/fluidsettings.xml | 72 +++++++++++++++++++++++++++++++++++ doc/fluidsynth-v11-devdoc.txt | 1 + src/synth/fluid_synth.c | 6 ++- 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/doc/fluidsettings.xml b/doc/fluidsettings.xml index 6144fa68..824d4213 100644 --- a/doc/fluidsettings.xml +++ b/doc/fluidsettings.xml @@ -42,6 +42,42 @@ Developers: Settings can be deprecated by adding: SOME TEXT When set to 1 (TRUE) the chorus effects module is activated. Otherwise, no chorus will be added to the output signal. Note that the amount of signal sent to the chorus module depends on the "chorus send" generator defined in the SoundFont. + + chorus.depth + num + 8 + 0 + 21 + + Specifies the modulation depth of the chorus. + + + chorus.level + num + 2 + 0 + 10 + + Specifies the output amplitude of the chorus signal. + + + chorus.nr + int + 3 + 0 + 99 + + Sets the voice count of the chorus. + + + chorus.speed + num + 0.3 + 0.29 + 5 + + Sets the modulation speed in Hz. + cpu-cores int @@ -247,6 +283,42 @@ Developers: Settings can be deprecated by adding: SOME TEXT + + reverb.damp + num + 0 + 0 + 1 + + Sets the amount of reverb damping. + + + reverb.level + num + 0.9 + 0 + 1 + + Sets the reverb output amplitude. + + + reverb.roomsize + num + 0.2 + 0 + 1 + + Sets the room size (i.e. amount of wet) reverb. + + + reverb.width + num + 0.5 + 0 + 100 + + Sets the stereo spread of the reverb signal. + sample-rate num diff --git a/doc/fluidsynth-v11-devdoc.txt b/doc/fluidsynth-v11-devdoc.txt index 45b352bd..f556d304 100644 --- a/doc/fluidsynth-v11-devdoc.txt +++ b/doc/fluidsynth-v11-devdoc.txt @@ -116,6 +116,7 @@ Changes in FluidSynth 2.0.0 concerning developers: - add fluid_synth_add_default_mod() and fluid_synth_remove_default_mod() for manipulating default modulators - add individual reverb setters: fluid_synth_set_reverb_roomsize(), fluid_synth_set_reverb_damp(), fluid_synth_set_reverb_width(), fluid_synth_set_reverb_level() - add individual chorus setters: fluid_synth_set_chorus_nr(), fluid_synth_set_chorus_level(), fluid_synth_set_chorus_speed(), fluid_synth_set_chorus_depth(), fluid_synth_set_chorus_type() +- add realtime settings for reverb and chorus parameters - introduce a separate data type for sequencer client IDs: #fluid_seq_id_t - add seek support to midi-player, see fluid_player_seek() - expose functions to manipulate the ladspa effects unit (see ladspa.h) diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 4bcabce5..8d2e8112 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -3429,7 +3429,7 @@ fluid_synth_render_blocks(fluid_synth_t* synth, int blockcount) } /* - * Handler for synth.reverb.* settings. + * Handler for synth.reverb.* and synth.chorus.* double settings. */ static void fluid_synth_handle_reverb_chorus_num (void *data, const char *name, double value) { @@ -3459,7 +3459,9 @@ static void fluid_synth_handle_reverb_chorus_num (void *data, const char *name, } } - +/* + * Handler for synth.reverb.* and synth.chorus.* integer settings. + */ static void fluid_synth_handle_reverb_chorus_int (void *data, const char *name, int value) { fluid_synth_t *synth = (fluid_synth_t *)data; From 435361ef0ca5a7c6032bde2785b8adaaee233526 Mon Sep 17 00:00:00 2001 From: derselbst Date: Thu, 17 May 2018 20:45:09 +0200 Subject: [PATCH 7/9] rename chorus getters to match naming conventions fluid_synth_get_chorus_speed() and fluid_synth_get_chorus_depth() --- bindings/fluidmax/fluidmax.c | 12 ++++++------ doc/fluidsynth-v11-devdoc.txt | 1 + include/fluidsynth/synth.h | 4 ++-- src/synth/fluid_synth.c | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/bindings/fluidmax/fluidmax.c b/bindings/fluidmax/fluidmax.c index 06617bd1..fc6b3929 100644 --- a/bindings/fluidmax/fluidmax.c +++ b/bindings/fluidmax/fluidmax.c @@ -821,8 +821,8 @@ fluidmax_chorus(t_object *o, Symbol *s, short ac, Atom *at) } else if(ftmax_is_number(at)) { - double speed = fluid_synth_get_chorus_speed_Hz(self->synth); - double depth = fluid_synth_get_chorus_depth_ms(self->synth); + double speed = fluid_synth_get_chorus_speed(self->synth); + double depth = fluid_synth_get_chorus_depth(self->synth); int type = fluid_synth_get_chorus_type(self->synth); int nr = fluid_synth_get_chorus_nr(self->synth); @@ -1267,8 +1267,8 @@ fluidmax_print(t_object *o, Symbol *s, short ac, Atom *at) if(self->chorus != 0) { double level = fluid_synth_get_chorus_level(self->synth); - double speed = fluid_synth_get_chorus_speed_Hz(self->synth); - double depth = fluid_synth_get_chorus_depth_ms(self->synth); + double speed = fluid_synth_get_chorus_speed(self->synth); + double depth = fluid_synth_get_chorus_depth(self->synth); int type = fluid_synth_get_chorus_type(self->synth); int nr = fluid_synth_get_chorus_nr(self->synth); @@ -1477,8 +1477,8 @@ fluidmax_info(t_object *o, Symbol *s, short ac, Atom *at) if(self->chorus != 0) { double level = fluid_synth_get_chorus_level(self->synth); - double speed = fluid_synth_get_chorus_speed_Hz(self->synth); - double depth = fluid_synth_get_chorus_depth_ms(self->synth); + double speed = fluid_synth_get_chorus_speed(self->synth); + double depth = fluid_synth_get_chorus_depth(self->synth); int type = fluid_synth_get_chorus_type(self->synth); int nr = fluid_synth_get_chorus_nr(self->synth); ftmax_atom_t a[5]; diff --git a/doc/fluidsynth-v11-devdoc.txt b/doc/fluidsynth-v11-devdoc.txt index f556d304..a067df20 100644 --- a/doc/fluidsynth-v11-devdoc.txt +++ b/doc/fluidsynth-v11-devdoc.txt @@ -107,6 +107,7 @@ Changes in FluidSynth 2.0.0 concerning developers: - reverb: roomsize is now limited to an upper threshold of 1.0 to avoid exponential volume increase - use unique device names for the "audio.portaudio.device" setting - rename fluid_mod_new() and fluid_mod_delete() to match naming conventions: new_fluid_mod() and delete_fluid_mod() +- rename chorus getters to match naming conventions: fluid_synth_get_chorus_speed() and fluid_synth_get_chorus_depth() - fluid_synth_remove_sfont() returns FLUID_OK or FLUID_FAILED

- add "midi.autoconnect" a setting for automatically connecting fluidsynth to available MIDI input ports diff --git a/include/fluidsynth/synth.h b/include/fluidsynth/synth.h index 7359a88c..e1b419ef 100644 --- a/include/fluidsynth/synth.h +++ b/include/fluidsynth/synth.h @@ -159,8 +159,8 @@ FLUIDSYNTH_API int fluid_synth_set_chorus_type(fluid_synth_t* synth, int type); FLUIDSYNTH_API void fluid_synth_set_chorus_on(fluid_synth_t* synth, int on); FLUIDSYNTH_API int fluid_synth_get_chorus_nr(fluid_synth_t* synth); FLUIDSYNTH_API double fluid_synth_get_chorus_level(fluid_synth_t* synth); -FLUIDSYNTH_API double fluid_synth_get_chorus_speed_Hz(fluid_synth_t* synth); -FLUIDSYNTH_API double fluid_synth_get_chorus_depth_ms(fluid_synth_t* synth); +FLUIDSYNTH_API double fluid_synth_get_chorus_speed(fluid_synth_t* synth); +FLUIDSYNTH_API double fluid_synth_get_chorus_depth(fluid_synth_t* synth); FLUIDSYNTH_API int fluid_synth_get_chorus_type(fluid_synth_t* synth); /* see fluid_chorus_mod */ diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 8d2e8112..0f91049e 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -4564,7 +4564,7 @@ fluid_synth_get_chorus_level(fluid_synth_t* synth) * @return Chorus speed in Hz (0.29-5.0) */ double -fluid_synth_get_chorus_speed_Hz(fluid_synth_t* synth) +fluid_synth_get_chorus_speed(fluid_synth_t* synth) { double result; fluid_return_val_if_fail (synth != NULL, 0.0); @@ -4580,7 +4580,7 @@ fluid_synth_get_chorus_speed_Hz(fluid_synth_t* synth) * @return Chorus depth */ double -fluid_synth_get_chorus_depth_ms(fluid_synth_t* synth) +fluid_synth_get_chorus_depth(fluid_synth_t* synth) { double result; fluid_return_val_if_fail (synth != NULL, 0.0); From dac1fe48cc62aa0862a46da05c02ffb3699ed324 Mon Sep 17 00:00:00 2001 From: derselbst Date: Thu, 17 May 2018 21:15:48 +0200 Subject: [PATCH 8/9] check that realtime reverb and chorus settings work --- test/test_synth_chorus_reverb.c | 51 ++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/test/test_synth_chorus_reverb.c b/test/test_synth_chorus_reverb.c index 14906ea3..35db73ed 100644 --- a/test/test_synth_chorus_reverb.c +++ b/test/test_synth_chorus_reverb.c @@ -9,28 +9,51 @@ int main(void) fluid_settings_t *settings = new_fluid_settings(); TEST_ASSERT(settings != NULL); - TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.roomsize", 1.0)); - TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.damp", 1.0)); - TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.width", 1.0)); - TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.level", 1.0)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.roomsize", 0.1)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.damp", 0.2)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.width", 0.3)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.level", 0.4)); TEST_SUCCESS(fluid_settings_setint(settings, "synth.chorus.nr", 99)); - TEST_SUCCESS(fluid_settings_setnum(settings, "synth.chorus.level", 1.0)); - TEST_SUCCESS(fluid_settings_setnum(settings, "synth.chorus.speed", 1.0)); - TEST_SUCCESS(fluid_settings_setnum(settings, "synth.chorus.depth", 1.0)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.chorus.level", 0.5)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.chorus.speed", 0.6)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.chorus.depth", 0.7)); synth = new_fluid_synth(settings); TEST_ASSERT(synth != NULL); - TEST_ASSERT(fluid_synth_get_reverb_roomsize(synth) == 1.0); - TEST_ASSERT(fluid_synth_get_reverb_damp(synth) == 1.0); - TEST_ASSERT(fluid_synth_get_reverb_width(synth) == 1.0); - TEST_ASSERT(fluid_synth_get_reverb_level(synth) == 1.0); + // check that the synth is initialized with the correct values + TEST_ASSERT(fluid_synth_get_reverb_roomsize(synth) == 0.1); + TEST_ASSERT(fluid_synth_get_reverb_damp(synth) == 0.2); + TEST_ASSERT(fluid_synth_get_reverb_width(synth) == 0.3); + TEST_ASSERT(fluid_synth_get_reverb_level(synth) == 0.4); TEST_ASSERT(fluid_synth_get_chorus_nr(synth) == 99); - TEST_ASSERT(fluid_synth_get_chorus_level(synth) == 1.0); - TEST_ASSERT(fluid_synth_get_chorus_speed_Hz(synth) == 1.0); - TEST_ASSERT(fluid_synth_get_chorus_depth_ms(synth) == 1.0); + TEST_ASSERT(fluid_synth_get_chorus_level(synth) == 0.5); + TEST_ASSERT(fluid_synth_get_chorus_speed(synth) == 0.6); + TEST_ASSERT(fluid_synth_get_chorus_depth(synth) == 0.7); + + // update the realtime settings afterward + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.roomsize", 0.11)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.damp", 0.22)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.width", 0.33)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.level", 0.44)); + + TEST_SUCCESS(fluid_settings_setint(settings, "synth.chorus.nr", 11)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.chorus.level", 0.55)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.chorus.speed", 0.66)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.chorus.depth", 0.77)); + + // check that the realtime settings correctly update the values in the synth + TEST_ASSERT(fluid_synth_get_reverb_roomsize(synth) == 0.11); + TEST_ASSERT(fluid_synth_get_reverb_damp(synth) == 0.22); + TEST_ASSERT(fluid_synth_get_reverb_width(synth) == 0.33); + TEST_ASSERT(fluid_synth_get_reverb_level(synth) == 0.44); + + TEST_ASSERT(fluid_synth_get_chorus_nr(synth) == 11); + TEST_ASSERT(fluid_synth_get_chorus_level(synth) == 0.55); + TEST_ASSERT(fluid_synth_get_chorus_speed(synth) == 0.66); + TEST_ASSERT(fluid_synth_get_chorus_depth(synth) == 0.77); delete_fluid_synth(synth); delete_fluid_settings(settings); From 0188cd9d93c85b07122ce4a7880231d37a855fcf Mon Sep 17 00:00:00 2001 From: derselbst Date: Thu, 17 May 2018 21:44:03 +0200 Subject: [PATCH 9/9] rename reverb roomsize setting to match naming conventions --- doc/fluidsettings.xml | 2 +- src/bindings/fluid_cmd.c | 2 +- src/synth/fluid_synth.c | 8 ++++---- test/test_synth_chorus_reverb.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/fluidsettings.xml b/doc/fluidsettings.xml index 824d4213..378d7442 100644 --- a/doc/fluidsettings.xml +++ b/doc/fluidsettings.xml @@ -302,7 +302,7 @@ Developers: Settings can be deprecated by adding: SOME TEXT
- reverb.roomsize + reverb.room-size num 0.2 0 diff --git a/src/bindings/fluid_cmd.c b/src/bindings/fluid_cmd.c index 3f1ef62a..3eccdcc3 100644 --- a/src/bindings/fluid_cmd.c +++ b/src/bindings/fluid_cmd.c @@ -832,7 +832,7 @@ fluid_handle_reverbsetroomsize(void* data, int ac, char** av, fluid_ostream_t ou return FLUID_FAILED; } - fluid_ostream_printf(out, "rev_setroomsize is deprecated! Use 'set synth.reverb.roomsize %s' instead.\n", av[0]); + fluid_ostream_printf(out, "rev_setroomsize is deprecated! Use 'set synth.reverb.room-size %s' instead.\n", av[0]); room_size = atof(av[0]); if (room_size < 0){ diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 0f91049e..5e10851e 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -197,7 +197,7 @@ void fluid_synth_settings(fluid_settings_t* settings) fluid_settings_register_int(settings, "synth.verbose", 0, 0, 1, FLUID_HINT_TOGGLED); fluid_settings_register_int(settings, "synth.reverb.active", 1, 0, 1, FLUID_HINT_TOGGLED); - fluid_settings_register_num(settings, "synth.reverb.roomsize", FLUID_REVERB_DEFAULT_ROOMSIZE, 0.0f, 1.0f, 0); + fluid_settings_register_num(settings, "synth.reverb.room-size", FLUID_REVERB_DEFAULT_ROOMSIZE, 0.0f, 1.0f, 0); fluid_settings_register_num(settings, "synth.reverb.damp", FLUID_REVERB_DEFAULT_DAMP, 0.0f, 1.0f, 0); fluid_settings_register_num(settings, "synth.reverb.width", FLUID_REVERB_DEFAULT_WIDTH, 0.0f, 100.0f, 0); fluid_settings_register_num(settings, "synth.reverb.level", FLUID_REVERB_DEFAULT_LEVEL, 0.0f, 1.0f, 0); @@ -654,7 +654,7 @@ new_fluid_synth(fluid_settings_t *settings) fluid_synth_handle_overflow, synth); fluid_settings_callback_str(settings, "synth.overflow.important-channels", fluid_synth_handle_important_channels, synth); - fluid_settings_callback_num(settings, "synth.reverb.roomsize", + fluid_settings_callback_num(settings, "synth.reverb.room-size", fluid_synth_handle_reverb_chorus_num, synth); fluid_settings_callback_num(settings, "synth.reverb.damp", fluid_synth_handle_reverb_chorus_num, synth); @@ -835,7 +835,7 @@ new_fluid_synth(fluid_settings_t *settings) { double room, damp, width, level; - fluid_settings_getnum(settings, "synth.reverb.roomsize", &room); + fluid_settings_getnum(settings, "synth.reverb.room-size", &room); fluid_settings_getnum(settings, "synth.reverb.damp", &damp); fluid_settings_getnum(settings, "synth.reverb.width", &width); fluid_settings_getnum(settings, "synth.reverb.level", &level); @@ -3436,7 +3436,7 @@ static void fluid_synth_handle_reverb_chorus_num (void *data, const char *name, fluid_synth_t *synth = (fluid_synth_t *)data; fluid_return_if_fail(synth != NULL); - if (FLUID_STRCMP(name, "synth.reverb.roomsize") == 0) { + if (FLUID_STRCMP(name, "synth.reverb.room-size") == 0) { fluid_synth_set_reverb_roomsize(synth, value); } else if (FLUID_STRCMP(name, "synth.reverb.damp") == 0) { diff --git a/test/test_synth_chorus_reverb.c b/test/test_synth_chorus_reverb.c index 35db73ed..ac2c0baa 100644 --- a/test/test_synth_chorus_reverb.c +++ b/test/test_synth_chorus_reverb.c @@ -9,7 +9,7 @@ int main(void) fluid_settings_t *settings = new_fluid_settings(); TEST_ASSERT(settings != NULL); - TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.roomsize", 0.1)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.room-size", 0.1)); TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.damp", 0.2)); TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.width", 0.3)); TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.level", 0.4)); @@ -34,7 +34,7 @@ int main(void) TEST_ASSERT(fluid_synth_get_chorus_depth(synth) == 0.7); // update the realtime settings afterward - TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.roomsize", 0.11)); + TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.room-size", 0.11)); TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.damp", 0.22)); TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.width", 0.33)); TEST_SUCCESS(fluid_settings_setnum(settings, "synth.reverb.level", 0.44));