44template <
typename FloatType>
93 void reset (
int numSteps)
noexcept
95 stepsToTarget = numSteps;
99 updateRampParameters();
112 if (stepsToTarget <= 0)
118 this->target = newValue;
119 this->countdown = stepsToTarget;
120 source = this->currentValue;
122 updateRampParameters();
136 temp *= r; temp += d;
137 this->currentValue =
jmap (temp, source, this->target);
139 return this->currentValue;
148 FloatType
skip (
int numSamples)
noexcept
150 if (numSamples >= this->countdown)
156 this->countdown -= numSamples;
158 auto rN = (FloatType)
std::pow (r, numSamples);
160 temp += d * (
rN - (FloatType) 1) / (r - (FloatType) 1);
162 this->currentValue =
jmap (temp, source, this->target);
163 return this->currentValue;
168 void updateRampParameters()
170 auto D = increasingRateOfChange ? B : (FloatType) 1 - B;
171 auto base = ((FloatType) 1 /
D) - (FloatType) 1;
172 r =
std::pow (base, (FloatType) 2 / (FloatType) stepsToTarget);
173 auto rN =
std::pow (r, (FloatType) stepsToTarget);
174 d = (r - (FloatType) 1) / (
rN - (FloatType) 1);
179 bool increasingRateOfChange =
true;
182 int stepsToTarget = 0;
183 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.
constexpr Type jmap(Type value0To1, Type targetRangeMin, Type targetRangeMax)
Remaps a normalised value (between 0 and 1) to a target range.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...