From 385bb55834d8f695c63107fd937c2500ceb910f6 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 17 Apr 2023 11:18:24 -0400 Subject: [PATCH] Move FastMath entirely to sst-basic-blocks; turn on gcc12 build (#6943) FastMath is now entirely from sst-basic-blocks for both filters and for surge. Closes #6532 --- libs/sst/sst-basic-blocks | 2 +- libs/sst/sst-filters | 2 +- src/common/CMakeLists.txt | 3 +- src/common/dsp/Oscillator.cpp | 2 +- .../dsp/effects/RingModulatorEffect.cpp | 7 +- src/common/dsp/effects/WaveShaperEffect.cpp | 2 +- .../dsp/effects/chowdsp/shared/wdf_sse.h | 2 +- .../spring_reverb/SpringReverbProc.cpp | 4 +- .../dsp/effects/chowdsp/tape/HysteresisOps.h | 3 +- .../dsp/modulators/MSEGModulationHelper.cpp | 2 +- src/common/dsp/oscillators/SineOscillator.cpp | 15 +- .../dsp/oscillators/StringOscillator.cpp | 5 +- src/common/dsp/utilities/FastMath.h | 225 ----------------- src/common/dsp/utilities/SSEComplex.h | 7 +- src/surge-testrunner/UnitTestsDSP.cpp | 232 ------------------ src/surge-testrunner/UnitTestsFLT.cpp | 1 - src/surge-testrunner/UnitTestsFX.cpp | 1 - src/surge-testrunner/UnitTestsMSEG.cpp | 1 - 18 files changed, 30 insertions(+), 486 deletions(-) delete mode 100644 src/common/dsp/utilities/FastMath.h diff --git a/libs/sst/sst-basic-blocks b/libs/sst/sst-basic-blocks index 98ba4587d5c..1843aab5cd6 160000 --- a/libs/sst/sst-basic-blocks +++ b/libs/sst/sst-basic-blocks @@ -1 +1 @@ -Subproject commit 98ba4587d5cdcbb8dee090db814b32ce4c946a44 +Subproject commit 1843aab5cd6f23f78cef4bdee5348feb0a76cfc0 diff --git a/libs/sst/sst-filters b/libs/sst/sst-filters index a0ce9e83534..5fa85393e65 160000 --- a/libs/sst/sst-filters +++ b/libs/sst/sst-filters @@ -1 +1 @@ -Subproject commit a0ce9e835347bf16099901d5f1bbbb2c1d3ae84d +Subproject commit 5fa85393e655dec6de281cf6919319ac5738e26f diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 0bcf91049c0..63d5b3c9005 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -31,11 +31,11 @@ else() target_compile_definitions(luajit-5.1 INTERFACE HAS_LUA=0) endif() +surge_add_lib_subdirectory(sst/sst-basic-blocks) surge_add_lib_subdirectory(sst/sst-cpputils) surge_add_lib_subdirectory(sst/sst-plugininfra) surge_add_lib_subdirectory(sst/sst-filters) surge_add_lib_subdirectory(sst/sst-waveshapers) -surge_add_lib_subdirectory(sst/sst-basic-blocks) set(PEGTL_BUILD_TESTS OFF CACHE BOOL "") set(PEGTL_BUILD_EXAMPLES OFF CACHE BOOL "") @@ -279,7 +279,6 @@ add_library(${PROJECT_NAME} dsp/oscillators/WindowOscillator.h dsp/utilities/DSPUtils.cpp dsp/utilities/DSPUtils.h - dsp/utilities/FastMath.h dsp/utilities/SSEComplex.h dsp/utilities/SSESincDelayLine.h dsp/vembertech/basic_dsp.cpp diff --git a/src/common/dsp/Oscillator.cpp b/src/common/dsp/Oscillator.cpp index 10c06314f1e..2d2dc1932dd 100644 --- a/src/common/dsp/Oscillator.cpp +++ b/src/common/dsp/Oscillator.cpp @@ -15,7 +15,7 @@ #include "Oscillator.h" #include "DSPUtils.h" -#include "FastMath.h" +#include "sst/basic-blocks/dsp/FastMath.h" #include #include "AliasOscillator.h" diff --git a/src/common/dsp/effects/RingModulatorEffect.cpp b/src/common/dsp/effects/RingModulatorEffect.cpp index 06c0b600238..d30e9879e06 100644 --- a/src/common/dsp/effects/RingModulatorEffect.cpp +++ b/src/common/dsp/effects/RingModulatorEffect.cpp @@ -2,7 +2,7 @@ #include "Tunings.h" #include "SineOscillator.h" #include "DebugHelpers.h" -#include "FastMath.h" +#include "sst/basic-blocks/dsp/FastMath.h" // http://recherche.ircam.fr/pub/dafx11/Papers/66_e.pdf @@ -119,8 +119,9 @@ void RingModulatorEffect::process(float *dataL, float *dataR) { // TODO efficiency of course auto vc = SineOscillator::valueFromSinAndCos( - Surge::DSP::fastsin(2.0 * M_PI * (phase[u] - 0.5)), - Surge::DSP::fastcos(2.0 * M_PI * (phase[u] - 0.5)), *pd_int[rm_carrier_shape]); + sst::basic_blocks::dsp::fastsin(2.0 * M_PI * (phase[u] - 0.5)), + sst::basic_blocks::dsp::fastcos(2.0 * M_PI * (phase[u] - 0.5)), + *pd_int[rm_carrier_shape]); phase[u] += dphase[u]; if (phase[u] > 1) diff --git a/src/common/dsp/effects/WaveShaperEffect.cpp b/src/common/dsp/effects/WaveShaperEffect.cpp index 4cc25c21718..a834e773df2 100644 --- a/src/common/dsp/effects/WaveShaperEffect.cpp +++ b/src/common/dsp/effects/WaveShaperEffect.cpp @@ -15,7 +15,7 @@ #include "WaveShaperEffect.h" #include "DebugHelpers.h" -#include "FastMath.h" +#include "sst/basic-blocks/dsp/FastMath.h" // http://recherche.ircam.fr/pub/dafx11/Papers/66_e.pdf diff --git a/src/common/dsp/effects/chowdsp/shared/wdf_sse.h b/src/common/dsp/effects/chowdsp/shared/wdf_sse.h index b107b67ae8a..4c820043dfc 100644 --- a/src/common/dsp/effects/chowdsp/shared/wdf_sse.h +++ b/src/common/dsp/effects/chowdsp/shared/wdf_sse.h @@ -4,7 +4,7 @@ #include #include #include -#include "FastMath.h" +#include "sst/basic-blocks/dsp/FastMath.h" #include "portable_intrinsics.h" namespace chowdsp diff --git a/src/common/dsp/effects/chowdsp/spring_reverb/SpringReverbProc.cpp b/src/common/dsp/effects/chowdsp/spring_reverb/SpringReverbProc.cpp index 5116bdf51d1..182df584a78 100644 --- a/src/common/dsp/effects/chowdsp/spring_reverb/SpringReverbProc.cpp +++ b/src/common/dsp/effects/chowdsp/spring_reverb/SpringReverbProc.cpp @@ -1,7 +1,7 @@ #include #include "SpringReverbProc.h" -#include "utilities/FastMath.h" +#include "sst/basic-blocks/dsp/FastMath.h" namespace { @@ -111,7 +111,7 @@ void SpringReverbProc::processBlock(float *left, float *right, const int numSamp } auto doSpringInput = [=](int ch, float input, int n) -> float { - auto output = Surge::DSP::fasttanh(input - feedbackGain * delay.popSample(ch)); + auto output = sst::basic_blocks::dsp::fasttanh(input - feedbackGain * delay.popSample(ch)); return dcBlocker.processSample(ch, output) + shortShakeBuffer[n]; }; diff --git a/src/common/dsp/effects/chowdsp/tape/HysteresisOps.h b/src/common/dsp/effects/chowdsp/tape/HysteresisOps.h index 516c8fcaf25..e66d73d667b 100644 --- a/src/common/dsp/effects/chowdsp/tape/HysteresisOps.h +++ b/src/common/dsp/effects/chowdsp/tape/HysteresisOps.h @@ -1,7 +1,8 @@ #pragma once #include -#include "FastMath.h" +#include "globals.h" +#include "sst/basic-blocks/dsp/FastMath.h" #define CHOWTAPE_HYSTERESIS_USE_SIMD 1 diff --git a/src/common/dsp/modulators/MSEGModulationHelper.cpp b/src/common/dsp/modulators/MSEGModulationHelper.cpp index 5be0e53fba0..dc4f8678413 100644 --- a/src/common/dsp/modulators/MSEGModulationHelper.cpp +++ b/src/common/dsp/modulators/MSEGModulationHelper.cpp @@ -18,7 +18,7 @@ #include #include "DebugHelpers.h" #include "basic_dsp.h" // for limit_range -#include "FastMath.h" +#include "sst/basic-blocks/dsp/FastMath.h" namespace Surge { diff --git a/src/common/dsp/oscillators/SineOscillator.cpp b/src/common/dsp/oscillators/SineOscillator.cpp index 66ca590b5b0..48df1c0cd12 100644 --- a/src/common/dsp/oscillators/SineOscillator.cpp +++ b/src/common/dsp/oscillators/SineOscillator.cpp @@ -14,7 +14,7 @@ */ #include "SineOscillator.h" -#include "FastMath.h" +#include "sst/basic-blocks/dsp/FastMath.h" #include /* @@ -671,10 +671,10 @@ void SineOscillator::process_block_internal(float pitch, float drift, float fmde auto lv = _mm_load_ps(&lastvalue[u]); auto x = _mm_add_ps(_mm_add_ps(ph, lv), fmpds); - x = Surge::DSP::clampToPiRangeSSE(x); + x = sst::basic_blocks::dsp::clampToPiRangeSSE(x); - auto sxl = Surge::DSP::fastsinSSE(x); - auto cxl = Surge::DSP::fastcosSSE(x); + auto sxl = sst::basic_blocks::dsp::fastsinSSE(x); + auto cxl = sst::basic_blocks::dsp::fastcosSSE(x); auto out_local = valueFromSinAndCosForMode(sxl, cxl, std::min(n_unison - u, 4)); @@ -787,8 +787,9 @@ void SineOscillator::process_block_legacy(float pitch, float drift, bool stereo, for (int u = 0; u < n_unison; u++) { - float out_local = singleValueFromSinAndCos(Surge::DSP::fastsin(phase[u]), - Surge::DSP::fastcos(phase[u])); + float out_local = + singleValueFromSinAndCos(sst::basic_blocks::dsp::fastsin(phase[u]), + sst::basic_blocks::dsp::fastcos(phase[u])); outL += (panL[u] * out_local) * out_attenuation * playingramp[u]; outR += (panR[u] * out_local) * out_attenuation * playingramp[u]; @@ -799,7 +800,7 @@ void SineOscillator::process_block_legacy(float pitch, float drift, bool stereo, playingramp[u] = 1; phase[u] += omega[u] + master_osc[k] * FMdepth.v; - phase[u] = Surge::DSP::clampToPiRange(phase[u]); + phase[u] = sst::basic_blocks::dsp::clampToPiRange(phase[u]); } FMdepth.process(); diff --git a/src/common/dsp/oscillators/StringOscillator.cpp b/src/common/dsp/oscillators/StringOscillator.cpp index 7c68700b22f..6fab749dc51 100644 --- a/src/common/dsp/oscillators/StringOscillator.cpp +++ b/src/common/dsp/oscillators/StringOscillator.cpp @@ -14,7 +14,7 @@ */ #include "globals.h" -#include "FastMath.h" +#include "sst/basic-blocks/dsp/FastMath.h" /* * String oscillator is a self-oscillating delay with various filters and @@ -689,7 +689,8 @@ void StringOscillator::process_block_internal(float pitch, float drift, bool ste if (FM) { - v *= Surge::DSP::fastexp(limit_range(fmdepth.v * master_osc[i] * 3, -6.f, 4.f)); + v *= sst::basic_blocks::dsp::fastexp( + limit_range(fmdepth.v * master_osc[i] * 3, -6.f, 4.f)); } v *= OS; diff --git a/src/common/dsp/utilities/FastMath.h b/src/common/dsp/utilities/FastMath.h deleted file mode 100644 index ab6509f0761..00000000000 --- a/src/common/dsp/utilities/FastMath.h +++ /dev/null @@ -1,225 +0,0 @@ -#pragma once - -#include "globals.h" -#include - -/* -** Fast Math Approximations to various Functions -** -** Documentation on each one -*/ - -/* -** These are directly copied from JUCE6 modules/juce_dsp/mathos/juce_FastMathApproximations.h -** -** Since JUCE6 is GPL3 and Surge is GPL3 that copy is fine, but I did want to explicitly -** acknowledge it -*/ - -namespace Surge -{ -namespace DSP -{ - -// JUCE6 Pade approximation of sin valid from -PI to PI with max error of 1e-5 and average error of -// 5e-7 -inline float fastsin(float x) noexcept -{ - auto x2 = x * x; - auto numerator = -x * (-(float)11511339840 + - x2 * ((float)1640635920 + x2 * (-(float)52785432 + x2 * (float)479249))); - auto denominator = - (float)11511339840 + x2 * ((float)277920720 + x2 * ((float)3177720 + x2 * (float)18361)); - return numerator / denominator; -} - -inline __m128 fastsinSSE(__m128 x) noexcept -{ -#define M(a, b) _mm_mul_ps(a, b) -#define A(a, b) _mm_add_ps(a, b) -#define S(a, b) _mm_sub_ps(a, b) -#define F(a) _mm_set_ps1(a) -#define C(x) __m128 m##x = F((float)x) - - /* - auto numerator = -x * (-(float)11511339840 + - x2 * ((float)1640635920 + x2 * (-(float)52785432 + x2 * (float)479249))); - auto denominator = - (float)11511339840 + x2 * ((float)277920720 + x2 * ((float)3177720 + x2 * (float)18361)); - */ - C(11511339840); - C(1640635920); - C(52785432); - C(479249); - C(277920720); - C(3177720); - C(18361); - auto mnegone = F(-1); - - auto x2 = M(x, x); - - auto num = M(mnegone, - M(x, S(M(x2, A(m1640635920, M(x2, S(M(x2, m479249), m52785432)))), m11511339840))); - auto den = A(m11511339840, M(x2, A(m277920720, M(x2, A(m3177720, M(x2, m18361)))))); - -#undef C -#undef M -#undef A -#undef S -#undef F - return _mm_div_ps(num, den); -} - -// JUCE6 Pade approximation of cos valid from -PI to PI with max error of 1e-5 and average error of -// 5e-7 -inline float fastcos(float x) noexcept -{ - auto x2 = x * x; - auto numerator = -(-(float)39251520 + x2 * ((float)18471600 + x2 * (-1075032 + 14615 * x2))); - auto denominator = (float)39251520 + x2 * (1154160 + x2 * (16632 + x2 * 127)); - return numerator / denominator; -} - -inline __m128 fastcosSSE(__m128 x) noexcept -{ -#define M(a, b) _mm_mul_ps(a, b) -#define A(a, b) _mm_add_ps(a, b) -#define S(a, b) _mm_sub_ps(a, b) -#define F(a) _mm_set_ps1(a) -#define C(x) __m128 m##x = F((float)x) - - // auto x2 = x * x; - auto x2 = M(x, x); - - C(39251520); - C(18471600); - C(1075032); - C(14615); - C(1154160); - C(16632); - C(127); - - // auto numerator = -(-(float)39251520 + x2 * ((float)18471600 + x2 * (-1075032 + 14615 * x2))); - auto num = S(m39251520, M(x2, A(m18471600, M(x2, S(M(m14615, x2), m1075032))))); - - // auto denominator = (float)39251520 + x2 * (1154160 + x2 * (16632 + x2 * 127)); - auto den = A(m39251520, M(x2, A(m1154160, M(x2, A(m16632, M(x2, m127)))))); -#undef C -#undef M -#undef A -#undef S -#undef F - return _mm_div_ps(num, den); -} - -/* -** Push x into -PI, PI periodically. There is probably a faster way to do this -*/ -inline float clampToPiRange(float x) -{ - if (x <= M_PI && x >= -M_PI) - return x; - float y = x + M_PI; // so now I am 0,2PI - - // float p = fmod( y, 2.0 * M_PI ); - - constexpr float oo2p = 1.0 / (2.0 * M_PI); - float p = y - 2.0 * M_PI * (int)(y * oo2p); - - if (p < 0) - p += 2.0 * M_PI; - return p - M_PI; -} - -inline __m128 clampToPiRangeSSE(__m128 x) -{ - const auto mpi = _mm_set1_ps(M_PI); - const auto m2pi = _mm_set1_ps(2.0 * M_PI); - const auto oo2p = _mm_set1_ps(1.0 / (2.0 * M_PI)); - const auto mz = _mm_setzero_ps(); - - auto y = _mm_add_ps(x, mpi); - auto yip = _mm_cvtepi32_ps(_mm_cvttps_epi32(_mm_mul_ps(y, oo2p))); - auto p = _mm_sub_ps(y, _mm_mul_ps(m2pi, yip)); - auto off = _mm_and_ps(_mm_cmplt_ps(p, mz), m2pi); - p = _mm_add_ps(p, off); - - return _mm_sub_ps(p, mpi); -} - -/* -** Valid in range -5, 5 -*/ -inline float fasttanh(float x) noexcept -{ - auto x2 = x * x; - auto numerator = x * (135135 + x2 * (17325 + x2 * (378 + x2))); - auto denominator = 135135 + x2 * (62370 + x2 * (3150 + 28 * x2)); - return numerator / denominator; -} - -// Valid in range (-PI/2, PI/2) -inline float fasttan(float x) noexcept -{ - auto x2 = x * x; - auto numerator = x * (-135135 + x2 * (17325 + x2 * (-378 + x2))); - auto denominator = -135135 + x2 * (62370 + x2 * (-3150 + 28 * x2)); - return numerator / denominator; -} - -inline __m128 fasttanhSSE(__m128 x) -{ - const __m128 m135135 = _mm_set_ps1(135135), m17325 = _mm_set_ps1(17325), - m378 = _mm_set_ps1(378), m62370 = _mm_set_ps1(62370), m3150 = _mm_set_ps1(3150), - m28 = _mm_set_ps1(28); - -#define M(a, b) _mm_mul_ps(a, b) -#define A(a, b) _mm_add_ps(a, b) - - auto x2 = M(x, x); - auto num = M(x, A(m135135, M(x2, A(m17325, M(x2, A(m378, x2)))))); - auto den = A(m135135, M(x2, A(m62370, M(x2, A(m3150, M(m28, x2)))))); - -#undef M -#undef A - - return _mm_div_ps(num, den); -} - -inline __m128 fasttanhSSEclamped(__m128 x) -{ - auto xc = _mm_min_ps(_mm_set_ps1(5), _mm_max_ps(_mm_set_ps1(-5), x)); - return fasttanhSSE(xc); -} - -/* -** Valid in range -6, 4 -*/ -inline float fastexp(float x) noexcept -{ - auto numerator = 1680 + x * (840 + x * (180 + x * (20 + x))); - auto denominator = 1680 + x * (-840 + x * (180 + x * (-20 + x))); - return numerator / denominator; -} - -inline __m128 fastexpSSE(__m128 x) noexcept -{ -#define M(a, b) _mm_mul_ps(a, b) -#define A(a, b) _mm_add_ps(a, b) -#define F(a) _mm_set_ps1(a) - - const __m128 m1680 = F(1680), m840 = F(840), mneg840 = F(-840), m180 = F(180), m20 = F(20), - mneg20 = F(-20); - - auto num = A(m1680, M(x, A(m840, M(x, A(m180, M(x, A(m20, x))))))); - auto den = A(m1680, M(x, A(mneg840, M(x, A(m180, M(x, A(mneg20, x))))))); - - return _mm_div_ps(num, den); - -#undef M -#undef A -#undef F -} - -} // namespace DSP -} // namespace Surge diff --git a/src/common/dsp/utilities/SSEComplex.h b/src/common/dsp/utilities/SSEComplex.h index 94e715c2c0d..ac4c31ce150 100644 --- a/src/common/dsp/utilities/SSEComplex.h +++ b/src/common/dsp/utilities/SSEComplex.h @@ -26,7 +26,7 @@ #include "globals.h" #include #include -#include "FastMath.h" +#include "sst/basic-blocks/dsp/FastMath.h" struct SSEComplex { @@ -79,8 +79,9 @@ struct SSEComplex inline static SSEComplex fastExp(__m128 angle) { - angle = Surge::DSP::clampToPiRangeSSE(angle); - return {Surge::DSP::fastcosSSE(angle), Surge::DSP::fastsinSSE(angle)}; + angle = sst::basic_blocks::dsp::clampToPiRangeSSE(angle); + return {sst::basic_blocks::dsp::fastcosSSE(angle), + sst::basic_blocks::dsp::fastsinSSE(angle)}; } inline SSEComplex map(std::function(const std::complex &)> f) diff --git a/src/surge-testrunner/UnitTestsDSP.cpp b/src/surge-testrunner/UnitTestsDSP.cpp index ec62dd77510..3fdf75a9247 100644 --- a/src/surge-testrunner/UnitTestsDSP.cpp +++ b/src/surge-testrunner/UnitTestsDSP.cpp @@ -7,7 +7,6 @@ #include "catch2/catch2.hpp" #include "UnitTestUtilities.h" -#include "FastMath.h" #include "SSESincDelayLine.h" @@ -358,237 +357,6 @@ TEST_CASE("lipol_ps class", "[dsp]") } } -TEST_CASE("Check FastMath Functions", "[dsp]") -{ - SECTION("Clamp to -PI,PI") - { - for (float f = -2132.7; f < 37424.3; f += 0.741) - { - float q = Surge::DSP::clampToPiRange(f); - INFO("Clamping " << f << " to " << q); - REQUIRE(q > -M_PI); - REQUIRE(q < M_PI); - } - } - - SECTION("fastSin and fastCos in range -PI, PI") - { - float sds = 0, md = 0; - int nsamp = 100000; - for (int i = 0; i < nsamp; ++i) - { - float p = 2.f * M_PI * rand() / RAND_MAX - M_PI; - float cp = std::cos(p); - float sp = std::sin(p); - float fcp = Surge::DSP::fastcos(p); - float fsp = Surge::DSP::fastsin(p); - - float cd = fabs(cp - fcp); - float sd = fabs(sp - fsp); - if (cd > md) - md = cd; - if (sd > md) - md = sd; - sds += cd * cd + sd * sd; - } - sds = sqrt(sds) / nsamp; - REQUIRE(md < 1e-4); - REQUIRE(sds < 1e-6); - } - - SECTION("fastSin and fastCos in range -10*PI, 10*PI with clampRange") - { - float sds = 0, md = 0; - int nsamp = 100000; - for (int i = 0; i < nsamp; ++i) - { - float p = 2.f * M_PI * rand() / RAND_MAX - M_PI; - p *= 10; - p = Surge::DSP::clampToPiRange(p); - float cp = std::cos(p); - float sp = std::sin(p); - float fcp = Surge::DSP::fastcos(p); - float fsp = Surge::DSP::fastsin(p); - - float cd = fabs(cp - fcp); - float sd = fabs(sp - fsp); - if (cd > md) - md = cd; - if (sd > md) - md = sd; - sds += cd * cd + sd * sd; - } - sds = sqrt(sds) / nsamp; - REQUIRE(md < 1e-4); - REQUIRE(sds < 1e-6); - } - - SECTION("fastSin and fastCos in range -100*PI, 100*PI with clampRange") - { - float sds = 0, md = 0; - int nsamp = 100000; - for (int i = 0; i < nsamp; ++i) - { - float p = 2.f * M_PI * rand() / RAND_MAX - M_PI; - p *= 100; - p = Surge::DSP::clampToPiRange(p); - float cp = std::cos(p); - float sp = std::sin(p); - float fcp = Surge::DSP::fastcos(p); - float fsp = Surge::DSP::fastsin(p); - - float cd = fabs(cp - fcp); - float sd = fabs(sp - fsp); - if (cd > md) - md = cd; - if (sd > md) - md = sd; - sds += cd * cd + sd * sd; - } - sds = sqrt(sds) / nsamp; - REQUIRE(md < 1e-4); - REQUIRE(sds < 1e-6); - } - - SECTION("fastTanh and fastTanhSSE") - { - for (float x = -4.9; x < 4.9; x += 0.02) - { - INFO("Testing unclamped at " << x); - auto q = _mm_set_ps1(x); - auto r = Surge::DSP::fasttanhSSE(q); - auto rn = tanh(x); - auto rd = Surge::DSP::fasttanh(x); - union - { - __m128 v; - float a[4]; - } U; - U.v = r; - REQUIRE(U.a[0] == Approx(rn).epsilon(1e-4)); - REQUIRE(rd == Approx(rn).epsilon(1e-4)); - } - - for (float x = -10; x < 10; x += 0.02) - { - INFO("Testing clamped at " << x); - auto q = _mm_set_ps1(x); - auto r = Surge::DSP::fasttanhSSEclamped(q); - auto cn = tanh(x); - union - { - __m128 v; - float a[4]; - } U; - U.v = r; - REQUIRE(U.a[0] == Approx(cn).epsilon(5e-4)); - } - } - - SECTION("fastTan") - { - // need to bump start point slightly, fasttan is only valid just after -PI/2 - for (float x = -M_PI / 2.0 + 0.001; x < M_PI / 2.0; x += 0.02) - { - INFO("Testing fasttan at " << x); - auto rn = tanf(x); - auto rd = Surge::DSP::fasttan(x); - REQUIRE(rd == Approx(rn).epsilon(1e-4)); - } - } - - SECTION("fastexp and fastexpSSE") - { - for (float x = -3.9; x < 2.9; x += 0.02) - { - INFO("Testing fastexp at " << x); - auto q = _mm_set_ps1(x); - auto r = Surge::DSP::fastexpSSE(q); - auto rn = exp(x); - auto rd = Surge::DSP::fastexp(x); - union - { - __m128 v; - float a[4]; - } U; - U.v = r; - - if (x < 0) - { - REQUIRE(U.a[0] == Approx(rn).margin(1e-3)); - REQUIRE(rd == Approx(rn).margin(1e-3)); - } - else - { - REQUIRE(U.a[0] == Approx(rn).epsilon(1e-3)); - REQUIRE(rd == Approx(rn).epsilon(1e-3)); - } - } - } - - SECTION("fastSine and fastSinSSE") - { - for (float x = -3.14; x < 3.14; x += 0.02) - { - INFO("Testing unclamped at " << x); - auto q = _mm_set_ps1(x); - auto r = Surge::DSP::fastsinSSE(q); - auto rn = sin(x); - auto rd = Surge::DSP::fastsin(x); - union - { - __m128 v; - float a[4]; - } U; - U.v = r; - REQUIRE(U.a[0] == Approx(rn).margin(1e-4)); - REQUIRE(rd == Approx(rn).margin(1e-4)); - REQUIRE(U.a[0] == Approx(rd).margin(1e-6)); - } - } - - SECTION("fastCos and fastCosSSE") - { - for (float x = -3.14; x < 3.14; x += 0.02) - { - INFO("Testing unclamped at " << x); - auto q = _mm_set_ps1(x); - auto r = Surge::DSP::fastcosSSE(q); - auto rn = cos(x); - auto rd = Surge::DSP::fastcos(x); - union - { - __m128 v; - float a[4]; - } U; - U.v = r; - REQUIRE(U.a[0] == Approx(rn).margin(1e-4)); - REQUIRE(rd == Approx(rn).margin(1e-4)); - REQUIRE(U.a[0] == Approx(rd).margin(1e-6)); - } - } - - SECTION("Clamp to -PI,PI SSE") - { - for (float f = -800.7; f < 816.4; f += 0.245) - { - auto fs = _mm_set_ps1(f); - - auto q = Surge::DSP::clampToPiRangeSSE(fs); - union - { - __m128 v; - float a[4]; - } U; - U.v = q; - for (int s = 0; s < 4; ++s) - { - REQUIRE(U.a[s] == Approx(Surge::DSP::clampToPiRange(f)).margin(1e-4)); - } - } - } -} - TEST_CASE("Sinc Delay Line", "[dsp]") { // This requires SurgeStorate to initialize its tables. Easiest way diff --git a/src/surge-testrunner/UnitTestsFLT.cpp b/src/surge-testrunner/UnitTestsFLT.cpp index 1772208b6f2..675d6746b65 100644 --- a/src/surge-testrunner/UnitTestsFLT.cpp +++ b/src/surge-testrunner/UnitTestsFLT.cpp @@ -9,7 +9,6 @@ #include "catch2/catch2.hpp" #include "UnitTestUtilities.h" -#include "FastMath.h" using namespace Surge::Test; diff --git a/src/surge-testrunner/UnitTestsFX.cpp b/src/surge-testrunner/UnitTestsFX.cpp index 00613815c12..d24716f2b72 100644 --- a/src/surge-testrunner/UnitTestsFX.cpp +++ b/src/surge-testrunner/UnitTestsFX.cpp @@ -9,7 +9,6 @@ #include "catch2/catch2.hpp" #include "UnitTestUtilities.h" -#include "FastMath.h" using namespace Surge::Test; diff --git a/src/surge-testrunner/UnitTestsMSEG.cpp b/src/surge-testrunner/UnitTestsMSEG.cpp index f2516ff8561..63264a1852c 100644 --- a/src/surge-testrunner/UnitTestsMSEG.cpp +++ b/src/surge-testrunner/UnitTestsMSEG.cpp @@ -5,7 +5,6 @@ #include "HeadlessUtils.h" #include "catch2/catch2.hpp" -#include "FastMath.h" #include "MSEGModulationHelper.h" struct msegObservation