Use @falktx's way for the math constants
This commit is contained in:
parent
81ee0f00fd
commit
542bd28a28
3 changed files with 17 additions and 20 deletions
|
|
@ -124,9 +124,7 @@ inline float midiNoteFrequency(const int noteNumber)
|
||||||
template<class T>
|
template<class T>
|
||||||
constexpr T clamp( T v, T lo, T hi )
|
constexpr T clamp( T v, T lo, T hi )
|
||||||
{
|
{
|
||||||
v = min(v, hi);
|
return max(min(v, hi), lo);
|
||||||
v = max(v, lo);
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int Increment = 1, class T>
|
template<int Increment = 1, class T>
|
||||||
|
|
@ -148,19 +146,18 @@ constexpr ValueType linearInterpolation(ValueType left, ValueType right, ValueTy
|
||||||
return left * leftCoeff + right * rightCoeff;
|
return left * leftCoeff + right * rightCoeff;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr double dPi { 3.141592653589793238462643383279502884};
|
template<class Type>
|
||||||
constexpr double dTwoPi { dPi * 2 };
|
constexpr Type pi() { return static_cast<Type>(3.141592653589793238462643383279502884); };
|
||||||
constexpr double dPiTwo { dPi / 2 };
|
template<class Type>
|
||||||
constexpr double dPiFour { dPi / 4 };
|
constexpr Type twoPi() { return pi<Type>() * 2; };
|
||||||
constexpr double dSqrtTwo { 1.414213562373095048801688724209698078569671875376948073176 };
|
template<class Type>
|
||||||
constexpr double dSqrtTwoInv { 0.707106781186547524400844362104849039284835937688474036588 };
|
constexpr Type piTwo() { return pi<Type>() / 2; };
|
||||||
|
template<class Type>
|
||||||
constexpr float fPi { 3.141592653589793238462643383279502884};
|
constexpr Type piFour() { return pi<Type>() / 4; };
|
||||||
constexpr float fTwoPi { fPi * 2 };
|
template<class Type>
|
||||||
constexpr float fPiTwo { fPi / 2 };
|
constexpr Type sqrtTwo() { return static_cast<Type>(1.414213562373095048801688724209698078569671875376948073176); };
|
||||||
constexpr float fPiFour { fPi / 4 };
|
template<class Type>
|
||||||
constexpr float fSqrtTwo { 1.414213562373095048801688724209698078569671875376948073176 };
|
constexpr Type sqrtTwoInv() { return static_cast<Type>(0.707106781186547524400844362104849039284835937688474036588); };
|
||||||
constexpr float fSqrtTwoInv { 0.707106781186547524400844362104849039284835937688474036588 };
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief A fraction which is parameterized by integer type
|
@brief A fraction which is parameterized by integer type
|
||||||
|
|
|
||||||
|
|
@ -748,7 +748,7 @@ namespace _internals {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (; i < panSize; ++i)
|
for (; i < panSize; ++i)
|
||||||
pan[i] = std::cos(i * (dPiTwo / (panSize - 1)));
|
pan[i] = std::cos(i * (twoPi<double>() / (panSize - 1)));
|
||||||
|
|
||||||
for (; i < static_cast<int>(pan.size()); ++i)
|
for (; i < static_cast<int>(pan.size()); ++i)
|
||||||
pan[i] = pan[panSize - 1];
|
pan[i] = pan[panSize - 1];
|
||||||
|
|
|
||||||
|
|
@ -479,7 +479,7 @@ void sfz::Voice::fillWithGenerator(AudioSpan<float> buffer) noexcept
|
||||||
auto bends = tempSpan2.first(buffer.getNumFrames());
|
auto bends = tempSpan2.first(buffer.getNumFrames());
|
||||||
auto phases = tempSpan2.first(buffer.getNumFrames());
|
auto phases = tempSpan2.first(buffer.getNumFrames());
|
||||||
|
|
||||||
const float step = baseFrequency * fTwoPi / sampleRate;
|
const float step = baseFrequency * twoPi<float>() / sampleRate;
|
||||||
fill<float>(jumps, step);
|
fill<float>(jumps, step);
|
||||||
|
|
||||||
if (region->bendStep > 1)
|
if (region->bendStep > 1)
|
||||||
|
|
@ -496,8 +496,8 @@ void sfz::Voice::fillWithGenerator(AudioSpan<float> buffer) noexcept
|
||||||
copy<float>(leftSpan, rightSpan);
|
copy<float>(leftSpan, rightSpan);
|
||||||
|
|
||||||
// Wrap the phase so we don't loose too much precision on longer notes
|
// Wrap the phase so we don't loose too much precision on longer notes
|
||||||
const auto numTwoPiWraps = static_cast<int>(phase / fTwoPi);
|
const auto numTwoPiWraps = static_cast<int>(phase / twoPi<float>());
|
||||||
phase -= fTwoPi * static_cast<float>(numTwoPiWraps);
|
phase -= twoPi<float>() * static_cast<float>(numTwoPiWraps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue