51template <
typename FloatType>
63 this->currentValue = initialValue;
64 this->target = initialValue;
78 void setLogParameters (FloatType midPointAmplitudedB,
bool rateOfChangeShouldIncrease)
noexcept
80 jassert (midPointAmplitudedB < (FloatType) 0.0);
83 increasingRateOfChange = rateOfChangeShouldIncrease;
91 void reset (
double sampleRate,
double rampLengthInSeconds)
noexcept
93 jassert (sampleRate > 0 && rampLengthInSeconds >= 0);
94 reset ((
int) std::floor (rampLengthInSeconds * sampleRate));
102 stepsToTarget = numSteps;
106 updateRampParameters();
116 if (newValue == this->target)
119 if (stepsToTarget <= 0)
125 this->target = newValue;
126 this->countdown = stepsToTarget;
127 source = this->currentValue;
129 updateRampParameters();
143 temp *= r; temp += d;
144 this->currentValue = jmap (temp, source, this->target);
146 return this->currentValue;
155 FloatType
skip (
int numSamples)
noexcept
157 if (numSamples >= this->countdown)
163 this->countdown -= numSamples;
165 auto rN = (FloatType) std::pow (r, numSamples);
167 temp += d * (rN - (FloatType) 1) / (r - (FloatType) 1);
169 this->currentValue = jmap (temp, source, this->target);
170 return this->currentValue;
175 void updateRampParameters()
177 auto D = increasingRateOfChange ? B : (FloatType) 1 - B;
178 auto base = ((FloatType) 1 / D) - (FloatType) 1;
179 r = std::pow (base, (FloatType) 2 / (FloatType) stepsToTarget);
180 auto rN = std::pow (r, (FloatType) stepsToTarget);
181 d = (r - (FloatType) 1) / (rN - (FloatType) 1);
186 bool increasingRateOfChange =
true;
189 int stepsToTarget = 0;
190 FloatType temp = 0, source = 0, r = 0, d = 1;
static Type decibelsToGain(Type decibels, Type minusInfinityDb=Type(defaultMinusInfinitydB))
Converts a dBFS value to its equivalent gain level.
A base class for the smoothed value classes.
bool isSmoothing() const noexcept
Returns true if the current value is currently being interpolated.
void setCurrentAndTargetValue(FloatType newValue)
Sets the current value and the target value.
Utility class for logarithmically smoothed linear values.
LogRampedValue()=default
Constructor.
FloatType getNextValue() noexcept
Compute the next value.
void reset(double sampleRate, double rampLengthInSeconds) noexcept
Reset to a new sample rate and ramp length.
void setLogParameters(FloatType midPointAmplitudedB, bool rateOfChangeShouldIncrease) noexcept
Sets the behaviour of the log ramp.
FloatType skip(int numSamples) noexcept
Skip the next numSamples samples.
LogRampedValue(FloatType initialValue) noexcept
Constructor.
void reset(int numSteps) noexcept
Set a new ramp length directly in samples.
void setTargetValue(FloatType newValue) noexcept
Set a new target value.