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

◆ trapezoid()

std::vector< double > MayaFlux::Kinesis::Discrete::trapezoid ( size_t  n,
size_t  fade_len 
)

Trapezoid taper coefficients with configurable flat region.

Linear ramp-in over fade_len samples, unity plateau, linear ramp-out over fade_len samples. If 2 * fade_len >= n the ramps are clamped so they meet at the centre with no plateau.

Parameters
nLength in samples
fade_lenRamp length in samples at each end
Returns
Coefficient vector of length n

Definition at line 55 of file Taper.cpp.

56{
57 if (n == 0)
58 return {};
59 if (n == 1)
60 return { 1.0 };
61 std::vector<double> w(n, 1.0);
62 const size_t ramp = std::min(fade_len, n / 2);
63 for (size_t i = 0; i < ramp; ++i) {
64 const double r = static_cast<double>(i) / static_cast<double>(ramp);
65 w[i] = r;
66 w[n - 1 - i] = r;
67 }
68 return w;
69}