Skip to content

Commit

Permalink
Allow for users to provide their own Omega function implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Dec 1, 2023
1 parent 0dfd1bd commit 7a3c85e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
8 changes: 8 additions & 0 deletions include/chowdsp_wdf/math/omega.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ namespace Omega
return y - (y - exp_approx<T> (x - y)) / (y + (T) 1);
}

struct Omega
{
template <typename T>
static T omega (T x)
{
return omega4 (x);
}
};
} // namespace Omega
} // namespace chowdsp

Expand Down
8 changes: 4 additions & 4 deletions include/chowdsp_wdf/wdft/wdft_nonlinearities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T, typename Next, DiodeQuality Quality = DiodeQuality::Best>
template <typename T, typename Next, DiodeQuality Quality = DiodeQuality::Best, typename OmegaProvider = Omega::Omega>
class DiodePairT final : public RootWDF
{
public:
Expand Down Expand Up @@ -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). */
Expand Down Expand Up @@ -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 <typename T, typename Next, DiodeQuality Quality = DiodeQuality::Best>
template <typename T, typename Next, DiodeQuality Quality = DiodeQuality::Best, typename OmegaProvider = Omega::Omega>
class DiodeT final : public RootWDF
{
public:
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 7a3c85e

Please sign in to comment.