77constexpr double kTwoPi = 6.283185307179586477;
79[[nodiscard]]
inline double wrap01(
double x)
noexcept {
80 return x - std::floor(x);
83[[nodiscard]]
inline double clamp_open(
double x)
noexcept {
84 return x < 1.0e-6 ? 1.0e-6 : (x > 1.0 - 1.0e-6 ? 1.0 - 1.0e-6 : x);
97 const double r = x -
a;
98 return r - r * r / (1.0 -
a);
105 const double pw =
clamp_open(params.pulse_width);
106 return x < pw ? x : 2.0 * pw - x;
134 return p <
a ? -1.0 + 2.0 * p /
a : 1.0 - 2.0 * (p -
a) / (1.0 -
a);
137 return 2.0 * p - 1.0;
139 return 1.0 - 2.0 * p;
154 const double whole = std::floor(phase);
167 if (!(std::isfinite(from) && std::isfinite(to)))
170 const double t = from;
174 const double span = to - from;
178 return lfo_wave(wave, from, params);
199 double value =
lfo_wave(wave, p, params);
200 if (!(increment > 0.0) || !std::isfinite(increment) || increment >= 1.0)
202 const double dt = increment;
208 const auto corner = [&](
double at,
double height,
bool slope) {
211 double behind = p - at;
212 behind -= std::floor(behind);
217 const double d = 1.0 - behind / dt;
220 double ahead = at - p;
221 ahead -= std::floor(ahead);
222 if (ahead > 0.0 && ahead <= dt) {
225 const double d = ahead / dt;
232 corner(0.0, -2.0,
false);
235 corner(0.0, +2.0,
false);
239 corner(0.0, +2.0,
false);
240 corner(pw, -2.0,
false);
246 const double turn = (2.0 /
a + 2.0 / (1.0 -
a)) * dt;
247 corner(
a, -turn,
true);
248 corner(0.0, +turn,
true);
Bandlimited-step (BLEP) and bandlimited-ramp (BLAMP) correction kernels.
double wave_integral_in_cycle(LfoWave wave, double x, const LfoShapeParams ¶ms) noexcept
The integral of one wave over [0, x] for x in [0, 1].
Definition lfo_sampling.hpp:88
double clamp_open(double x) noexcept
Definition lfo_sampling.hpp:83
constexpr double kTwoPi
Definition lfo_sampling.hpp:77
double wrap01(double x) noexcept
Definition lfo_sampling.hpp:79
double wave_integral_per_cycle(LfoWave wave, const LfoShapeParams ¶ms) noexcept
The integral over one whole cycle: zero for every wave but the square.
Definition lfo_sampling.hpp:116
Correction poly_blep(double d, double height) noexcept
polyBLEP correction for a step in the VALUE.
Definition blep.hpp:177
Correction poly_blamp(double d, double slope_change) noexcept
polyBLAMP correction for a break in the SLOPE.
Definition blep.hpp:206
Definition additive_bank.hpp:218
double lfo_wave_integral(LfoWave wave, double phase, const LfoShapeParams ¶ms={}) noexcept
The cumulative integral of wave from phase 0 to phase, in value x cycles.
Definition lfo_sampling.hpp:152
double lfo_wave_bandlimited(LfoWave wave, double phase, double increment, const LfoShapeParams ¶ms={}) noexcept
The band-limited value of wave for a consumer that reads it EVERY sample, at phase with a per-sample ...
Definition lfo_sampling.hpp:196
constexpr bool lfo_wave_is_periodic(LfoWave wave) noexcept
True for the waves that are periodic functions of phase (everything but the two random waves).
Definition lfo_sampling.hpp:71
@ a
Definition formant_filter_bank.hpp:20
LfoWave
The effect-wave vocabulary, shared by these functions and by EffectLfoT (lfo.hpp),...
Definition lfo_sampling.hpp:53
@ sample_hold
Definition lfo_sampling.hpp:59
@ square
Definition lfo_sampling.hpp:58
@ saw_down
Definition lfo_sampling.hpp:57
@ sine
Definition lfo_sampling.hpp:54
@ saw_up
Definition lfo_sampling.hpp:56
@ smooth_random
Definition lfo_sampling.hpp:60
@ triangle
Definition lfo_sampling.hpp:55
double lfo_wave(LfoWave wave, double phase, const LfoShapeParams ¶ms={}) noexcept
The trivial value of wave at phase (any real number of cycles), in [-1, 1].
Definition lfo_sampling.hpp:126
double lfo_wave_mean(LfoWave wave, double from, double to, const LfoShapeParams ¶ms={}) noexcept
The exact mean of wave over the phase interval [from, to], in any units of whole cycles and of any le...
Definition lfo_sampling.hpp:165
@ value
the widget's primary value (Knob, Fader, RangeSlider, Toggle, ProgressBar)
Definition binding_diagnostics.hpp:19
The shape parameters the deterministic waves take.
Definition lfo_sampling.hpp:64
double pulse_width
Square: fraction of the cycle spent at +1, in (0, 1).
Definition lfo_sampling.hpp:65
double triangle_peak
Triangle: phase of the +1 apex, in (0, 1).
Definition lfo_sampling.hpp:66
double after
Add to the sample following it.
Definition blep.hpp:93
double before
Add to the sample preceding the discontinuity.
Definition blep.hpp:91