AME
ame_RcLowPass.hpp
Go to the documentation of this file.
1
11#pragma once
12
13#include "ame_Math.hpp"
14
15#include <cassert>
16#include <concepts>
17#include <type_traits>
18
19namespace ame::dsp
20{
26template <std::floating_point FloatType>
28{
29 static_assert (! std::is_const<FloatType>::value, "FloatType is must NOT be const.");
30
31public:
32 explicit RcLowPass (FloatType sampleRate)
33 : samplePeriod (FloatType (1.0) / sampleRate)
34 {
35 }
36 ~RcLowPass() = default;
37
39 void setSampleRate (FloatType newSampleRate) noexcept
40 {
41 samplePeriod = FloatType (1.0) / newSampleRate;
42 }
43
48 void setCutOffFrequency (FloatType cutOffFrequency) noexcept
49 {
50 coef = (ame::twoPi<FloatType> * cutOffFrequency * samplePeriod) / (ame::twoPi<FloatType> * cutOffFrequency * samplePeriod + 1);
51 }
52
57 void setRawCoefficient (FloatType newRawCoefficient)
58 {
59 assert (0.0f < newRawCoefficient && newRawCoefficient <= 1.0f);
60 coef = newRawCoefficient;
61 }
62
66 FloatType getRawCoefficient() const noexcept
67 {
68 return coef;
69 }
70
75 FloatType process (FloatType input) noexcept
76 {
77 lastOutput = coef * input + (FloatType (1.0) - coef) * lastOutput;
78 return lastOutput;
79 }
80
81private:
82 FloatType coef { 1.0 };
83 FloatType lastOutput {};
84 FloatType samplePeriod { 1.0f / 48000.0f };
85};
86} // namespace ame::dsp
Math functions.
RC low-pass filter for parameter smoothing.
Definition: ame_RcLowPass.hpp:28
void setCutOffFrequency(FloatType cutOffFrequency) noexcept
LPF cutoff.
Definition: ame_RcLowPass.hpp:48
void setRawCoefficient(FloatType newRawCoefficient)
Set raw coefficient value.
Definition: ame_RcLowPass.hpp:57
void setSampleRate(FloatType newSampleRate) noexcept
Set new sampleRate.
Definition: ame_RcLowPass.hpp:39
FloatType getRawCoefficient() const noexcept
Get raw value of coefficient.
Definition: ame_RcLowPass.hpp:66
FloatType process(FloatType input) noexcept
Process filter.
Definition: ame_RcLowPass.hpp:75