Skip to content

Commit

Permalink
Fix modLfoToVol behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
derselbst committed Sep 8, 2024
1 parent 7f39048 commit cb4244b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/utils/fluid_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,20 @@ fluid_cb2amp(fluid_real_t cb)
*/

/* minimum attenuation: 0 dB */
if(cb < 0)
if(FLUID_UNLIKELY(cb < 0))
{
return 1.0;
/* Issue #1374: it seems that by using modLfoToVolEnv, the attenuation can become negative and
* therefore the signal needs to be amplified.
* In such a rare case, calculate the attenuation on the fly.
*
* This behavior is backed by the spec saying:
* modLfoToVolume: "A positive number indicates a positive LFO excursion increases volume;
* a negative number indicates a positive excursion decreases volume.
* [...] For example, a value of 100 indicates that the volume will first rise ten dB, then fall ten dB."
*
* And in order to rise, a negative attenuation must be permitted.
*/
return FLUID_POW(10.0f, cb / -200.0f);
}

if(cb >= FLUID_CB_AMP_SIZE)
Expand Down

0 comments on commit cb4244b

Please sign in to comment.