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

◆ trapezoid()

MAYAFLUX_API 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 62 of file Taper.cpp.

63{
64 if (n == 0)
65 return {};
66 if (n == 1)
67 return { 1.0 };
68 std::vector<double> w(n, 1.0);
69 const size_t ramp = std::min(fade_len, n / 2);
70 for (size_t i = 0; i < ramp; ++i) {
71 const double r = static_cast<double>(i) / static_cast<double>(ramp);
72 w[i] = r;
73 w[n - 1 - i] = r;
74 }
75 return w;
76}