From c8592ba72d4a7caa1872bc24cdf8921625a6acf9 Mon Sep 17 00:00:00 2001 From: Fawn Sannar Date: Tue, 22 Oct 2024 18:21:08 -0600 Subject: [PATCH 1/8] add templates for common geometric constants --- include/lmms_constants.h | 48 ++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/include/lmms_constants.h b/include/lmms_constants.h index 4390b81eaec..b674ef2a422 100644 --- a/include/lmms_constants.h +++ b/include/lmms_constants.h @@ -28,33 +28,27 @@ namespace lmms { - -constexpr long double LD_PI = 3.14159265358979323846264338327950288419716939937510; -constexpr long double LD_2PI = LD_PI * 2.0; -constexpr long double LD_PI_2 = LD_PI * 0.5; -constexpr long double LD_PI_R = 1.0 / LD_PI; -constexpr long double LD_PI_SQR = LD_PI * LD_PI; -constexpr long double LD_E = 2.71828182845904523536028747135266249775724709369995; -constexpr long double LD_E_R = 1.0 / LD_E; -constexpr long double LD_SQRT_2 = 1.41421356237309504880168872420969807856967187537695; - -constexpr double D_PI = (double) LD_PI; -constexpr double D_2PI = (double) LD_2PI; -constexpr double D_PI_2 = (double) LD_PI_2; -constexpr double D_PI_R = (double) LD_PI_R; -constexpr double D_PI_SQR = (double) LD_PI_SQR; -constexpr double D_E = (double) LD_E; -constexpr double D_E_R = (double) LD_E_R; -constexpr double D_SQRT_2 = (double) LD_SQRT_2; - -constexpr float F_PI = (float) LD_PI; -constexpr float F_2PI = (float) LD_2PI; -constexpr float F_PI_2 = (float) LD_PI_2; -constexpr float F_PI_R = (float) LD_PI_R; -constexpr float F_PI_SQR = (float) LD_PI_SQR; -constexpr float F_E = (float) LD_E; -constexpr float F_E_R = (float) LD_E_R; -constexpr float F_SQRT_2 = (float) LD_SQRT_2; +template constexpr T PI = T(3.14159265358979323846264338327950288419716939937510); +template constexpr T PI_2 = T(PI / 2.0); +template constexpr T PI_R = T(1.0 / PI); +template constexpr T PI_SQR = T(PI * PI); +template constexpr T TAU = T(PI * 2.0); +template constexpr T TAU_R = T(1.0 / TAU); +template constexpr T E = T(2.71828182845904523536028747135266249775724709369995); +template constexpr T E_R = T(1.0 / E); +template constexpr T SQRT_2 = T(1.41421356237309504880168872420969807856967187537695); + +// TODO these aliases are still in use across the codebase. It would +// probably be good to either keep these aliases but mark them as +// deprecated, or to replace uses of them with the template versions +// instead. Leaving them be for now. +constexpr double D_PI = PI; +constexpr double D_2PI = TAU; +constexpr float F_PI = PI; +constexpr float F_2PI = TAU; +constexpr float F_PI_2 = PI_2; +constexpr float F_PI_SQR = PI_SQR; +constexpr float F_E = E; constexpr float F_EPSILON = 1.0e-10f; // 10^-10 From fdc56b406e20a55bb542a62cb3d73a088c458539 Mon Sep 17 00:00:00 2001 From: Fawn Sannar Date: Tue, 22 Oct 2024 18:52:22 -0600 Subject: [PATCH 2/8] oops missed one --- include/lmms_constants.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/lmms_constants.h b/include/lmms_constants.h index b674ef2a422..eca75f12fb4 100644 --- a/include/lmms_constants.h +++ b/include/lmms_constants.h @@ -42,6 +42,7 @@ template constexpr T SQRT_2 = T(1.4142135623730950488016887242096980 // probably be good to either keep these aliases but mark them as // deprecated, or to replace uses of them with the template versions // instead. Leaving them be for now. +constexpr long double LD_2PI = TAU; constexpr double D_PI = PI; constexpr double D_2PI = TAU; constexpr float F_PI = PI; From ae0dfc8829d42fab39fc21ced36d59c4e1233a4d Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 22 Oct 2024 19:04:13 -0600 Subject: [PATCH 3/8] LD_2PI -> LD_PI i re-added the wrong constant ffs --- include/lmms_constants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/lmms_constants.h b/include/lmms_constants.h index eca75f12fb4..840be620586 100644 --- a/include/lmms_constants.h +++ b/include/lmms_constants.h @@ -42,7 +42,7 @@ template constexpr T SQRT_2 = T(1.4142135623730950488016887242096980 // probably be good to either keep these aliases but mark them as // deprecated, or to replace uses of them with the template versions // instead. Leaving them be for now. -constexpr long double LD_2PI = TAU; +constexpr long double LD_PI = PI; constexpr double D_PI = PI; constexpr double D_2PI = TAU; constexpr float F_PI = PI; From 447a157d9bcdb4581fdbc6c8355e3798c1538d0a Mon Sep 17 00:00:00 2001 From: Fawn Sannar Date: Tue, 22 Oct 2024 23:19:41 -0600 Subject: [PATCH 4/8] CamelCase names and also verify compilation without -DLMMS_MINIMAL --- include/lmms_constants.h | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/include/lmms_constants.h b/include/lmms_constants.h index 840be620586..0502f432d5a 100644 --- a/include/lmms_constants.h +++ b/include/lmms_constants.h @@ -28,28 +28,26 @@ namespace lmms { -template constexpr T PI = T(3.14159265358979323846264338327950288419716939937510); -template constexpr T PI_2 = T(PI / 2.0); -template constexpr T PI_R = T(1.0 / PI); -template constexpr T PI_SQR = T(PI * PI); -template constexpr T TAU = T(PI * 2.0); -template constexpr T TAU_R = T(1.0 / TAU); +template constexpr T Pi = T(3.14159265358979323846264338327950288419716939937510); +template constexpr T Pi2 = T(Pi / 2.0); +template constexpr T PiR = T(1.0 / Pi); +template constexpr T PiSqr = T(Pi * Pi); +template constexpr T Tau = T(Pi * 2.0); +template constexpr T TauR = T(1.0 / Tau); template constexpr T E = T(2.71828182845904523536028747135266249775724709369995); -template constexpr T E_R = T(1.0 / E); -template constexpr T SQRT_2 = T(1.41421356237309504880168872420969807856967187537695); +template constexpr T ER = T(1.0 / E); +template constexpr T Sqrt2 = T(1.41421356237309504880168872420969807856967187537695); -// TODO these aliases are still in use across the codebase. It would -// probably be good to either keep these aliases but mark them as -// deprecated, or to replace uses of them with the template versions -// instead. Leaving them be for now. -constexpr long double LD_PI = PI; -constexpr double D_PI = PI; -constexpr double D_2PI = TAU; -constexpr float F_PI = PI; -constexpr float F_2PI = TAU; -constexpr float F_PI_2 = PI_2; -constexpr float F_PI_SQR = PI_SQR; +constexpr long double LD_2PI = Tau; +constexpr long double LD_PI = Pi; +constexpr double D_PI = Pi; +constexpr double D_2PI = Tau; +constexpr float F_PI = Pi; +constexpr float F_2PI = Tau; +constexpr float F_PI_2 = Pi2; +constexpr float F_PI_SQR = PiSqr; constexpr float F_E = E; +constexpr float F_SQRT_2 = Sqrt2; constexpr float F_EPSILON = 1.0e-10f; // 10^-10 From 26e37f795251f25f3cad2fd87717001ccb366276 Mon Sep 17 00:00:00 2001 From: Fawn Date: Wed, 23 Oct 2024 13:47:51 -0600 Subject: [PATCH 5/8] C++20 stuff Updated to account for `` and C++20: - Marked all `lmms_constants.h` constants with an exact equivalent in `` as deprecated - Removed all `lmms_constants.h` constants where no variant is currently in use - Using `inline constexpr` - Using `std::floating_point` concept instead of `typename` --- include/lmms_constants.h | 59 ++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/include/lmms_constants.h b/include/lmms_constants.h index 0502f432d5a..b552ab824c8 100644 --- a/include/lmms_constants.h +++ b/include/lmms_constants.h @@ -25,29 +25,48 @@ #ifndef LMMS_CONSTANTS_H #define LMMS_CONSTANTS_H +#include +#include + namespace lmms { -template constexpr T Pi = T(3.14159265358979323846264338327950288419716939937510); -template constexpr T Pi2 = T(Pi / 2.0); -template constexpr T PiR = T(1.0 / Pi); -template constexpr T PiSqr = T(Pi * Pi); -template constexpr T Tau = T(Pi * 2.0); -template constexpr T TauR = T(1.0 / Tau); -template constexpr T E = T(2.71828182845904523536028747135266249775724709369995); -template constexpr T ER = T(1.0 / E); -template constexpr T Sqrt2 = T(1.41421356237309504880168872420969807856967187537695); - -constexpr long double LD_2PI = Tau; -constexpr long double LD_PI = Pi; -constexpr double D_PI = Pi; -constexpr double D_2PI = Tau; -constexpr float F_PI = Pi; -constexpr float F_2PI = Tau; -constexpr float F_PI_2 = Pi2; -constexpr float F_PI_SQR = PiSqr; -constexpr float F_E = E; -constexpr float F_SQRT_2 = Sqrt2; +template inline constexpr T Tau = T(std::numbers::pi_v * 2.0); +template inline constexpr T HalfPi = T(std::numbers::pi_v / 2.0); +template inline constexpr T PiSquared = T(std::numbers::pi_v * std::numbers::pi_v); + +inline constexpr long double LD_2PI = Tau; +inline constexpr double D_2PI = Tau; +inline constexpr float F_2PI = Tau; +inline constexpr float F_PI_2 = HalfPi; +inline constexpr float F_PI_SQR = PiSquared; + +[[deprecated("use std::numbers::pi_v instead")]] +inline constexpr long double LD_PI = std::numbers::pi_v; + +[[deprecated("use std::numbers::pi_v instead")]] +inline constexpr double D_PI = std::numbers::pi_v; + +[[deprecated("use std::numbers::pi_v instead")]] +inline constexpr float F_PI = std::numbers::pi_v; + +[[deprecated("use std::numbers::e_v instead")]] +inline constexpr long double LD_E = std::numbers::e_v; + +[[deprecated("use std::numbers::e_v instead")]] +inline constexpr double D_E = std::numbers::e_v; + +[[deprecated("use std::numbers::e_v instead")]] +inline constexpr float F_E = std::numbers::e_v; + +[[deprecated("use std::numbers::sqrt2_v instead")]] +inline constexpr long double LD_SQRT_2 = std::numbers::sqrt2_v; + +[[deprecated("use std::numbers::sqrt2_v instead")]] +inline constexpr double D_SQRT_2 = std::numbers::sqrt2_v; + +[[deprecated("use std::numbers::sqrt2_v instead")]] +inline constexpr float F_SQRT_2 = std::numbers::sqrt2_v; constexpr float F_EPSILON = 1.0e-10f; // 10^-10 From 3a61877034c1eace1fd05647577743cb30cac16d Mon Sep 17 00:00:00 2001 From: Fawn Sannar Date: Wed, 27 Nov 2024 14:05:44 -0700 Subject: [PATCH 6/8] add lmms::numbers namespace --- include/BasicFilters.h | 23 +++--- include/DspEffectLibrary.h | 2 +- include/Oscillator.h | 2 +- include/QuadratureLfo.h | 9 +- include/interpolation.h | 2 +- include/lmms_constants.h | 82 ++++++++++--------- include/lmms_math.h | 9 +- plugins/Compressor/Compressor.cpp | 2 +- plugins/Delay/Lfo.cpp | 2 +- plugins/Delay/Lfo.h | 7 +- plugins/Dispersion/Dispersion.cpp | 2 +- plugins/Eq/EqCurve.cpp | 21 ++--- plugins/Eq/EqFilter.h | 10 +-- plugins/Eq/EqSpectrumView.cpp | 6 +- plugins/Flanger/FlangerEffect.cpp | 2 +- .../GranularPitchShifterEffect.cpp | 2 +- .../GranularPitchShifterEffect.h | 6 +- plugins/MultitapEcho/MultitapEcho.h | 2 +- plugins/Xpressive/ExprSynth.cpp | 4 +- plugins/Xpressive/Xpressive.cpp | 4 +- src/core/BandLimitedWave.cpp | 16 ++-- src/core/Instrument.cpp | 4 +- src/core/Oscillator.cpp | 8 +- src/core/fft_helpers.cpp | 6 +- src/gui/widgets/Knob.cpp | 2 +- 25 files changed, 114 insertions(+), 121 deletions(-) diff --git a/include/BasicFilters.h b/include/BasicFilters.h index 8d21b3657ca..663941c0cab 100644 --- a/include/BasicFilters.h +++ b/include/BasicFilters.h @@ -74,21 +74,20 @@ class LinkwitzRiley inline void setCoeffs( float freq ) { // wc - const double wc = D_2PI * freq; + const double wc = numbers::tau * freq; const double wc2 = wc * wc; const double wc3 = wc2 * wc; m_wc4 = wc2 * wc2; // k - const double k = wc / tan( D_PI * freq / m_sampleRate ); + const double k = wc / tan(numbers::pi * freq / m_sampleRate); const double k2 = k * k; const double k3 = k2 * k; m_k4 = k2 * k2; // a - static const double sqrt2 = sqrt( 2.0 ); - const double sq_tmp1 = sqrt2 * wc3 * k; - const double sq_tmp2 = sqrt2 * wc * k3; + const double sq_tmp1 = numbers::sqrt2 * wc3 * k; + const double sq_tmp2 = numbers::sqrt2 * wc * k3; m_a = 1.0 / ( 4.0 * wc2 * k2 + 2.0 * sq_tmp1 + m_k4 + 2.0 * sq_tmp2 + m_wc4 ); @@ -718,7 +717,7 @@ class BasicFilters { _freq = std::clamp(_freq, 50.0f, 20000.0f); const float sr = m_sampleRatio * 0.25f; - const float f = 1.0f / ( _freq * F_2PI ); + const float f = 1.0f / (_freq * numbers::tau_v); m_rca = 1.0f - sr / ( f + sr ); m_rcb = 1.0f - m_rca; @@ -751,8 +750,8 @@ class BasicFilters const float fract = vowelf - vowel; // interpolate between formant frequencies - const float f0 = 1.0f / ( linearInterpolate( _f[vowel+0][0], _f[vowel+1][0], fract ) * F_2PI ); - const float f1 = 1.0f / ( linearInterpolate( _f[vowel+0][1], _f[vowel+1][1], fract ) * F_2PI ); + const float f0 = 1.0f / (linearInterpolate(_f[vowel+0][0], _f[vowel+1][0], fract) * numbers::tau_v); + const float f1 = 1.0f / (linearInterpolate(_f[vowel+0][1], _f[vowel+1][1], fract) * numbers::tau_v); // samplerate coeff: depends on oversampling const float sr = m_type == FilterType::FastFormant ? m_sampleRatio : m_sampleRatio * 0.25f; @@ -774,7 +773,7 @@ class BasicFilters // (Empirical tunning) m_p = ( 3.6f - 3.2f * f ) * f; m_k = 2.0f * m_p - 1; - m_r = _q * powf( F_E, ( 1 - m_p ) * 1.386249f ); + m_r = _q * powf(numbers::e_v, (1 - m_p) * 1.386249f); if( m_doubleFilter ) { @@ -791,7 +790,7 @@ class BasicFilters m_p = ( 3.6f - 3.2f * f ) * f; m_k = 2.0f * m_p - 1.0f; - m_r = _q * 0.1f * powf( F_E, ( 1 - m_p ) * 1.386249f ); + m_r = _q * 0.1f * powf(numbers::e_v, (1 - m_p) * 1.386249f); return; } @@ -801,7 +800,7 @@ class BasicFilters m_type == FilterType::Highpass_SV || m_type == FilterType::Notch_SV ) { - const float f = sinf(std::max(minFreq(), _freq) * m_sampleRatio * F_PI); + const float f = sinf(std::max(minFreq(), _freq) * m_sampleRatio * numbers::pi_v); m_svf1 = std::min(f, 0.825f); m_svf2 = std::min(f * 2.0f, 0.825f); m_svq = std::max(0.0001f, 2.0f - (_q * 0.1995f)); @@ -810,7 +809,7 @@ class BasicFilters // other filters _freq = std::clamp(_freq, minFreq(), 20000.0f); - const float omega = F_2PI * _freq * m_sampleRatio; + const float omega = numbers::tau_v * _freq * m_sampleRatio; const float tsin = sinf( omega ) * 0.5f; const float tcos = cosf( omega ); diff --git a/include/DspEffectLibrary.h b/include/DspEffectLibrary.h index 348c7076509..ddd7dc14d34 100644 --- a/include/DspEffectLibrary.h +++ b/include/DspEffectLibrary.h @@ -328,7 +328,7 @@ namespace lmms::DspEffectLibrary void nextSample( sample_t& inLeft, sample_t& inRight ) { - const float toRad = F_PI / 180; + const float toRad = numbers::pi_v / 180; const sample_t tmp = inLeft; inLeft += inRight * sinf( m_wideCoeff * ( .5 * toRad ) ); inRight -= tmp * sinf( m_wideCoeff * ( .5 * toRad ) ); diff --git a/include/Oscillator.h b/include/Oscillator.h index 0a5e166dc9e..a8c3be29006 100644 --- a/include/Oscillator.h +++ b/include/Oscillator.h @@ -114,7 +114,7 @@ class LMMS_EXPORT Oscillator // now follow the wave-shape-routines... static inline sample_t sinSample( const float _sample ) { - return sinf( _sample * F_2PI ); + return sinf(_sample * numbers::tau_v); } static inline sample_t triangleSample( const float _sample ) diff --git a/include/QuadratureLfo.h b/include/QuadratureLfo.h index 6f007e0725c..7d4190cf046 100644 --- a/include/QuadratureLfo.h +++ b/include/QuadratureLfo.h @@ -37,7 +37,7 @@ class QuadratureLfo QuadratureLfo( int sampleRate ) : m_frequency(0), m_phase(0), - m_offset(D_PI / 2) + m_offset(numbers::pi_half) { setSampleRate(sampleRate); } @@ -64,7 +64,7 @@ class QuadratureLfo inline void setSampleRate ( int samplerate ) { m_samplerate = samplerate; - m_twoPiOverSr = F_2PI / samplerate; + m_twoPiOverSr = numbers::tau_v / samplerate; m_increment = m_frequency * m_twoPiOverSr; } @@ -81,10 +81,7 @@ class QuadratureLfo *r = sinf( m_phase + m_offset ); m_phase += m_increment; - while (m_phase >= D_2PI) - { - m_phase -= D_2PI; - } + while (m_phase >= numbers::tau) { m_phase -= numbers::tau; } } private: diff --git a/include/interpolation.h b/include/interpolation.h index 0b972bc279e..d9bbe4ea7ee 100644 --- a/include/interpolation.h +++ b/include/interpolation.h @@ -82,7 +82,7 @@ inline float cubicInterpolate( float v0, float v1, float v2, float v3, float x ) inline float cosinusInterpolate( float v0, float v1, float x ) { - const float f = ( 1.0f - cosf( x * F_PI ) ) * 0.5f; + const float f = (1.0f - cosf(x * numbers::pi_v)) * 0.5f; return f * (v1 - v0) + v0; } diff --git a/include/lmms_constants.h b/include/lmms_constants.h index b552ab824c8..266604fa839 100644 --- a/include/lmms_constants.h +++ b/include/lmms_constants.h @@ -25,48 +25,54 @@ #ifndef LMMS_CONSTANTS_H #define LMMS_CONSTANTS_H -#include -#include +// #include +// #include -namespace lmms +namespace lmms::numbers { -template inline constexpr T Tau = T(std::numbers::pi_v * 2.0); -template inline constexpr T HalfPi = T(std::numbers::pi_v / 2.0); -template inline constexpr T PiSquared = T(std::numbers::pi_v * std::numbers::pi_v); - -inline constexpr long double LD_2PI = Tau; -inline constexpr double D_2PI = Tau; -inline constexpr float F_2PI = Tau; -inline constexpr float F_PI_2 = HalfPi; -inline constexpr float F_PI_SQR = PiSquared; - -[[deprecated("use std::numbers::pi_v instead")]] -inline constexpr long double LD_PI = std::numbers::pi_v; - -[[deprecated("use std::numbers::pi_v instead")]] -inline constexpr double D_PI = std::numbers::pi_v; - -[[deprecated("use std::numbers::pi_v instead")]] -inline constexpr float F_PI = std::numbers::pi_v; - -[[deprecated("use std::numbers::e_v instead")]] -inline constexpr long double LD_E = std::numbers::e_v; +//TODO C++20: Use std::floating_point instead of typename +//TODO C++20: Use std::numbers::pi_v instead of literal value +template +inline constexpr T pi_v = T(3.14159265358979323846264338327950288419716939937510); +inline constexpr double pi = pi_v; + +//TODO C++20: Use std::floating_point instead of typename +template +inline constexpr T tau_v = T(pi_v * 2.0); +inline constexpr double tau = tau_v; + +//TODO C++20: Use std::floating_point instead of typename +template +inline constexpr T pi_half_v = T(pi_v / 2.0); +inline constexpr double pi_half = pi_half_v; + +//TODO C++20: Use std::floating_point instead of typename +template +inline constexpr T pi_sqr_v = T(pi_v * pi_v); +inline constexpr double pi_sqr = pi_sqr_v; + +//TODO C++20: Use std::floating_point instead of typename +//TODO C++20: Use std::numbers::e_v instead of literal value +template +inline constexpr T e_v = T(2.71828182845904523536028747135266249775724709369995); +inline constexpr double e = e_v; + +//TODO C++20: Use std::floating_point instead of typename +template +inline constexpr T inv_e_v = T(1.0 / e_v); +inline constexpr double inv_e = e_v; + +//TODO C++20: Use std::floating_point instead of typename +//TODO C++20: Use std::numbers::sqrt2_v instead of literal value +template +inline constexpr T sqrt2_v = T(1.41421356237309504880168872420969807856967187537695); +inline constexpr double sqrt2 = sqrt2_v; + +} -[[deprecated("use std::numbers::e_v instead")]] -inline constexpr double D_E = std::numbers::e_v; - -[[deprecated("use std::numbers::e_v instead")]] -inline constexpr float F_E = std::numbers::e_v; - -[[deprecated("use std::numbers::sqrt2_v instead")]] -inline constexpr long double LD_SQRT_2 = std::numbers::sqrt2_v; - -[[deprecated("use std::numbers::sqrt2_v instead")]] -inline constexpr double D_SQRT_2 = std::numbers::sqrt2_v; - -[[deprecated("use std::numbers::sqrt2_v instead")]] -inline constexpr float F_SQRT_2 = std::numbers::sqrt2_v; +namespace lmms +{ constexpr float F_EPSILON = 1.0e-10f; // 10^-10 diff --git a/include/lmms_math.h b/include/lmms_math.h index bdadd7ba0c4..cf504e7c401 100644 --- a/include/lmms_math.h +++ b/include/lmms_math.h @@ -140,10 +140,10 @@ inline float logToLinearScale(float min, float max, float value) { const float mmax = std::max(std::abs(min), std::abs(max)); const float val = value * ( max - min ) + min; - float result = signedPowf( val / mmax, F_E ) * mmax; + float result = signedPowf(val / mmax, numbers::e_v) * mmax; return std::isnan( result ) ? 0 : result; } - float result = powf( value, F_E ) * ( max - min ) + min; + float result = powf(value, numbers::e_v) * (max - min) + min; return std::isnan( result ) ? 0 : result; } @@ -151,16 +151,15 @@ inline float logToLinearScale(float min, float max, float value) //! @brief Scales value from logarithmic to linear. Value should be in min-max range. inline float linearToLogScale(float min, float max, float value) { - static const float EXP = 1.0f / F_E; const float valueLimited = std::clamp(value, min, max); const float val = ( valueLimited - min ) / ( max - min ); if( min < 0 ) { const float mmax = std::max(std::abs(min), std::abs(max)); - float result = signedPowf( valueLimited / mmax, EXP ) * mmax; + float result = signedPowf(valueLimited / mmax, numbers::inv_e_v) * mmax; return std::isnan( result ) ? 0 : result; } - float result = powf( val, EXP ) * ( max - min ) + min; + float result = powf(val, numbers::inv_e_v) * (max - min) + min; return std::isnan( result ) ? 0 : result; } diff --git a/plugins/Compressor/Compressor.cpp b/plugins/Compressor/Compressor.cpp index 1e4c0d0f608..78d695750ea 100755 --- a/plugins/Compressor/Compressor.cpp +++ b/plugins/Compressor/Compressor.cpp @@ -220,7 +220,7 @@ void CompressorEffect::calcTiltCoeffs() m_lgain = exp(g1 / amp) - 1; m_hgain = exp(g2 / amp) - 1; - const float omega = 2 * F_PI * m_compressorControls.m_tiltFreqModel.value(); + const float omega = numbers::tau_v * m_compressorControls.m_tiltFreqModel.value(); const float n = 1 / (m_sampleRate * 3 + omega); m_a0 = 2 * omega * n; m_b1 = (m_sampleRate * 3 - omega) * n; diff --git a/plugins/Delay/Lfo.cpp b/plugins/Delay/Lfo.cpp index 5a449243a47..a6d490d4045 100644 --- a/plugins/Delay/Lfo.cpp +++ b/plugins/Delay/Lfo.cpp @@ -33,7 +33,7 @@ namespace lmms Lfo::Lfo( int samplerate ) { m_samplerate = samplerate; - m_twoPiOverSr = F_2PI / samplerate; + m_twoPiOverSr = numbers::tau_v / samplerate; } diff --git a/plugins/Delay/Lfo.h b/plugins/Delay/Lfo.h index ea8435d134d..8f69412ea71 100644 --- a/plugins/Delay/Lfo.h +++ b/plugins/Delay/Lfo.h @@ -50,10 +50,7 @@ class Lfo m_frequency = frequency; m_increment = m_frequency * m_twoPiOverSr; - if( m_phase >= F_2PI ) - { - m_phase -= F_2PI; - } + if (m_phase >= numbers::tau_v) { m_phase -= numbers::tau_v; } } @@ -62,7 +59,7 @@ class Lfo inline void setSampleRate ( int samplerate ) { m_samplerate = samplerate; - m_twoPiOverSr = F_2PI / samplerate; + m_twoPiOverSr = numbers::tau_v / samplerate; m_increment = m_frequency * m_twoPiOverSr; } diff --git a/plugins/Dispersion/Dispersion.cpp b/plugins/Dispersion/Dispersion.cpp index 4d8dd40b016..624c161e6db 100644 --- a/plugins/Dispersion/Dispersion.cpp +++ b/plugins/Dispersion/Dispersion.cpp @@ -70,7 +70,7 @@ Effect::ProcessStatus DispersionEffect::processImpl(SampleFrame* buf, const fpp_ const bool dc = m_dispersionControls.m_dcModel.value(); // All-pass coefficient calculation - const float w0 = (F_2PI / m_sampleRate) * freq; + const float w0 = (numbers::tau_v / m_sampleRate) * freq; const float a0 = 1 + (std::sin(w0) / (reso * 2.f)); float apCoeff1 = (1 - (a0 - 1)) / a0; float apCoeff2 = (-2 * std::cos(w0)) / a0; diff --git a/plugins/Eq/EqCurve.cpp b/plugins/Eq/EqCurve.cpp index 417f101f798..14f5b456fc7 100644 --- a/plugins/Eq/EqCurve.cpp +++ b/plugins/Eq/EqCurve.cpp @@ -201,8 +201,7 @@ bool EqHandle::mousePressed() const float EqHandle::getPeakCurve( float x ) { double freqZ = xPixelToFreq( EqHandle::x(), m_width ); - const int SR = Engine::audioEngine()->outputSampleRate(); - double w0 = 2 * LD_PI * freqZ / SR ; + double w0 = numbers::tau * freqZ / Engine::audioEngine()->outputSampleRate(); double c = cosf( w0 ); double s = sinf( w0 ); double Q = getResonance(); @@ -238,8 +237,7 @@ float EqHandle::getPeakCurve( float x ) float EqHandle::getHighShelfCurve( float x ) { double freqZ = xPixelToFreq( EqHandle::x(), m_width ); - const int SR = Engine::audioEngine()->outputSampleRate(); - double w0 = 2 * LD_PI * freqZ / SR; + double w0 = numbers::tau * freqZ / Engine::audioEngine()->outputSampleRate(); double c = cosf( w0 ); double s = sinf( w0 ); double A = pow( 10, yPixelToGain( EqHandle::y(), m_heigth, m_pixelsPerUnitHeight ) * 0.025 ); @@ -274,8 +272,7 @@ float EqHandle::getHighShelfCurve( float x ) float EqHandle::getLowShelfCurve( float x ) { double freqZ = xPixelToFreq( EqHandle::x(), m_width ); - const int SR = Engine::audioEngine()->outputSampleRate(); - double w0 = 2 * LD_PI * freqZ / SR ; + double w0 = numbers::tau * freqZ / Engine::audioEngine()->outputSampleRate(); double c = cosf( w0 ); double s = sinf( w0 ); double A = pow( 10, yPixelToGain( EqHandle::y(), m_heigth, m_pixelsPerUnitHeight ) / 40 ); @@ -310,8 +307,7 @@ float EqHandle::getLowShelfCurve( float x ) float EqHandle::getLowCutCurve( float x ) { double freqZ = xPixelToFreq( EqHandle::x(), m_width ); - const int SR = Engine::audioEngine()->outputSampleRate(); - double w0 = 2 * LD_PI * freqZ / SR ; + double w0 = numbers::tau * freqZ / Engine::audioEngine()->outputSampleRate(); double c = cosf( w0 ); double s = sinf( w0 ); double resonance = getResonance(); @@ -353,8 +349,7 @@ float EqHandle::getLowCutCurve( float x ) float EqHandle::getHighCutCurve( float x ) { double freqZ = xPixelToFreq( EqHandle::x(), m_width ); - const int SR = Engine::audioEngine()->outputSampleRate(); - double w0 = 2 * LD_PI * freqZ / SR ; + double w0 = numbers::tau * freqZ / Engine::audioEngine()->outputSampleRate(); double c = cosf( w0 ); double s = sinf( w0 ); double resonance = getResonance(); @@ -527,10 +522,8 @@ void EqHandle::setlp48() double EqHandle::calculateGain(const double freq, const double a1, const double a2, const double b0, const double b1, const double b2 ) { - const int SR = Engine::audioEngine()->outputSampleRate(); - - const double w = 2 * LD_PI * freq / SR ; - const double PHI = pow( sin( w / 2 ), 2 ) * 4; + const double w = sin(numbers::pi * freq / Engine::audioEngine()->outputSampleRate()); + const double PHI = w * w * 4; double gain = 10 * log10( pow( b0 + b1 + b2 , 2 ) + ( b0 * b2 * PHI - ( b1 * ( b0 + b2 ) + 4 * b0 * b2 ) ) * PHI ) - 10 * log10( pow( 1 + a1 + a2, 2 ) diff --git a/plugins/Eq/EqFilter.h b/plugins/Eq/EqFilter.h index 5408d131ce3..03a1f385d50 100644 --- a/plugins/Eq/EqFilter.h +++ b/plugins/Eq/EqFilter.h @@ -185,7 +185,7 @@ public : { // calc intermediate - float w0 = F_2PI * m_freq / m_sampleRate; + float w0 = numbers::tau_v * m_freq / m_sampleRate; float c = cosf( w0 ); float s = sinf( w0 ); float alpha = s / ( 2 * m_res ); @@ -228,7 +228,7 @@ public : { // calc intermediate - float w0 = F_2PI * m_freq / m_sampleRate; + float w0 = numbers::tau_v * m_freq / m_sampleRate; float c = cosf( w0 ); float s = sinf( w0 ); float alpha = s / ( 2 * m_res ); @@ -269,7 +269,7 @@ class EqPeakFilter : public EqFilter void calcCoefficents() override { // calc intermediate - float w0 = F_2PI * m_freq / m_sampleRate; + float w0 = numbers::tau_v * m_freq / m_sampleRate; float c = cosf( w0 ); float s = sinf( w0 ); float A = pow( 10, m_gain * 0.025); @@ -332,7 +332,7 @@ public : { // calc intermediate - float w0 = F_2PI * m_freq / m_sampleRate; + float w0 = numbers::tau_v * m_freq / m_sampleRate; float c = cosf( w0 ); float s = sinf( w0 ); float A = pow( 10, m_gain * 0.025); @@ -369,7 +369,7 @@ public : { // calc intermediate - float w0 = F_2PI * m_freq / m_sampleRate; + float w0 = numbers::tau_v * m_freq / m_sampleRate; float c = cosf( w0 ); float s = sinf( w0 ); float A = pow( 10, m_gain * 0.025 ); diff --git a/plugins/Eq/EqSpectrumView.cpp b/plugins/Eq/EqSpectrumView.cpp index 99df328efec..14b49e64f4d 100644 --- a/plugins/Eq/EqSpectrumView.cpp +++ b/plugins/Eq/EqSpectrumView.cpp @@ -56,9 +56,9 @@ EqAnalyser::EqAnalyser() : for (auto i = std::size_t{0}; i < FFT_BUFFER_SIZE; i++) { - m_fftWindow[i] = (a0 - a1 * cos(2 * F_PI * i / ((float)FFT_BUFFER_SIZE - 1.0)) - + a2 * cos(4 * F_PI * i / ((float)FFT_BUFFER_SIZE - 1.0)) - - a3 * cos(6 * F_PI * i / ((float)FFT_BUFFER_SIZE - 1.0))); + m_fftWindow[i] = (a0 - a1 * cos(2 * numbers::pi_v * i / ((float)FFT_BUFFER_SIZE - 1.0)) + + a2 * cos(4 * numbers::pi_v * i / ((float)FFT_BUFFER_SIZE - 1.0)) + - a3 * cos(6 * numbers::pi_v * i / ((float)FFT_BUFFER_SIZE - 1.0))); } clear(); } diff --git a/plugins/Flanger/FlangerEffect.cpp b/plugins/Flanger/FlangerEffect.cpp index c13de47cd09..9aa765ff420 100644 --- a/plugins/Flanger/FlangerEffect.cpp +++ b/plugins/Flanger/FlangerEffect.cpp @@ -94,7 +94,7 @@ Effect::ProcessStatus FlangerEffect::processImpl(SampleFrame* buf, const fpp_t f float amplitude = m_flangerControls.m_lfoAmountModel.value() * Engine::audioEngine()->outputSampleRate(); bool invertFeedback = m_flangerControls.m_invertFeedbackModel.value(); m_lfo->setFrequency( 1.0/m_flangerControls.m_lfoFrequencyModel.value() ); - m_lfo->setOffset( m_flangerControls.m_lfoPhaseModel.value() / 180 * D_PI ); + m_lfo->setOffset(m_flangerControls.m_lfoPhaseModel.value() / 180 * numbers::pi); m_lDelay->setFeedback( m_flangerControls.m_feedbackModel.value() ); m_rDelay->setFeedback( m_flangerControls.m_feedbackModel.value() ); auto dryS = std::array{}; diff --git a/plugins/GranularPitchShifter/GranularPitchShifterEffect.cpp b/plugins/GranularPitchShifter/GranularPitchShifterEffect.cpp index 27c935ab9ab..2a48f0e3cdf 100755 --- a/plugins/GranularPitchShifter/GranularPitchShifterEffect.cpp +++ b/plugins/GranularPitchShifter/GranularPitchShifterEffect.cpp @@ -271,7 +271,7 @@ void GranularPitchShifterEffect::changeSampleRate() m_grainCount = 0; m_grains.reserve(8);// arbitrary - m_dcCoeff = std::exp(-2.0 * F_PI * DcRemovalHz / m_sampleRate); + m_dcCoeff = std::exp(-numbers::tau_v * DcRemovalHz / m_sampleRate); const double pitch = m_granularpitchshifterControls.m_pitchModel.value() * (1. / 12.); const double pitchSpread = m_granularpitchshifterControls.m_pitchSpreadModel.value() * (1. / 24.); diff --git a/plugins/GranularPitchShifter/GranularPitchShifterEffect.h b/plugins/GranularPitchShifter/GranularPitchShifterEffect.h index 09b8025cdc5..d844b852ff0 100755 --- a/plugins/GranularPitchShifter/GranularPitchShifterEffect.h +++ b/plugins/GranularPitchShifter/GranularPitchShifterEffect.h @@ -118,10 +118,10 @@ class GranularPitchShifterEffect : public Effect void setCoefs(float sampleRate, float cutoff) { - const float g = std::tan(F_PI * cutoff / sampleRate); - const float ginv = g / (1.f + g * (g + F_SQRT_2)); + const float g = std::tan(numbers::pi_v * cutoff / sampleRate); + const float ginv = g / (1.f + g * (g + numbers::sqrt2_v)); m_g1 = ginv; - m_g2 = 2.f * (g + F_SQRT_2) * ginv; + m_g2 = 2.f * (g + numbers::sqrt2_v) * ginv; m_g3 = g * ginv; m_g4 = 2.f * ginv; } diff --git a/plugins/MultitapEcho/MultitapEcho.h b/plugins/MultitapEcho/MultitapEcho.h index 8c8a007aaaa..676c59ff554 100644 --- a/plugins/MultitapEcho/MultitapEcho.h +++ b/plugins/MultitapEcho/MultitapEcho.h @@ -54,7 +54,7 @@ class MultitapEchoEffect : public Effect inline void setFilterFreq( float fc, StereoOnePole & f ) { - const float b1 = expf( -2.0f * F_PI * fc ); + const float b1 = expf(-numbers::tau_v * fc); f.setCoeffs( 1.0f - b1, b1 ); } diff --git a/plugins/Xpressive/ExprSynth.cpp b/plugins/Xpressive/ExprSynth.cpp index c48b94ec8dc..79bf9892a36 100644 --- a/plugins/Xpressive/ExprSynth.cpp +++ b/plugins/Xpressive/ExprSynth.cpp @@ -398,7 +398,7 @@ struct sin_wave static inline float process(float x) { x = positiveFraction(x); - return sinf(x * F_2PI); + return sinf(x * numbers::tau_v); } }; static freefunc1 sin_wave_func; @@ -520,7 +520,7 @@ ExprFront::ExprFront(const char * expr, int last_func_samples) m_data->m_expression_string = expr; m_data->m_symbol_table.add_pi(); - m_data->m_symbol_table.add_constant("e", F_E); + m_data->m_symbol_table.add_constant("e", numbers::e_v); m_data->m_symbol_table.add_constant("seed", SimpleRandom::generator() & max_float_integer_mask); diff --git a/plugins/Xpressive/Xpressive.cpp b/plugins/Xpressive/Xpressive.cpp index 23a76b22820..ea29778e630 100644 --- a/plugins/Xpressive/Xpressive.cpp +++ b/plugins/Xpressive/Xpressive.cpp @@ -252,14 +252,14 @@ void Xpressive::smooth(float smoothness,const graphModel * in,graphModel * out) const int guass_size = (int)(smoothness * 5) | 1; const int guass_center = guass_size/2; const float delta = smoothness; - const float a= 1.0f / (sqrtf(2.0f * F_PI) * delta); + const float a = 1.0f / (sqrtf(numbers::tau_v) * delta); auto const guassian = new float[guass_size]; float sum = 0.0f; float temp = 0.0f; for (int i = 0; i < guass_size; i++) { temp = (i - guass_center) / delta; - sum += guassian[i] = a * powf(F_E, -0.5f * temp * temp); + sum += guassian[i] = a * expf(-0.5f * temp * temp); } for (int i = 0; i < guass_size; i++) { diff --git a/src/core/BandLimitedWave.cpp b/src/core/BandLimitedWave.cpp index 060ff510a43..466482fabe5 100644 --- a/src/core/BandLimitedWave.cpp +++ b/src/core/BandLimitedWave.cpp @@ -103,8 +103,8 @@ void BandLimitedWave::generateWaves() { hlen = static_cast( len ) / static_cast( harm ); const double amp = -1.0 / static_cast( harm ); - //const double a2 = cos( om * harm * F_2PI ); - s += amp * /*a2 **/sin( static_cast( ph * harm ) / static_cast( len ) * F_2PI ); + //const double a2 = cos(om * harm * numbers::tau_v); + s += amp * /*a2 **/sin(static_cast(ph * harm) / static_cast(len) * numbers::tau_v); harm++; } while( hlen > 2.0 ); s_waveforms[static_cast(BandLimitedWave::Waveform::BLSaw)].setSampleAt( i, ph, s ); @@ -145,8 +145,8 @@ void BandLimitedWave::generateWaves() { hlen = static_cast( len ) / static_cast( harm ); const double amp = 1.0 / static_cast( harm ); - //const double a2 = cos( om * harm * F_2PI ); - s += amp * /*a2 **/ sin( static_cast( ph * harm ) / static_cast( len ) * F_2PI ); + //const double a2 = cos(om * harm * numbers::tau_v); + s += amp * /*a2 **/ sin(static_cast(ph * harm) / static_cast(len) * numbers::tau_v); harm += 2; } while( hlen > 2.0 ); s_waveforms[static_cast(BandLimitedWave::Waveform::BLSquare)].setSampleAt( i, ph, s ); @@ -186,9 +186,9 @@ void BandLimitedWave::generateWaves() { hlen = static_cast( len ) / static_cast( harm ); const double amp = 1.0 / static_cast( harm * harm ); - //const double a2 = cos( om * harm * F_2PI ); - s += amp * /*a2 **/ sin( ( static_cast( ph * harm ) / static_cast( len ) + - ( ( harm + 1 ) % 4 == 0 ? 0.5 : 0.0 ) ) * F_2PI ); + //const double a2 = cos(om * harm * numbers::tau_v); + s += amp * /*a2 **/ sin((static_cast(ph * harm) / static_cast(len) + + ((harm + 1) % 4 == 0 ? 0.5 : 0.0)) * numbers::tau_v); harm += 2; } while( hlen > 2.0 ); s_waveforms[static_cast(BandLimitedWave::Waveform::BLTriangle)].setSampleAt( i, ph, s ); @@ -273,4 +273,4 @@ moogfile.close(); } -} // namespace lmms \ No newline at end of file +} // namespace lmms diff --git a/src/core/Instrument.cpp b/src/core/Instrument.cpp index 9237ad70dbe..40cb96aa13d 100644 --- a/src/core/Instrument.cpp +++ b/src/core/Instrument.cpp @@ -152,7 +152,7 @@ void Instrument::applyFadeIn(SampleFrame* buf, NotePlayHandle * n) { for (ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch) { - buf[offset + f][ch] *= 0.5 - 0.5 * cosf(F_PI * (float) f / (float) n->m_fadeInLength); + buf[offset + f][ch] *= 0.5 - 0.5 * cosf(numbers::pi_v * (float) f / (float) n->m_fadeInLength); } } } @@ -168,7 +168,7 @@ void Instrument::applyFadeIn(SampleFrame* buf, NotePlayHandle * n) for (ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch) { float currentLength = n->m_fadeInLength * (1.0f - (float) f / frames) + new_length * ((float) f / frames); - buf[f][ch] *= 0.5 - 0.5 * cosf(F_PI * (float) (total + f) / currentLength); + buf[f][ch] *= 0.5 - 0.5 * cosf(numbers::pi_v * (float) (total + f) / currentLength); if (total + f >= currentLength) { n->m_fadeInLength = currentLength; diff --git a/src/core/Oscillator.cpp b/src/core/Oscillator.cpp index a875cf2d4f4..8425fd513bd 100644 --- a/src/core/Oscillator.cpp +++ b/src/core/Oscillator.cpp @@ -127,7 +127,7 @@ void Oscillator::generateSawWaveTable(int bands, sample_t* table, int firstBand) const float imod = (i - OscillatorConstants::WAVETABLE_LENGTH / 2.f) / OscillatorConstants::WAVETABLE_LENGTH; for (int n = firstBand; n <= bands; n++) { - table[i] += (n % 2 ? 1.0f : -1.0f) / n * sinf(F_2PI * n * imod) / F_PI_2; + table[i] += (n % 2 ? 1.0f : -1.0f) / n * sinf(numbers::tau_v * n * imod) / numbers::pi_half_v; } } } @@ -143,7 +143,7 @@ void Oscillator::generateTriangleWaveTable(int bands, sample_t* table, int first for (int n = firstBand | 1; n <= bands; n += 2) { table[i] += (n & 2 ? -1.0f : 1.0f) / powf(n, 2.0f) * - sinf(F_2PI * n * i / (float)OscillatorConstants::WAVETABLE_LENGTH) / (F_PI_SQR / 8); + sinf(numbers::tau_v * n * i / (float)OscillatorConstants::WAVETABLE_LENGTH) / (numbers::pi_sqr_v / 8); } } } @@ -158,7 +158,9 @@ void Oscillator::generateSquareWaveTable(int bands, sample_t* table, int firstBa { for (int n = firstBand | 1; n <= bands; n += 2) { - table[i] += (1.0f / n) * sinf(F_2PI * i * n / OscillatorConstants::WAVETABLE_LENGTH) / (F_PI / 4); + table[i] += (1.0f / n) + * sinf(numbers::tau_v * i * n / OscillatorConstants::WAVETABLE_LENGTH) + / (numbers::pi_v / 4); } } } diff --git a/src/core/fft_helpers.cpp b/src/core/fft_helpers.cpp index c2431034170..0e9eeb47663 100644 --- a/src/core/fft_helpers.cpp +++ b/src/core/fft_helpers.cpp @@ -144,9 +144,9 @@ int precomputeWindow(float *window, unsigned int length, FFTWindow type, bool no // common computation for cosine-sum based windows for (unsigned int i = 0; i < length; i++) { - window[i] = (a0 - a1 * cos(2 * F_PI * i / ((float)length - 1.0)) - + a2 * cos(4 * F_PI * i / ((float)length - 1.0)) - - a3 * cos(6 * F_PI * i / ((float)length - 1.0))); + window[i] = (a0 - a1 * cos(2 * numbers::pi_v * i / ((float)length - 1.0)) + + a2 * cos(4 * numbers::pi_v * i / ((float)length - 1.0)) + - a3 * cos(6 * numbers::pi_v * i / ((float)length - 1.0))); gain += window[i]; } diff --git a/src/gui/widgets/Knob.cpp b/src/gui/widgets/Knob.cpp index 8941dcc29d4..bea5cb1dfed 100644 --- a/src/gui/widgets/Knob.cpp +++ b/src/gui/widgets/Knob.cpp @@ -316,7 +316,7 @@ void Knob::setTextColor( const QColor & c ) QLineF Knob::calculateLine( const QPointF & _mid, float _radius, float _innerRadius ) const { - const float rarc = m_angle * F_PI / 180.0; + const float rarc = m_angle * numbers::pi_v / 180.0; const float ca = cos( rarc ); const float sa = -sin( rarc ); From 07941706b3aa7abc43185cc33cf6ce09e0441bbd Mon Sep 17 00:00:00 2001 From: Fawn Sannar Date: Thu, 28 Nov 2024 00:00:50 -0700 Subject: [PATCH 7/8] Remove panning_constants.h Moves the four constants in panning_constants.h into panning.h, then removes panning.h. --- include/MidiEvent.h | 2 +- include/panning.h | 5 ++++- include/panning_constants.h | 41 ------------------------------------- src/tracks/SampleTrack.cpp | 2 +- 4 files changed, 6 insertions(+), 44 deletions(-) delete mode 100644 include/panning_constants.h diff --git a/include/MidiEvent.h b/include/MidiEvent.h index 453f6541098..b23f6a99f42 100644 --- a/include/MidiEvent.h +++ b/include/MidiEvent.h @@ -27,7 +27,7 @@ #include #include "Midi.h" -#include "panning_constants.h" +#include "panning.h" #include "volume.h" namespace lmms diff --git a/include/panning.h b/include/panning.h index 0fd74d1cc5a..2945988ba26 100644 --- a/include/panning.h +++ b/include/panning.h @@ -27,7 +27,6 @@ #define LMMS_PANNING_H #include "lmms_basics.h" -#include "panning_constants.h" #include "Midi.h" #include "volume.h" @@ -36,6 +35,10 @@ namespace lmms { +inline constexpr panning_t PanningRight = 100; +inline constexpr panning_t PanningLeft = -PanningRight; +inline constexpr panning_t PanningCenter = 0; +inline constexpr panning_t DefaultPanning = PanningCenter; inline StereoVolumeVector panningToVolumeVector( panning_t _p, float _scale = 1.0f ) diff --git a/include/panning_constants.h b/include/panning_constants.h deleted file mode 100644 index 8f40219f8d4..00000000000 --- a/include/panning_constants.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * panning_constants.h - declaration of some constants, concerning the - * panning of a note - * - * Copyright (c) 2004-2009 Tobias Doerffel - * - * This file is part of LMMS - https://lmms.io - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program (see COPYING); if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - */ - -#ifndef LMMS_PANNING_CONSTANTS_H -#define LMMS_PANNING_CONSTANTS_H - -namespace lmms -{ - - -constexpr panning_t PanningRight = ( 0 + 100 ); -constexpr panning_t PanningLeft = - PanningRight; -constexpr panning_t PanningCenter = 0; -constexpr panning_t DefaultPanning = PanningCenter; - - -} // namespace lmms - -#endif // LMMS_PANNING_CONSTANTS_H diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 8ad75799dd0..c17e3718c68 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -29,7 +29,7 @@ #include "EffectChain.h" #include "Mixer.h" -#include "panning_constants.h" +#include "panning.h" #include "PatternStore.h" #include "PatternTrack.h" #include "SampleClip.h" From d96ff66a49a9e9476c14b17fc871387c7c3de83c Mon Sep 17 00:00:00 2001 From: Fawn Sannar Date: Fri, 29 Nov 2024 01:04:10 -0700 Subject: [PATCH 8/8] Use std::exp(n) instead of powf(numbers::e, n) --- include/BasicFilters.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/BasicFilters.h b/include/BasicFilters.h index 663941c0cab..c667569cc7b 100644 --- a/include/BasicFilters.h +++ b/include/BasicFilters.h @@ -773,7 +773,7 @@ class BasicFilters // (Empirical tunning) m_p = ( 3.6f - 3.2f * f ) * f; m_k = 2.0f * m_p - 1; - m_r = _q * powf(numbers::e_v, (1 - m_p) * 1.386249f); + m_r = _q * std::exp((1 - m_p) * 1.386249f); if( m_doubleFilter ) { @@ -790,7 +790,7 @@ class BasicFilters m_p = ( 3.6f - 3.2f * f ) * f; m_k = 2.0f * m_p - 1.0f; - m_r = _q * 0.1f * powf(numbers::e_v, (1 - m_p) * 1.386249f); + m_r = _q * 0.1f * std::exp((1 - m_p) * 1.386249f); return; }