From 122066ca6d87d1b5527697283adb834e0244e4f0 Mon Sep 17 00:00:00 2001 From: derselbst Date: Sat, 5 Mar 2022 18:18:28 +0100 Subject: [PATCH 1/3] Cosmetic changes --- src/rvoice/fluid_adsr_env.h | 10 ++++------ src/synth/fluid_voice.c | 3 ++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/rvoice/fluid_adsr_env.h b/src/rvoice/fluid_adsr_env.h index 9ed652d0b..7c069b8d6 100644 --- a/src/rvoice/fluid_adsr_env.h +++ b/src/rvoice/fluid_adsr_env.h @@ -37,7 +37,7 @@ struct _fluid_env_data_t }; /* Indices for envelope tables */ -enum fluid_voice_envelope_index_t +enum fluid_voice_envelope_index { FLUID_VOICE_ENVDELAY, FLUID_VOICE_ENVATTACK, @@ -49,7 +49,7 @@ enum fluid_voice_envelope_index_t FLUID_VOICE_ENVLAST }; -typedef enum fluid_voice_envelope_index_t fluid_adsr_env_section_t; +typedef enum fluid_voice_envelope_index fluid_adsr_env_section_t; typedef struct _fluid_adsr_env_t fluid_adsr_env_t; @@ -57,8 +57,8 @@ struct _fluid_adsr_env_t { fluid_env_data_t data[FLUID_VOICE_ENVLAST]; unsigned int count; - int section; fluid_real_t val; /* the current value of the envelope */ + fluid_adsr_env_section_t section; }; /* For performance, all functions are inlined */ @@ -106,8 +106,6 @@ fluid_adsr_env_calc(fluid_adsr_env_t *env, int is_volenv) } env->val = x; - - } /* This one cannot be inlined since it is referenced in @@ -118,7 +116,7 @@ static FLUID_INLINE void fluid_adsr_env_reset(fluid_adsr_env_t *env) { env->count = 0; - env->section = 0; + env->section = FLUID_VOICE_ENVDELAY; env->val = 0.0f; } diff --git a/src/synth/fluid_voice.c b/src/synth/fluid_voice.c index a7fa3be01..e827f9ff2 100644 --- a/src/synth/fluid_voice.c +++ b/src/synth/fluid_voice.c @@ -1110,8 +1110,9 @@ fluid_voice_update_param(fluid_voice_t *voice, int gen) /* Modulation envelope */ case GEN_MODENVDELAY: /* SF2.01 section 8.1.3 # 25 */ fluid_clip(x, -12000.0f, 5000.0f); + count = NUM_BUFFERS_DELAY(x); fluid_voice_update_modenv(voice, TRUE, FLUID_VOICE_ENVDELAY, - NUM_BUFFERS_DELAY(x), 0.0f, 0.0f, -1.0f, 1.0f); + count, 0.0f, 0.0f, -1.0f, 1.0f); break; case GEN_MODENVATTACK: /* SF2.01 section 8.1.3 # 26 */ From 344796a6a8d4fb8697358899eef1ea73005aa794 Mon Sep 17 00:00:00 2001 From: derselbst Date: Sat, 5 Mar 2022 18:41:19 +0100 Subject: [PATCH 2/3] Potential fix for #1059 Apply Christian's decay to sustain transition hack to modenv as well. --- src/rvoice/fluid_adsr_env.h | 5 +++-- src/rvoice/fluid_rvoice.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/rvoice/fluid_adsr_env.h b/src/rvoice/fluid_adsr_env.h index 7c069b8d6..5e99c6bf3 100644 --- a/src/rvoice/fluid_adsr_env.h +++ b/src/rvoice/fluid_adsr_env.h @@ -64,7 +64,7 @@ struct _fluid_adsr_env_t /* For performance, all functions are inlined */ static FLUID_INLINE void -fluid_adsr_env_calc(fluid_adsr_env_t *env, int is_volenv) +fluid_adsr_env_calc(fluid_adsr_env_t *env) { fluid_env_data_t *env_data; fluid_real_t x; @@ -76,7 +76,8 @@ fluid_adsr_env_calc(fluid_adsr_env_t *env, int is_volenv) { // If we're switching envelope stages from decay to sustain, force the value to be the end value of the previous stage // Hmm, should this only apply to volenv? It was so before refactoring, so keep it for now. [DH] - if(env->section == FLUID_VOICE_ENVDECAY && is_volenv) + // No, must apply to both, otherwise some voices may sound detuned. [TM] (https://github.com/FluidSynth/fluidsynth/issues/1059) + if(env->section == FLUID_VOICE_ENVDECAY) { env->val = env_data->min * env_data->coeff; } diff --git a/src/rvoice/fluid_rvoice.c b/src/rvoice/fluid_rvoice.c index 5f54c33b1..403a55587 100644 --- a/src/rvoice/fluid_rvoice.c +++ b/src/rvoice/fluid_rvoice.c @@ -331,7 +331,7 @@ fluid_rvoice_write(fluid_rvoice_t *voice, fluid_real_t *dsp_buf) /******************* vol env **********************/ - fluid_adsr_env_calc(&voice->envlfo.volenv, 1); + fluid_adsr_env_calc(&voice->envlfo.volenv); fluid_check_fpe("voice_write vol env"); if(fluid_adsr_env_get_section(&voice->envlfo.volenv) == FLUID_VOICE_ENVFINISHED) @@ -341,7 +341,7 @@ fluid_rvoice_write(fluid_rvoice_t *voice, fluid_real_t *dsp_buf) /******************* mod env **********************/ - fluid_adsr_env_calc(&voice->envlfo.modenv, 0); + fluid_adsr_env_calc(&voice->envlfo.modenv); fluid_check_fpe("voice_write mod env"); /******************* lfo **********************/ From 8784dbbc7454620ee2efa74c6e5e37014c0f3bd1 Mon Sep 17 00:00:00 2001 From: derselbst Date: Tue, 15 Mar 2022 21:35:32 +0100 Subject: [PATCH 3/3] Elaborate on MSB and LSB handling, #1052 --- src/synth/fluid_synth.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 636dc01e4..68ce09658 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -1557,6 +1557,10 @@ fluid_synth_remove_default_mod(fluid_synth_t *synth, const fluid_mod_t *mod) /** * Send a MIDI controller event on a MIDI channel. + * + * Most CCs are 7-bits wide in FluidSynth. There are a few exceptions which may be 14-bits wide as are documented here: + * https://github.com/FluidSynth/fluidsynth/wiki/FluidFeatures#midi-control-change-implementation-chart + * * @param synth FluidSynth instance * @param chan MIDI channel number (0 to MIDI channel count - 1) * @param num MIDI controller number (0-127) @@ -1571,6 +1575,8 @@ fluid_synth_remove_default_mod(fluid_synth_t *synth, const fluid_mod_t *mod) * could be used as CC global for all channels belonging to basic channel 7. * - Let a basic channel 0 in mode 3. If MIDI channel 15 is disabled it could be used * as CC global for all channels belonging to basic channel 0. + * @warning Contrary to the MIDI Standard, this function does not clear LSB controllers, + * when MSB controllers are received. */ int fluid_synth_cc(fluid_synth_t *synth, int chan, int num, int val)