From 87c6174cad0b1eb618077e28542587dccb8c832b Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 31 May 2020 17:25:55 +0200 Subject: [PATCH] Use a custom lround and silence tidy --- src/sfizz/MathHelpers.h | 14 ++++++++++++++ src/sfizz/Panning.cpp | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) 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]; }