Use a custom lround and silence tidy

This commit is contained in:
Paul Ferrand 2020-05-31 17:25:55 +02:00 committed by Jean Pierre Cimalando
parent 1498daa8a6
commit 87c6174cad
2 changed files with 16 additions and 1 deletions

View file

@ -254,6 +254,20 @@ constexpr Type sqrtTwo() { return static_cast<Type>(1.41421356237309504880168872
template <class Type>
constexpr Type sqrtTwoInv() { return static_cast<Type>(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<class T, absl::enable_if_t<std::is_floating_point<T>::value, int> = 0 >
constexpr long int lroundPositive(T value)
{
return static_cast<int>(0.5f + value); // NOLINT
}
/**
@brief A fraction which is parameterized by integer type
*/

View file

@ -1,5 +1,6 @@
#include "Panning.h"
#include <array>
#include <cmath>
namespace sfz
{
@ -24,7 +25,7 @@ static const auto panData = []()
float panLookup(float pan)
{
// reduce range, round to nearest
int index = static_cast<int>(0.5f + pan * (panSize - 1));
int index = lroundPositive(pan * (panSize - 1));
return panData[index];
}