42template <std::
floating_po
int FloatType>
43constexpr FloatType
addModulo2Pi (FloatType phase, FloatType increment)
noexcept
46 while (phase > twoPi<FloatType>)
48 phase -= twoPi<FloatType>;
62template <std::
floating_po
int FloatType>
63constexpr FloatType
scale (FloatType sourceValue,
64 FloatType sourceRangeMin,
65 FloatType sourceRangeMax,
66 FloatType targetRangeMin,
67 FloatType targetRangeMax)
70 + ((targetRangeMax - targetRangeMin) * (sourceValue - sourceRangeMin)) / (sourceRangeMax - sourceRangeMin);
76template <std::
floating_po
int FloatType>
79 static_assert (! std::is_const<FloatType>::value,
"FloatType is must NOT be const.");
110 void reset (FloatType newValue)
noexcept
113 currentValue = newValue;
122 stepsToTarget = numSteps;
130 if (newValue == target)
135 if (stepsToTarget <= 0)
142 countdown = stepsToTarget;
159 currentValue += step;
163 currentValue = target;
171 step = (target - currentValue) / stepsToTarget;
174 FloatType currentValue {};
178 int stepsToTarget {};
186template <std::
floating_po
int FloatType>
189 static_assert (! std::is_const<FloatType>::value,
"FloatType is must NOT be const.");
198 Slide (FloatType slownessOfIncrease, FloatType slownessOfDecrease)
noexcept
200 slideUp.store (slownessOfIncrease);
201 slideDown.store (slownessOfDecrease);
211 assert (slownessIncrease >= 1.0f);
212 slideUp.store (slownessIncrease);
221 assert (slownessDecrease >= 1.0f);
222 slideDown.store (slownessDecrease);
231 const auto dt = input - lastOutput;
232 const auto s = dt > FloatType (0.0) ? slideUp.load() : slideDown.load();
233 lastOutput = lastOutput + dt / s;
238 FloatType lastOutput {};
239 std::atomic<FloatType> slideUp { 1.0 };
240 std::atomic<FloatType> slideDown { 1.0 };
245 template <
typename T>
246 concept signed_number = std::signed_integral<T> || std::floating_point<T>;
252template <
signed_number T>
259 explicit Wrap (T length) : length (length)
290 [[nodiscard]] T
get (T offset = 0) const noexcept
292 auto n = num + offset;
313 [[nodiscard]] T getLength() const noexcept
352 while (num >= length)
379template <
typename... Ts>
380constexpr std::array<std::byte,
sizeof...(Ts)> makeBytes (Ts&&... args)
noexcept
382 return { std::byte (std::forward<Ts> (args))... };
constexpr FloatType addModulo2Pi(FloatType phase, FloatType increment) noexcept
Increment the phase and returns in the range of 0~2pi.
Definition: ame_Util.hpp:43
constexpr FloatType scale(FloatType sourceValue, FloatType sourceRangeMin, FloatType sourceRangeMax, FloatType targetRangeMin, FloatType targetRangeMax)
Map values to an output range.
Definition: ame_Util.hpp:63
Smooth values linearly.
Definition: ame_Util.hpp:78
void setRampLength(const int numSteps) noexcept
Set a new ramp length in samples.
Definition: ame_Util.hpp:120
void reset(FloatType newValue) noexcept
Reset the currentValue, targetValue and ramp count.
Definition: ame_Util.hpp:110
void setTargetValue(FloatType newValue) noexcept
Set the next value to ramp towards.
Definition: ame_Util.hpp:128
FloatType getNextValue() noexcept
Compute the smoothed value.
Definition: ame_Util.hpp:149
FloatType getTargetValue() const noexcept
Returns the target value towards which the smoothed value is currently moving.
Definition: ame_Util.hpp:102
FloatType getCurrentValue() const noexcept
Returns the current value to the ramp.
Definition: ame_Util.hpp:96
bool isSmoothing() const noexcept
Returns true if the current value is currently being interpolated.
Definition: ame_Util.hpp:90
Smooth values logarithmically.
Definition: ame_Util.hpp:188
void setSlownessOfIncrease(FloatType slownessIncrease)
Set the slowness of the increase.
Definition: ame_Util.hpp:209
Slide(FloatType slownessOfIncrease, FloatType slownessOfDecrease) noexcept
Create an Slide object.
Definition: ame_Util.hpp:198
FloatType process(FloatType input) noexcept
Filter an input value
Definition: ame_Util.hpp:229
void setSlownessOfDecrease(FloatType slownessDecrease)
Set the slowness of the decrease.
Definition: ame_Util.hpp:219
A number to wrap between 0~length.
Definition: ame_Util.hpp:254
T operator+=(T add) noexcept
+= operator.
Definition: ame_Util.hpp:349
Wrap(T length)
Definition: ame_Util.hpp:259
void changeLength(T newLength) noexcept
The number to automatically wrap in the range [0, length-1].
Definition: ame_Util.hpp:308
T get(T offset=0) const noexcept
Get the current value or the number of the current value plus an offset.
Definition: ame_Util.hpp:290
T operator++() noexcept
Prefix increment.
Definition: ame_Util.hpp:321
void set(T n)
Sets the current value to an arbitrary number.
Definition: ame_Util.hpp:271
範囲を表す構造体.
Definition: ame_Util.hpp:29