Readability cleanup
This commit is contained in:
parent
db2f64d3cc
commit
ba4c64adea
2 changed files with 51 additions and 39 deletions
|
|
@ -26,7 +26,7 @@
|
||||||
* @author Paul Ferrand (paul@ferrand.cc)
|
* @author Paul Ferrand (paul@ferrand.cc)
|
||||||
* @brief Contains math helper functions and math constants
|
* @brief Contains math helper functions and math constants
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
* @date 2019-11-23
|
* @date 2019-11-23
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <algorithm>
|
#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))
|
* @brief Converts db values into power (applies 10**(in/10))
|
||||||
*
|
*
|
||||||
* @tparam Type
|
* @tparam Type
|
||||||
* @param in
|
* @param in
|
||||||
* @return Type
|
* @return Type
|
||||||
*/
|
*/
|
||||||
template <class Type>
|
template <class Type>
|
||||||
inline constexpr Type db2pow(Type in)
|
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))
|
* @brief Converts power values into dB (applies 10log10(in))
|
||||||
*
|
*
|
||||||
* @tparam Type
|
* @tparam Type
|
||||||
* @param in
|
* @param in
|
||||||
* @return Type
|
* @return Type
|
||||||
*/
|
*/
|
||||||
template <class Type>
|
template <class Type>
|
||||||
inline constexpr Type pow2db(Type in)
|
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))
|
* @brief Converts dB values to magnitude (applies 10**(in/20))
|
||||||
*
|
*
|
||||||
* @tparam Type
|
* @tparam Type
|
||||||
* @param in
|
* @param in
|
||||||
* @return constexpr Type
|
* @return constexpr Type
|
||||||
*/
|
*/
|
||||||
template <class Type>
|
template <class Type>
|
||||||
inline constexpr Type db2mag(Type in)
|
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))
|
* @brief Converts magnitude values into dB (applies 20log10(in))
|
||||||
*
|
*
|
||||||
* @tparam Type
|
* @tparam Type
|
||||||
* @param in
|
* @param in
|
||||||
* @return Type
|
* @return Type
|
||||||
*/
|
*/
|
||||||
template <class Type>
|
template <class Type>
|
||||||
inline constexpr Type mag2db(Type in)
|
inline constexpr Type mag2db(Type in)
|
||||||
|
|
@ -95,9 +95,9 @@ inline constexpr Type mag2db(Type in)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Global random singletons
|
* @brief Global random singletons
|
||||||
*
|
*
|
||||||
* TODO: could be moved into a singleton class holder
|
* TODO: could be moved into a singleton class holder
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
namespace Random {
|
namespace Random {
|
||||||
static std::random_device randomDevice;
|
static std::random_device randomDevice;
|
||||||
|
|
@ -106,9 +106,9 @@ namespace Random {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Converts a midi note to a frequency value
|
* @brief Converts a midi note to a frequency value
|
||||||
*
|
*
|
||||||
* @param noteNumber
|
* @param noteNumber
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
inline float midiNoteFrequency(const int noteNumber)
|
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!
|
* @brief Clamps a value between bounds, including the bounds!
|
||||||
*
|
*
|
||||||
* @tparam T
|
* @tparam T
|
||||||
* @param v
|
* @param v
|
||||||
* @param lo
|
* @param lo
|
||||||
* @param hi
|
* @param hi
|
||||||
* @return T
|
* @return T
|
||||||
*/
|
*/
|
||||||
template<class 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;
|
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>
|
template <class Type>
|
||||||
constexpr Type pi { 3.141592653589793238462643383279502884 };
|
constexpr Type pi { 3.141592653589793238462643383279502884 };
|
||||||
template <class Type>
|
template <class Type>
|
||||||
|
|
|
||||||
|
|
@ -420,23 +420,16 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
|
||||||
auto leftSource = source.getChannel(0);
|
auto leftSource = source.getChannel(0);
|
||||||
if (source.getNumChannels() == 1) {
|
if (source.getNumChannels() == 1) {
|
||||||
while (ind < indices.end()) {
|
while (ind < indices.end()) {
|
||||||
*left = leftSource[*ind] * (*leftCoeff) + leftSource[*ind + 1] * (*rightCoeff);
|
*left = linearInterpolation(leftSource[*ind], leftSource[*ind + 1], *leftCoeff, *rightCoeff);
|
||||||
left++;
|
incrementAll(ind, left, leftCoeff, rightCoeff);
|
||||||
ind++;
|
|
||||||
leftCoeff++;
|
|
||||||
rightCoeff++;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto right = buffer.getChannel(1);
|
auto right = buffer.getChannel(1);
|
||||||
auto rightSource = source.getChannel(1);
|
auto rightSource = source.getChannel(1);
|
||||||
while (ind < indices.end()) {
|
while (ind < indices.end()) {
|
||||||
*left = leftSource[*ind] * (*leftCoeff) + leftSource[*ind + 1] * (*rightCoeff);
|
*left = linearInterpolation(leftSource[*ind], leftSource[*ind + 1], *leftCoeff, *rightCoeff);
|
||||||
*right = rightSource[*ind] * (*leftCoeff) + rightSource[*ind + 1] * (*rightCoeff);
|
*right = linearInterpolation(rightSource[*ind], rightSource[*ind + 1], *leftCoeff, *rightCoeff);
|
||||||
left++;
|
incrementAll(ind, left, right, leftCoeff, rightCoeff);
|
||||||
right++;
|
|
||||||
ind++;
|
|
||||||
leftCoeff++;
|
|
||||||
rightCoeff++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue