43 if (!std::isfinite(curve.strength))
44 curve.strength = 0.0f;
45 curve.strength = std::clamp(curve.strength, 0.0f, 1.0f);
54template <
typename SampleType>
56 if constexpr (std::is_same_v<SampleType, float>) {
59 const SampleType k =
static_cast<SampleType
>(
kCurveSpan) * curve;
60 if (std::abs(k) < SampleType{1.0e-8})
62 return -std::expm1(-k *
progress) / -std::expm1(-k);
68template <
typename SampleType>
71 static_assert(std::is_floating_point_v<SampleType>);
72 const SampleType p = std::isfinite(
progress)
73 ? std::clamp(
progress, SampleType{0}, SampleType{1})
77 switch (curve.shape) {
81 return p * p * (SampleType{3} - SampleType{2} * p);
83 return p >= 1.0f ? 1.0f : 0.0f;
88 p,
static_cast<SampleType
>(
rising ? -curve.strength : curve.strength));
91 p,
static_cast<SampleType
>(
rising ? curve.strength : -curve.strength));
96template <
typename SampleType,
typename ProgressType>
100 static_assert(std::is_floating_point_v<SampleType>);
101 static_assert(std::is_floating_point_v<ProgressType>);
102 const double a =
static_cast<double>(start);
103 const double b =
static_cast<double>(end);
104 if (!std::isfinite(
a))
105 return std::isfinite(b) ? end : SampleType{0};
106 if (!std::isfinite(b))
109 const SampleType shaped =
111 const SampleType result = std::lerp(start, end, shaped);
SampleType precise_stage_curve(SampleType progress, SampleType curve) noexcept
Definition modulation_curve.hpp:55
Definition additive_bank.hpp:218
float smoothstep(float p)
Cubic smoothstep, 3t^2 - 2t^3.
Definition mod_tools.hpp:75
@ exponential
Definition mod_tools.hpp:106
SampleType interpolate_modulation_curve(SampleType start, SampleType end, ProgressType progress, ModulationCurve curve={}) noexcept
Definition modulation_curve.hpp:97
@ rising
Definition rise_fall_generator.hpp:19
@ hold
Definition envelope.hpp:59
ModulationCurve sanitize_modulation_curve(ModulationCurve curve) noexcept
Definition modulation_curve.hpp:42
ModulationCurveShape
Definition modulation_curve.hpp:26
@ smoothstep
Definition modulation_curve.hpp:30
@ logarithmic
Definition modulation_curve.hpp:29
@ linear
Definition modulation_curve.hpp:27
@ exponential
Definition modulation_curve.hpp:28
@ hold
Definition modulation_curve.hpp:31
T snap_to_zero(T x)
Returns 0 if |x| < snap_threshold, else x.
Definition denormal.hpp:45
float stage_curve(float p, float curve)
The shared stage-shaping law:
Definition mod_tools.hpp:44
@ a
Definition formant_filter_bank.hpp:20
@ linear
2-point. Cheapest; audible imaging when pitching up.
Definition granular.hpp:133
@ progress
Definition finite_stretch_builder.hpp:30
SampleType modulation_curve_progress(SampleType progress, ModulationCurve curve, bool rising) noexcept
Definition modulation_curve.hpp:69
constexpr float kCurveSpan
Curve span for the shared stage-shaping law.
Definition mod_tools.hpp:31
Curve strength is dimensionless and legal in [0, 1].
Definition modulation_curve.hpp:37
ModulationCurveShape shape
Definition modulation_curve.hpp:38
float strength
Definition modulation_curve.hpp:39