DaisySP
Loading...
Searching...
No Matches
onepole.h
1/*
2Copyright (c) 2020 Electrosmith, Corp, Emilie Gillet
3
4Use of this source code is governed by an MIT-style
5license that can be found in the LICENSE file or at
6https://opensource.org/licenses/MIT.
7*/
8
9#ifndef DSY_ONEPOLE_H
10#define DSY_ONEPOLE_H
11
12#include "Utility/dsp.h"
13#include <cmath>
14#include <algorithm>
15
16namespace daisysp
17{
27{
28 public:
29 OnePole() {}
30 ~OnePole() {}
31
38 {
39 FILTER_MODE_LOW_PASS,
40 FILTER_MODE_HIGH_PASS
41 };
42
44 void Init()
45 {
46 Reset();
47 mode_ = FILTER_MODE_LOW_PASS;
48 }
49
51 inline void Reset() { state_ = 0.0f; }
52
56 inline void SetFrequency(float freq)
57 {
58 // Clip coefficient to about 100.
59 freq = freq < 0.497f ? freq : 0.497f;
60
61 g_ = tanf(PI_F * freq);
62 gi_ = 1.f / (1.f + g_);
63 }
64
68 inline void SetFilterMode(FilterMode mode) { mode_ = mode; }
69
73 inline float Process(float in)
74 {
75 float lp;
76 lp = (g_ * in + state_) * gi_;
77 state_ = g_ * (in - lp) + lp;
78
79 switch(mode_)
80 {
81 case FILTER_MODE_LOW_PASS: return lp;
82 case FILTER_MODE_HIGH_PASS: return in - lp;
83 }
84
85 return 0.0f;
86 }
87
92 inline void ProcessBlock(float* in_out, size_t size)
93 {
94 while(size--)
95 {
97 ++in_out;
98 }
99 }
100
101 private:
102 float g_;
103 float gi_;
104 float state_;
105 FilterMode mode_;
106};
107
108} // namespace daisysp
109
110#endif // DSY_ONEPOLE_H
Definition delayline.h:29
One Pole Lowpass / Highpass Filter.
Definition onepole.h:27
FilterMode
Operational modes of the filter.
Definition onepole.h:38
float Process(float in)
Definition onepole.h:73
void Init()
Definition onepole.h:44
void ProcessBlock(float *in_out, size_t size)
Definition onepole.h:92
void Reset()
Definition onepole.h:51
void SetFilterMode(FilterMode mode)
Definition onepole.h:68
void SetFrequency(float freq)
Definition onepole.h:56
FIR Filter implementation, generic and ARM CMSIS DSP based.
Definition adenv.h:16