mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2025-03-01 07:00:44 +00:00
Fix minor bug in lower_boundary_for_attenuation()
- v variable is renamed min_val for clarity. - This fix a bug when calculating the possible minimun value (min_val) of a modulator. min_val should only be dependant of: - signs of mapped sources (ie bipolar [-1..+1] or unipolar [0..+1]) - sign of amount. - absolute value of amount.
This commit is contained in:
parent
ef5739f3ce
commit
06bca9b894
1 changed files with 23 additions and 10 deletions
|
@ -1696,9 +1696,10 @@ int fluid_voice_get_velocity(const fluid_voice_t *voice)
|
||||||
* A lower boundary for the attenuation (as in 'the minimum
|
* A lower boundary for the attenuation (as in 'the minimum
|
||||||
* attenuation of this voice, with volume pedals, modulators
|
* attenuation of this voice, with volume pedals, modulators
|
||||||
* etc. resulting in minimum attenuation, cannot fall below x cB) is
|
* etc. resulting in minimum attenuation, cannot fall below x cB) is
|
||||||
* calculated. This has to be called during fluid_voice_init, after
|
* calculated. This has to be called during fluid_voice_start, after
|
||||||
* all modulators have been run on the voice once. Also,
|
* all modulators have been run on the voice once. Also,
|
||||||
* voice->attenuation has to be initialized.
|
* voice->attenuation has to be initialized.
|
||||||
|
* (see fluid_voice_calculate_runtime_synthesis_parameters())
|
||||||
*/
|
*/
|
||||||
static fluid_real_t
|
static fluid_real_t
|
||||||
fluid_voice_get_lower_boundary_for_attenuation(fluid_voice_t *voice)
|
fluid_voice_get_lower_boundary_for_attenuation(fluid_voice_t *voice)
|
||||||
|
@ -1725,30 +1726,42 @@ fluid_voice_get_lower_boundary_for_attenuation(fluid_voice_t *voice)
|
||||||
{
|
{
|
||||||
|
|
||||||
fluid_real_t current_val = fluid_mod_get_value(mod, voice);
|
fluid_real_t current_val = fluid_mod_get_value(mod, voice);
|
||||||
fluid_real_t v = fabs(mod->amount);
|
/* min_val is the possible minimum value for this modulator.
|
||||||
|
it depends of 3 things :
|
||||||
|
1)the minimum values of src1,src2 (i.e -1 if mapping is bipolar
|
||||||
|
or 0 if mapping is unipolar).
|
||||||
|
2)the sign of amount.
|
||||||
|
3)absolute value of amount.
|
||||||
|
|
||||||
if((mod->src1 == FLUID_MOD_PITCHWHEEL)
|
When at least one source mapping is bipolar:
|
||||||
|| (mod->flags1 & FLUID_MOD_BIPOLAR)
|
min_val is -|amount| regardless the sign of amount.
|
||||||
|
When both sources mapping are unipolar:
|
||||||
|
min_val is -|amount|, if amount is negative.
|
||||||
|
min_val is 0, if amount is positive
|
||||||
|
*/
|
||||||
|
fluid_real_t min_val = fabs(mod->amount);
|
||||||
|
|
||||||
|
/* Can this modulator produce a negative contribution? */
|
||||||
|
if((mod->flags1 & FLUID_MOD_BIPOLAR)
|
||||||
|| (mod->flags2 & FLUID_MOD_BIPOLAR)
|
|| (mod->flags2 & FLUID_MOD_BIPOLAR)
|
||||||
|| (mod->amount < 0))
|
|| (mod->amount < 0))
|
||||||
{
|
{
|
||||||
/* Can this modulator produce a negative contribution? */
|
min_val *= -1.0; /* min_val = - |amount|*/
|
||||||
v *= -1.0;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* No negative value possible. But still, the minimum contribution is 0. */
|
/* No negative value possible. But still, the minimum contribution is 0. */
|
||||||
v = 0;
|
min_val = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For example:
|
/* For example:
|
||||||
* - current_val=100
|
* - current_val=100
|
||||||
* - min_val=-4000
|
* - min_val=-4000
|
||||||
* - possible_att_reduction_cB += 4100
|
* - possible reduction contribution of this modulator = current_val - min_val = 4100
|
||||||
*/
|
*/
|
||||||
if(current_val > v)
|
if(current_val > min_val)
|
||||||
{
|
{
|
||||||
possible_att_reduction_cB += (current_val - v);
|
possible_att_reduction_cB += (current_val - min_val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue