Add special cases for the rate transformation in envelopes

For increasing linear ramps, a 0s ramp is an increment of 1.0
For decaying exponential ramps, a 0s ramp is a multiplicator of 0.0f
This commit is contained in:
Paul Ferrand 2020-08-19 19:12:33 +02:00
parent fae0cda971
commit f6e0bb8b3f

View file

@ -20,13 +20,18 @@ Type ADSREnvelope<Type>::secondsToSamples (Type timeInSeconds) const noexcept
template<class Type>
Type ADSREnvelope<Type>::secondsToLinRate (Type timeInSeconds) const noexcept
{
timeInSeconds = std::max<Type>(timeInSeconds, config::virtuallyZero);
if (timeInSeconds == 0)
return 1.0f;
return 1 / (sampleRate * timeInSeconds);
};
template<class Type>
Type ADSREnvelope<Type>::secondsToExpRate (Type timeInSeconds) const noexcept
{
if (timeInSeconds == 0)
return 0.0f;
timeInSeconds = std::max<Type>(25e-3, timeInSeconds);
return std::exp(-9.0 / (timeInSeconds * sampleRate));
};