From 7a3c85e47346af7765c23c8855b032f6c0bcdedb Mon Sep 17 00:00:00 2001 From: jatin Date: Thu, 30 Nov 2023 22:57:56 -0800 Subject: [PATCH] Allow for users to provide their own Omega function implementation --- CMakeLists.txt | 2 +- include/chowdsp_wdf/math/omega.h | 8 ++++++++ include/chowdsp_wdf/wdft/wdft_nonlinearities.h | 8 ++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3acb03d..b964e10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(chowdsp_wdf VERSION 1.0.0 LANGUAGES C CXX) include(cmake/CXXStandard.cmake) diff --git a/include/chowdsp_wdf/math/omega.h b/include/chowdsp_wdf/math/omega.h index 5ecb4cf..f29c170 100644 --- a/include/chowdsp_wdf/math/omega.h +++ b/include/chowdsp_wdf/math/omega.h @@ -323,6 +323,14 @@ namespace Omega return y - (y - exp_approx (x - y)) / (y + (T) 1); } + struct Omega + { + template + static T omega (T x) + { + return omega4 (x); + } + }; } // namespace Omega } // namespace chowdsp diff --git a/include/chowdsp_wdf/wdft/wdft_nonlinearities.h b/include/chowdsp_wdf/wdft/wdft_nonlinearities.h index 29c443f..c7a2176 100644 --- a/include/chowdsp_wdf/wdft/wdft_nonlinearities.h +++ b/include/chowdsp_wdf/wdft/wdft_nonlinearities.h @@ -24,7 +24,7 @@ namespace wdft * See Werner et al., "An Improved and Generalized Diode Clipper Model for Wave Digital Filters" * https://www.researchgate.net/publication/299514713_An_Improved_and_Generalized_Diode_Clipper_Model_for_Wave_Digital_Filters */ - template + template class DiodePairT final : public RootWDF { public: @@ -86,7 +86,7 @@ namespace wdft { // See eqn (18) from reference paper T lambda = (T) signum::signum (wdf.a); - wdf.b = wdf.a + (T) 2 * lambda * (R_Is - Vt * Omega::omega4 (logR_Is_overVt + lambda * wdf.a * oneOverVt + R_Is_overVt)); + wdf.b = wdf.a + (T) 2 * lambda * (R_Is - Vt * OmegaProvider::omega (logR_Is_overVt + lambda * wdf.a * oneOverVt + R_Is_overVt)); } /** Implementation for float/double (Best). */ @@ -118,7 +118,7 @@ namespace wdft * See Werner et al., "An Improved and Generalized Diode Clipper Model for Wave Digital Filters" * https://www.researchgate.net/publication/299514713_An_Improved_and_Generalized_Diode_Clipper_Model_for_Wave_Digital_Filters */ - template + template class DiodeT final : public RootWDF { public: @@ -167,7 +167,7 @@ namespace wdft inline T reflected() noexcept { // See eqn (10) from reference paper - wdf.b = wdf.a + twoR_Is - twoVt * Omega::omega4 (logR_Is_overVt + wdf.a * oneOverVt + R_Is_overVt); + wdf.b = wdf.a + twoR_Is - twoVt * OmegaProvider::omega (logR_Is_overVt + wdf.a * oneOverVt + R_Is_overVt); return wdf.b; }