I'm looking at some c++ audio DSP code from the Q audio dsp library https://github.com/cycfi/Q
i've noticed that in the file q_lib/include/q/synth/square.hpp the author has created a generator for bandlimited square waves using constexpr functions. (this is his function to return the current value)
constexpr float operator()(phase p, phase dt) const
{
constexpr auto middle = phase::max() / 2;
auto r = p < middle ? 1.0f : -1.0f;
// Correct rising discontinuity
r += poly_blep(p, dt);
// Correct falling discontinuity
r -= poly_blep(p + middle, dt);
return r;
}
I'm trying to work out if there is any functional benefit to this since, for many use-cases, phase p and phase dt can't be evaluated at compile time, does this mean the function just turns into a normal non-const one? or is there still some other benefit apart from it being const function when p & dt are constant?