Readability cleanup

This commit is contained in:
Paul Ferrand 2019-12-23 18:32:37 +01:00
parent db2f64d3cc
commit ba4c64adea
2 changed files with 51 additions and 39 deletions

View file

@ -26,7 +26,7 @@
* @author Paul Ferrand (paul@ferrand.cc)
* @brief Contains math helper functions and math constants
* @version 0.1
* @date 2019-11-23
* @date 2019-11-23
*/
#pragma once
#include <algorithm>
@ -43,10 +43,10 @@ inline constexpr T min(T op1, T op2, T op3, T op4) { return std::min(op1, std::m
/**
* @brief Converts db values into power (applies 10**(in/10))
*
* @tparam Type
* @param in
* @return Type
*
* @tparam Type
* @param in
* @return Type
*/
template <class Type>
inline constexpr Type db2pow(Type in)
@ -56,10 +56,10 @@ inline constexpr Type db2pow(Type in)
/**
* @brief Converts power values into dB (applies 10log10(in))
*
* @tparam Type
* @param in
* @return Type
*
* @tparam Type
* @param in
* @return Type
*/
template <class Type>
inline constexpr Type pow2db(Type in)
@ -69,10 +69,10 @@ inline constexpr Type pow2db(Type in)
/**
* @brief Converts dB values to magnitude (applies 10**(in/20))
*
* @tparam Type
* @param in
* @return constexpr Type
*
* @tparam Type
* @param in
* @return constexpr Type
*/
template <class Type>
inline constexpr Type db2mag(Type in)
@ -82,10 +82,10 @@ inline constexpr Type db2mag(Type in)
/**
* @brief Converts magnitude values into dB (applies 20log10(in))
*
* @tparam Type
* @param in
* @return Type
*
* @tparam Type
* @param in
* @return Type
*/
template <class Type>
inline constexpr Type mag2db(Type in)
@ -95,9 +95,9 @@ inline constexpr Type mag2db(Type in)
/**
* @brief Global random singletons
*
*
* TODO: could be moved into a singleton class holder
*
*
*/
namespace Random {
static std::random_device randomDevice;
@ -106,9 +106,9 @@ namespace Random {
/**
* @brief Converts a midi note to a frequency value
*
* @param noteNumber
* @return float
*
* @param noteNumber
* @return float
*/
inline float midiNoteFrequency(const int noteNumber)
{
@ -117,11 +117,11 @@ inline float midiNoteFrequency(const int noteNumber)
/**
* @brief Clamps a value between bounds, including the bounds!
*
* @tparam T
* @param v
* @param lo
* @param hi
*
* @tparam T
* @param v
* @param lo
* @param hi
* @return T
*/
template<class T>
@ -131,6 +131,25 @@ constexpr T clamp( const T& v, const T& lo, const T& hi )
return (v < lo) ? lo : (hi < v) ? hi : v;
}
template<class T>
constexpr void incrementAll(T& only)
{
only++;
}
template<class T, class... Args>
constexpr void incrementAll(T& first, Args&... rest)
{
first++;
incrementAll(rest...);
}
template<class ValueType>
constexpr ValueType linearInterpolation(ValueType left, ValueType right, ValueType leftCoeff, ValueType rightCoeff)
{
return left * leftCoeff + right * rightCoeff;
}
template <class Type>
constexpr Type pi { 3.141592653589793238462643383279502884 };
template <class Type>

View file

@ -420,23 +420,16 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
auto leftSource = source.getChannel(0);
if (source.getNumChannels() == 1) {
while (ind < indices.end()) {
*left = leftSource[*ind] * (*leftCoeff) + leftSource[*ind + 1] * (*rightCoeff);
left++;
ind++;
leftCoeff++;
rightCoeff++;
*left = linearInterpolation(leftSource[*ind], leftSource[*ind + 1], *leftCoeff, *rightCoeff);
incrementAll(ind, left, leftCoeff, rightCoeff);
}
} else {
auto right = buffer.getChannel(1);
auto rightSource = source.getChannel(1);
while (ind < indices.end()) {
*left = leftSource[*ind] * (*leftCoeff) + leftSource[*ind + 1] * (*rightCoeff);
*right = rightSource[*ind] * (*leftCoeff) + rightSource[*ind + 1] * (*rightCoeff);
left++;
right++;
ind++;
leftCoeff++;
rightCoeff++;
*left = linearInterpolation(leftSource[*ind], leftSource[*ind + 1], *leftCoeff, *rightCoeff);
*right = linearInterpolation(rightSource[*ind], rightSource[*ind + 1], *leftCoeff, *rightCoeff);
incrementAll(ind, left, right, leftCoeff, rightCoeff);
}
}