From 29f6ac104913fe348e538b04f4bbfc65adbd2a28 Mon Sep 17 00:00:00 2001 From: derselbst Date: Thu, 7 Sep 2017 11:42:01 +0200 Subject: [PATCH 1/8] add setting for volume envelope processing fixes #70 --- src/synth/fluid_synth.c | 14 +++++++++++++- src/utils/fluid_conv.c | 11 +++++++++++ src/utils/fluid_conv.h | 8 +++----- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index c44baf88..ff7a5f3f 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -224,6 +224,7 @@ void fluid_synth_settings(fluid_settings_t* settings) fluid_settings_add_option(settings, "synth.midi-bank-select", "xg"); fluid_settings_add_option(settings, "synth.midi-bank-select", "mma"); + fluid_settings_register_str(settings, "synth.volenv", "emu", 0, NULL, NULL); } /** @@ -554,8 +555,19 @@ new_fluid_synth(fluid_settings_t *settings) double gain; int i, nbuf; + /* initialize all the conversion tables and other stuff */ - if (fluid_synth_initialized == 0) { + if (fluid_synth_initialized == 0) + { + char* buf; + if(fluid_settings_getstr(settings, "synth.volenv", &buf)) + { + if(FLUID_STRCMP(buf, "compliant") == 0) + fluid_conversion_set_atten_power(FLUID_ATTEN_POWER_DEFAULT_COMPLIANT); + else + fluid_conversion_set_atten_power(FLUID_ATTEN_POWER_DEFAULT_EMU); + } + fluid_synth_init(); } diff --git a/src/utils/fluid_conv.c b/src/utils/fluid_conv.c index 50ab1010..6a3ee103 100644 --- a/src/utils/fluid_conv.c +++ b/src/utils/fluid_conv.c @@ -21,6 +21,12 @@ #include "fluid_conv.h" +/* EMU 8k/10k don't follow spec in regards to volume attenuation. + * This factor is used in the equation pow (10.0, cb / FLUID_ATTEN_POWER_FACTOR). + * By the standard this should be -200.0. */ +/* 07/11/2008 modified by S. Christian Collins for increased velocity sensitivity. Now it equals the response of EMU10K1 programming.*/ +static double FLUID_ATTEN_POWER_FACTOR = FLUID_ATTEN_POWER_DEFAULT_EMU; /* was (-531.509)*/ + /* conversion tables */ fluid_real_t fluid_ct2hz_tab[FLUID_CENTS_HZ_SIZE]; fluid_real_t fluid_cb2amp_tab[FLUID_CB_AMP_SIZE]; @@ -91,6 +97,11 @@ fluid_conversion_config(void) } } +void fluid_conversion_set_atten_power(double atten) +{ + FLUID_ATTEN_POWER_FACTOR = atten; +} + /* * fluid_ct2hz */ diff --git a/src/utils/fluid_conv.h b/src/utils/fluid_conv.h index f0b91168..838b1496 100644 --- a/src/utils/fluid_conv.h +++ b/src/utils/fluid_conv.h @@ -29,13 +29,11 @@ #define FLUID_ATTEN_AMP_SIZE 1441 #define FLUID_PAN_SIZE 1002 -/* EMU 8k/10k don't follow spec in regards to volume attenuation. - * This factor is used in the equation pow (10.0, cb / FLUID_ATTEN_POWER_FACTOR). - * By the standard this should be -200.0. */ -/* 07/11/2008 modified by S. Christian Collins for increased velocity sensitivity. Now it equals the response of EMU10K1 programming.*/ -#define FLUID_ATTEN_POWER_FACTOR (-200.0) /* was (-531.509)*/ +#define FLUID_ATTEN_POWER_DEFAULT_EMU (-200.0) +#define FLUID_ATTEN_POWER_DEFAULT_COMPLIANT (-531.509) void fluid_conversion_config(void); +void fluid_conversion_set_atten_power(double atten); fluid_real_t fluid_ct2hz_real(fluid_real_t cents); fluid_real_t fluid_ct2hz(fluid_real_t cents); From 65193c6f945cb89dbb3322b974c51465833992cf Mon Sep 17 00:00:00 2001 From: derselbst Date: Thu, 7 Sep 2017 13:42:44 +0200 Subject: [PATCH 2/8] document "synth.volenv" --- doc/fluidsynth-v11-devdoc.txt | 27 ++++++++++++++++++++++++++- doc/fluidsynth.1 | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/doc/fluidsynth-v11-devdoc.txt b/doc/fluidsynth-v11-devdoc.txt index 1b963824..b80ed29e 100644 --- a/doc/fluidsynth-v11-devdoc.txt +++ b/doc/fluidsynth-v11-devdoc.txt @@ -641,7 +641,6 @@ is one, midi driver is one, midi player is one etc) so you should usually leave it on. Also see synth.parallel-render. - synth.verbose Type @@ -660,6 +659,32 @@ leave it on. Also see synth.parallel-render. can be helpful for debugging. This setting cannot be changed after the synthesizer has started. + + + synth.volenv + Type + string + + + + Default + emu + + + + Options + compliant, emu + + + + Description + Specifies the kind of volume envelope processing. This + esp. influences the way fluidsynth responses to noteon velocity. + The default setting 'emu' causes the envelope to be highly + dynamic (i.e. compatible with the EMU10K1). Alternatively this + may be set to 'compliant' for a less dynamic envelope, as it was + done before fluidsynth 1.0.9. + \section CreatingAudioDriver Creating the Audio Driver diff --git a/doc/fluidsynth.1 b/doc/fluidsynth.1 index 5ca03981..4c5c838c 100644 --- a/doc/fluidsynth.1 +++ b/doc/fluidsynth.1 @@ -221,6 +221,9 @@ Must always to be true for usage by fluidsynth executable. .TP .B synth.verbose BOOL [def=False] Print received MIDI events to stdout. +.TP +.B synth.volenv STR [def='emu' vals:'compliant', 'emu'] +Specifies the kind of volume envelope processing. This esp. influences the way fluidsynth responses to noteon velocity. The default setting 'emu' causes the envelope to be highly dynamic (i.e. compatible with the EMU10K1). Alternatively this may be set to 'compliant' for a less dynamic envelope, as it was done before fluidsynth 1.0.9. .TP .B GENERAL AUDIO From bc12b61e4a387072607660972b5c31ab8d110e84 Mon Sep 17 00:00:00 2001 From: derselbst Date: Sat, 9 Sep 2017 16:00:00 +0200 Subject: [PATCH 3/8] allow any double string value for "synth.volenv" --- src/synth/fluid_synth.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index ff7a5f3f..3fc5759d 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -564,8 +564,16 @@ new_fluid_synth(fluid_settings_t *settings) { if(FLUID_STRCMP(buf, "compliant") == 0) fluid_conversion_set_atten_power(FLUID_ATTEN_POWER_DEFAULT_COMPLIANT); - else + else if(FLUID_STRCMP(buf, "emu") == 0) fluid_conversion_set_atten_power(FLUID_ATTEN_POWER_DEFAULT_EMU); + else + { + double atten = atof(buf); + if(atten != 0.0) + fluid_conversion_set_atten_power(atten); + else + fluid_conversion_set_atten_power(FLUID_ATTEN_POWER_DEFAULT_EMU); + } } fluid_synth_init(); From ca92dbbc94cf547b4251be8cc9eb16e1365b9439 Mon Sep 17 00:00:00 2001 From: derselbst Date: Tue, 19 Sep 2017 10:54:58 +0200 Subject: [PATCH 4/8] correctly register synth.volenv options --- src/synth/fluid_synth.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 3fc5759d..aa5bd15a 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -225,6 +225,8 @@ void fluid_synth_settings(fluid_settings_t* settings) fluid_settings_add_option(settings, "synth.midi-bank-select", "mma"); fluid_settings_register_str(settings, "synth.volenv", "emu", 0, NULL, NULL); + fluid_settings_add_option(settings, "synth.volenv", "emu"); + fluid_settings_add_option(settings, "synth.volenv", "compliant"); } /** @@ -559,20 +561,22 @@ new_fluid_synth(fluid_settings_t *settings) /* initialize all the conversion tables and other stuff */ if (fluid_synth_initialized == 0) { - char* buf; - if(fluid_settings_getstr(settings, "synth.volenv", &buf)) + char buf[64]; + if (fluid_settings_str_equal (settings, "synth.volenv", "compliant") == 1) { - if(FLUID_STRCMP(buf, "compliant") == 0) fluid_conversion_set_atten_power(FLUID_ATTEN_POWER_DEFAULT_COMPLIANT); - else if(FLUID_STRCMP(buf, "emu") == 0) + } + else if (fluid_settings_str_equal (settings, "synth.volenv", "emu") == 1) + { fluid_conversion_set_atten_power(FLUID_ATTEN_POWER_DEFAULT_EMU); - else + } + else + { + if (fluid_settings_copystr(settings, "synth.volenv", buf, 64) == 1) { double atten = atof(buf); if(atten != 0.0) fluid_conversion_set_atten_power(atten); - else - fluid_conversion_set_atten_power(FLUID_ATTEN_POWER_DEFAULT_EMU); } } From 471cbffc20f43894916856ade4c9e93bad050d20 Mon Sep 17 00:00:00 2001 From: derselbst Date: Tue, 19 Sep 2017 11:06:03 +0200 Subject: [PATCH 5/8] update synth.volenv doc --- doc/fluidsynth-v11-devdoc.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/fluidsynth-v11-devdoc.txt b/doc/fluidsynth-v11-devdoc.txt index b80ed29e..9e732d35 100644 --- a/doc/fluidsynth-v11-devdoc.txt +++ b/doc/fluidsynth-v11-devdoc.txt @@ -683,7 +683,10 @@ leave it on. Also see synth.parallel-render. The default setting 'emu' causes the envelope to be highly dynamic (i.e. compatible with the EMU10K1). Alternatively this may be set to 'compliant' for a less dynamic envelope, as it was - done before fluidsynth 1.0.9. + done before fluidsynth 1.0.9. Note that this setting can only be + changed until the first synth has been created. Changing it + afterwards will have no effect for the rest of fluidsynths + lifetime. From d708c2f5e2504ba155168d1d15d6bf003a04410b Mon Sep 17 00:00:00 2001 From: derselbst Date: Tue, 19 Sep 2017 17:12:14 +0200 Subject: [PATCH 6/8] specify bufsize via sizeof() --- src/synth/fluid_synth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index aa5bd15a..9fad26e7 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -572,7 +572,7 @@ new_fluid_synth(fluid_settings_t *settings) } else { - if (fluid_settings_copystr(settings, "synth.volenv", buf, 64) == 1) + if (fluid_settings_copystr(settings, "synth.volenv", buf, sizeof(buf)/sizeof(buf[0])) == 1) { double atten = atof(buf); if(atten != 0.0) From 7bf280cf7701344cbaceacaaec2030499f3edca6 Mon Sep 17 00:00:00 2001 From: derselbst Date: Tue, 19 Sep 2017 17:12:33 +0200 Subject: [PATCH 7/8] linebreak --- src/utils/fluid_conv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/fluid_conv.c b/src/utils/fluid_conv.c index 6a3ee103..13ea6b5e 100644 --- a/src/utils/fluid_conv.c +++ b/src/utils/fluid_conv.c @@ -24,7 +24,8 @@ /* EMU 8k/10k don't follow spec in regards to volume attenuation. * This factor is used in the equation pow (10.0, cb / FLUID_ATTEN_POWER_FACTOR). * By the standard this should be -200.0. */ -/* 07/11/2008 modified by S. Christian Collins for increased velocity sensitivity. Now it equals the response of EMU10K1 programming.*/ +/* 07/11/2008 modified by S. Christian Collins for increased velocity sensitivity. + * Now it equals the response of EMU10K1 programming.*/ static double FLUID_ATTEN_POWER_FACTOR = FLUID_ATTEN_POWER_DEFAULT_EMU; /* was (-531.509)*/ /* conversion tables */ From 3c99490a60f25a97c7e3501fef351232f297ef01 Mon Sep 17 00:00:00 2001 From: derselbst Date: Wed, 20 Sep 2017 20:13:18 +0200 Subject: [PATCH 8/8] check for new return values of fluid_settings_*() --- src/synth/fluid_synth.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 9fad26e7..25d59790 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -562,17 +562,17 @@ new_fluid_synth(fluid_settings_t *settings) if (fluid_synth_initialized == 0) { char buf[64]; - if (fluid_settings_str_equal (settings, "synth.volenv", "compliant") == 1) + if (fluid_settings_str_equal (settings, "synth.volenv", "compliant") == FLUID_OK) { fluid_conversion_set_atten_power(FLUID_ATTEN_POWER_DEFAULT_COMPLIANT); } - else if (fluid_settings_str_equal (settings, "synth.volenv", "emu") == 1) + else if (fluid_settings_str_equal (settings, "synth.volenv", "emu") == FLUID_OK) { fluid_conversion_set_atten_power(FLUID_ATTEN_POWER_DEFAULT_EMU); } else { - if (fluid_settings_copystr(settings, "synth.volenv", buf, sizeof(buf)/sizeof(buf[0])) == 1) + if (fluid_settings_copystr(settings, "synth.volenv", buf, sizeof(buf)/sizeof(buf[0])) == FLUID_OK) { double atten = atof(buf); if(atten != 0.0)