![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Reverb system using single comb filter class for ST Nucleo F401RE.
comb_filter.hpp@0:47e72130375e, 2014-10-31 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Fri Oct 31 07:37:36 2014 +0000
- Revision:
- 0:47e72130375e
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:47e72130375e | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:47e72130375e | 2 | // Comb filter |
MikamiUitOpen | 0:47e72130375e | 3 | // 2014/10/23, Copyright (c) 2014 MIKAMI, Naoki |
MikamiUitOpen | 0:47e72130375e | 4 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:47e72130375e | 5 | |
MikamiUitOpen | 0:47e72130375e | 6 | #ifndef COMB_FILTER_HPP |
MikamiUitOpen | 0:47e72130375e | 7 | #define COMB_FILTER_HPP |
MikamiUitOpen | 0:47e72130375e | 8 | |
MikamiUitOpen | 0:47e72130375e | 9 | #include "mbed.h" |
MikamiUitOpen | 0:47e72130375e | 10 | |
MikamiUitOpen | 0:47e72130375e | 11 | template<int delay> class CombFilter |
MikamiUitOpen | 0:47e72130375e | 12 | { |
MikamiUitOpen | 0:47e72130375e | 13 | private: |
MikamiUitOpen | 0:47e72130375e | 14 | const float GC_; |
MikamiUitOpen | 0:47e72130375e | 15 | int ptr_; |
MikamiUitOpen | 0:47e72130375e | 16 | float un_[delay]; // for delay |
MikamiUitOpen | 0:47e72130375e | 17 | float Get() { return un_[ptr_]; } |
MikamiUitOpen | 0:47e72130375e | 18 | void Set(float x) |
MikamiUitOpen | 0:47e72130375e | 19 | { |
MikamiUitOpen | 0:47e72130375e | 20 | un_[ptr_] = x; |
MikamiUitOpen | 0:47e72130375e | 21 | if (++ptr_ >= delay) ptr_ = 0; |
MikamiUitOpen | 0:47e72130375e | 22 | } |
MikamiUitOpen | 0:47e72130375e | 23 | public: |
MikamiUitOpen | 0:47e72130375e | 24 | // Constructor |
MikamiUitOpen | 0:47e72130375e | 25 | CombFilter(float g) : GC_(g), ptr_(0) {} |
MikamiUitOpen | 0:47e72130375e | 26 | |
MikamiUitOpen | 0:47e72130375e | 27 | // Execute comb filter |
MikamiUitOpen | 0:47e72130375e | 28 | float Execute(float x) |
MikamiUitOpen | 0:47e72130375e | 29 | { |
MikamiUitOpen | 0:47e72130375e | 30 | float yn = Get(); |
MikamiUitOpen | 0:47e72130375e | 31 | Set(x + GC_*yn); |
MikamiUitOpen | 0:47e72130375e | 32 | return yn; |
MikamiUitOpen | 0:47e72130375e | 33 | } |
MikamiUitOpen | 0:47e72130375e | 34 | |
MikamiUitOpen | 0:47e72130375e | 35 | // Clear internal delay elements |
MikamiUitOpen | 0:47e72130375e | 36 | void Clear() |
MikamiUitOpen | 0:47e72130375e | 37 | { for (int n=0; n<delay; n++) un_[n] = 0; } |
MikamiUitOpen | 0:47e72130375e | 38 | }; |
MikamiUitOpen | 0:47e72130375e | 39 | #endif // COMB_FILTER_HPP |
MikamiUitOpen | 0:47e72130375e | 40 |