22 static_assert(std::is_floating_point_v<SampleType>);
35 if (std::isfinite(
static_cast<double>(gain)))
41 if (std::isfinite(
static_cast<double>(pole)))
47 return static_cast<SampleType
>(reflection_gain_);
49 [[nodiscard]] SampleType
loss_pole() const noexcept {
50 return static_cast<SampleType
>(loss_pole_);
53 [[nodiscard]] SampleType
process(SampleType input)
noexcept {
54 const auto x =
static_cast<double>(input);
55 if (!std::isfinite(x))
56 return finite_cast(last_output_);
58 const auto output = reflection_gain_ * (1.0 - loss_pole_) * x +
59 loss_pole_ * last_output_;
60 if (!std::isfinite(output)) {
65 return finite_cast(last_output_);
68 void reset() noexcept { last_output_ = 0.0; }
71 [[nodiscard]]
static SampleType finite_cast(
double value)
noexcept {
72 const auto limit =
static_cast<double>(std::numeric_limits<SampleType>::max());
73 if (!std::isfinite(value) || value > limit || value < -limit)
75 return static_cast<SampleType
>(value);
80 double last_output_ = 0.0;
A passive boundary filter with H(z) = g (1 - a) / (1 - a z^-1).
Definition waveguide_reflection_filter.hpp:21
void set_reflection_gain(SampleType gain) noexcept
Definition waveguide_reflection_filter.hpp:34
void set_loss_pole(SampleType pole) noexcept
Definition waveguide_reflection_filter.hpp:40
SampleType loss_pole() const noexcept
Definition waveguide_reflection_filter.hpp:49
static constexpr double minimum_loss_pole
Definition waveguide_reflection_filter.hpp:28
SampleType process(SampleType input) noexcept
Definition waveguide_reflection_filter.hpp:53
static constexpr double default_reflection_gain
Definition waveguide_reflection_filter.hpp:27
static constexpr double maximum_loss_pole
Definition waveguide_reflection_filter.hpp:31
static constexpr double minimum_reflection_gain
Definition waveguide_reflection_filter.hpp:25
static constexpr double maximum_reflection_gain
Definition waveguide_reflection_filter.hpp:26
static constexpr double default_loss_pole
Definition waveguide_reflection_filter.hpp:32
void reset() noexcept
Definition waveguide_reflection_filter.hpp:68
SampleType reflection_gain() const noexcept
Definition waveguide_reflection_filter.hpp:46
Definition additive_bank.hpp:218
WaveguideReflectionFilterT< float > WaveguideReflectionFilter
Definition waveguide_reflection_filter.hpp:83
WaveguideReflectionFilterT< double > WaveguideReflectionFilter64
Definition waveguide_reflection_filter.hpp:84
T snap_recursion_state(T x)
Snap a per-sample recursion's state: snap_to_zero() where subnormals are slow, the identity where kSu...
Definition denormal.hpp:84