Have this inline double code from a PolyBlep oscillator for making a synthesizer. I was wondering if I could make it more efficient maybe using intrinsic replacements or just refactoring the code so that the compiler can automatically apply intrinsic when it compiles. Any other methods that are not using vector just plain refactoring would be fine just some speed improvement as it is a little taxing thank you!
inline double blep(double t, double dt) {
if (t < dt) {
return -square_number(t / dt - 1);
}
else if (t > 1 - dt) {
return square_number((t - 1) / dt + 1);
}
else {
return 0;
}
}
It uses a lot of subtract and divide but also some logic wondering if there is a way to speed this up a little for better cpu savings?
This is using C++ type code in Visual Studio 2019 c++17. Any suggestion would be appreciated thank you!
Source Code https://github.com/martinfinke/PolyBLEP
EDIT: t and dt are varible non static incoming values of phase position (t) and freq/pitch (dt)