-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
294cc82
commit f6a6e6f
Showing
4 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include <grit/audio/waveshape/wave_shaper.hpp> | ||
#include <grit/audio/waveshape/wave_shaper_adaa1.hpp> | ||
|
||
#include <etl/cmath.hpp> | ||
#include <etl/concepts.hpp> | ||
|
||
namespace grit { | ||
|
||
template<etl::floating_point Float> | ||
struct DiodeRectifierNonlinearity | ||
{ | ||
constexpr DiodeRectifierNonlinearity() = default; | ||
|
||
[[nodiscard]] constexpr auto operator()(Float x) const -> Float { return f(x); } | ||
|
||
[[nodiscard]] static constexpr auto f(Float x) -> Float | ||
{ | ||
return Float(0.2) * etl::exp(Float(1.79) * x) - Float(0.2); | ||
} | ||
|
||
[[nodiscard]] static constexpr auto ad1(Float x) -> Float | ||
{ | ||
return Float(-0.2) * x + Float(0.111731843575419) * etl::exp(Float(1.79) * x); | ||
} | ||
}; | ||
|
||
template<etl::floating_point Float> | ||
using DiodeRectifier = WaveShaper<Float, DiodeRectifierNonlinearity<Float>>; | ||
|
||
template<etl::floating_point Float> | ||
using DiodeRectifierADAA1 = WaveShaperADAA1<Float, DiodeRectifierNonlinearity<Float>>; | ||
|
||
} // namespace grit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "diode_rectifier.hpp" | ||
|
||
#include <catch2/catch_approx.hpp> | ||
#include <catch2/catch_template_test_macros.hpp> | ||
|
||
TEMPLATE_TEST_CASE("grit/audio/waveshape: DiodeRectifier", "", double) | ||
{ | ||
using Float = TestType; | ||
|
||
auto shaper = grit::DiodeRectifier<Float>{}; | ||
STATIC_REQUIRE(etl::is_empty_v<grit::DiodeRectifier<Float>>); | ||
|
||
REQUIRE(shaper(Float(-2.0)) == Catch::Approx(-0.1944248603)); | ||
REQUIRE(shaper(Float(-1.5)) == Catch::Approx(-0.1863557612)); | ||
REQUIRE(shaper(Float(+0.0)) == Catch::Approx(+0.0)); | ||
REQUIRE(shaper(Float(+1.0)) == Catch::Approx(+0.9978904933)); | ||
} | ||
|
||
TEMPLATE_TEST_CASE("grit/audio/waveshape: DiodeRectifierADAA1", "", float, double) | ||
{ | ||
using Float = TestType; | ||
|
||
auto shaper = grit::DiodeRectifierADAA1<Float>{}; | ||
REQUIRE(shaper(Float(-2.0)) < Float(0)); | ||
REQUIRE(shaper(Float(-2.0)) == Catch::Approx(-0.1944248603)); | ||
|
||
REQUIRE(shaper(Float(-1.5)) < Float(0)); | ||
REQUIRE(shaper(Float(-1.5)) == Catch::Approx(-0.1863557612)); | ||
} |