Potential fix for #1059

Apply Christian's decay to sustain transition hack to modenv as well.
This commit is contained in:
derselbst 2022-03-05 18:41:19 +01:00
parent 122066ca6d
commit 344796a6a8
2 changed files with 5 additions and 4 deletions

View file

@ -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;
}

View file

@ -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 **********************/