diff --git a/src/sfizz/MathHelpers.h b/src/sfizz/MathHelpers.h index cf30c79a..4a6aff49 100644 --- a/src/sfizz/MathHelpers.h +++ b/src/sfizz/MathHelpers.h @@ -254,6 +254,20 @@ constexpr Type sqrtTwo() { return static_cast(1.41421356237309504880168872 template constexpr Type sqrtTwoInv() { return static_cast(0.707106781186547524400844362104849039284835937688474036588); }; +/** + * @brief lround for positive values + * This optimizes a bit better by ignoring the negative code path + * + * @tparam T + * @param value + * @return constexpr long int + */ +template::value, int> = 0 > +constexpr long int lroundPositive(T value) +{ + return static_cast(0.5f + value); // NOLINT +} + /** @brief A fraction which is parameterized by integer type */ diff --git a/src/sfizz/Panning.cpp b/src/sfizz/Panning.cpp index bdafebd8..299f2955 100644 --- a/src/sfizz/Panning.cpp +++ b/src/sfizz/Panning.cpp @@ -1,5 +1,6 @@ #include "Panning.h" #include +#include namespace sfz { @@ -24,7 +25,7 @@ static const auto panData = []() float panLookup(float pan) { // reduce range, round to nearest - int index = static_cast(0.5f + pan * (panSize - 1)); + int index = lroundPositive(pan * (panSize - 1)); return panData[index]; }