MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ ramp_exponential()

MAYAFLUX_API std::vector< double > MayaFlux::Kinesis::Discrete::ramp_exponential ( size_t  n,
double  start = 0.001,
double  end = 1.0 
)

Exponential ramp from start to end over n samples.

Each step multiplies by a constant growth factor. A true exponential cannot originate at zero, so start is clamped away from it; callers wanting a curve that begins at silence should offset the result.

Parameters
nLength in samples
startFirst value, clamped to magnitude >= 1e-9
endLast value
Returns
Vector of length n; n == 1 returns { start }

Definition at line 253 of file Transform.cpp.

254{
255 if (n == 0)
256 return {};
257
258 constexpr double k_min_magnitude = 1e-9;
259 double s = start;
260 if (std::abs(s) < k_min_magnitude)
261 s = std::copysign(k_min_magnitude, s == 0.0 ? 1.0 : s);
262
263 if (n == 1)
264 return { s };
265
266 double e = end;
267 if (std::abs(e) < k_min_magnitude)
268 e = std::copysign(k_min_magnitude, e == 0.0 ? 1.0 : e);
269 if ((s < 0.0) != (e < 0.0))
270 e = std::copysign(std::abs(e), s);
271
272 std::vector<double> out(n);
273 const double growth = std::pow(e / s, 1.0 / static_cast<double>(n - 1));
274 out[0] = s;
275 for (size_t i = 1; i < n; ++i)
276 out[i] = out[i - 1] * growth;
277 return out;
278}