Demo program of digital signal processing: Variable LPF/HPF, Vocal canceller, Pitch shifter, Reverbrator. ディジタル信号処理のデモプログラム. 遮断周波数可変 LPF/HPF,ボーカルキャンセラ,ピッチシフタ,残響生成器.
Dependencies: Array_Matrix F446_AD_DA UIT_AQM1602 mbed
SignalProcessing/ReverbUnit.hpp@6:96b4f6ce2dc9, 2017-02-21 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Tue Feb 21 13:14:47 2017 +0000
- Revision:
- 6:96b4f6ce2dc9
- Parent:
- 5:503bd366fd73
7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:fa74b1130cc3 | 1 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:fa74b1130cc3 | 2 | // Reverb unit |
MikamiUitOpen | 5:503bd366fd73 | 3 | // 2017/01/31, Copyright (c) 2017 MIKAMI, Naoki |
MikamiUitOpen | 0:fa74b1130cc3 | 4 | //-------------------------------------------------------------- |
MikamiUitOpen | 0:fa74b1130cc3 | 5 | |
MikamiUitOpen | 0:fa74b1130cc3 | 6 | #ifndef REVERB_UNIT_HPP |
MikamiUitOpen | 0:fa74b1130cc3 | 7 | #define REVERB_UNIT_HPP |
MikamiUitOpen | 0:fa74b1130cc3 | 8 | |
MikamiUitOpen | 0:fa74b1130cc3 | 9 | #include "mbed.h" |
MikamiUitOpen | 0:fa74b1130cc3 | 10 | #include "Array.hpp" |
MikamiUitOpen | 0:fa74b1130cc3 | 11 | namespace Mikami |
MikamiUitOpen | 0:fa74b1130cc3 | 12 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 13 | // Base class for reverb unit |
MikamiUitOpen | 0:fa74b1130cc3 | 14 | class Reverb |
MikamiUitOpen | 0:fa74b1130cc3 | 15 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 16 | public: |
MikamiUitOpen | 0:fa74b1130cc3 | 17 | // Constructor |
MikamiUitOpen | 0:fa74b1130cc3 | 18 | Reverb(int delay) : DELAY_(delay), un_(delay) |
MikamiUitOpen | 0:fa74b1130cc3 | 19 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 20 | ptr_ = 0; |
MikamiUitOpen | 0:fa74b1130cc3 | 21 | Clear(); |
MikamiUitOpen | 0:fa74b1130cc3 | 22 | } |
MikamiUitOpen | 0:fa74b1130cc3 | 23 | |
MikamiUitOpen | 0:fa74b1130cc3 | 24 | ~Reverb() {} |
MikamiUitOpen | 0:fa74b1130cc3 | 25 | |
MikamiUitOpen | 0:fa74b1130cc3 | 26 | // Execute of filter (pure virtual function) |
MikamiUitOpen | 0:fa74b1130cc3 | 27 | virtual float Execute(float x) = 0; |
MikamiUitOpen | 0:fa74b1130cc3 | 28 | |
MikamiUitOpen | 0:fa74b1130cc3 | 29 | // Clear internal delay elements |
MikamiUitOpen | 0:fa74b1130cc3 | 30 | void Clear() |
MikamiUitOpen | 0:fa74b1130cc3 | 31 | { for (int n=0; n<DELAY_; n++) un_[n] = 0; } |
MikamiUitOpen | 0:fa74b1130cc3 | 32 | |
MikamiUitOpen | 0:fa74b1130cc3 | 33 | protected: |
MikamiUitOpen | 0:fa74b1130cc3 | 34 | float Get() { return un_[ptr_]; } |
MikamiUitOpen | 0:fa74b1130cc3 | 35 | |
MikamiUitOpen | 0:fa74b1130cc3 | 36 | void Set(float x) |
MikamiUitOpen | 0:fa74b1130cc3 | 37 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 38 | un_[ptr_] = x; |
MikamiUitOpen | 0:fa74b1130cc3 | 39 | if (++ptr_ >= DELAY_) ptr_ = 0; |
MikamiUitOpen | 0:fa74b1130cc3 | 40 | } |
MikamiUitOpen | 5:503bd366fd73 | 41 | |
MikamiUitOpen | 0:fa74b1130cc3 | 42 | private: |
MikamiUitOpen | 0:fa74b1130cc3 | 43 | const int DELAY_; |
MikamiUitOpen | 0:fa74b1130cc3 | 44 | Array<float> un_; // for delay |
MikamiUitOpen | 0:fa74b1130cc3 | 45 | int ptr_; |
MikamiUitOpen | 0:fa74b1130cc3 | 46 | |
MikamiUitOpen | 0:fa74b1130cc3 | 47 | // disallow copy constructor and assignment operator |
MikamiUitOpen | 0:fa74b1130cc3 | 48 | Reverb(const Reverb&); |
MikamiUitOpen | 0:fa74b1130cc3 | 49 | Reverb& operator=(const Reverb&); |
MikamiUitOpen | 0:fa74b1130cc3 | 50 | }; |
MikamiUitOpen | 0:fa74b1130cc3 | 51 | |
MikamiUitOpen | 0:fa74b1130cc3 | 52 | // Reverb unit using comb filter |
MikamiUitOpen | 0:fa74b1130cc3 | 53 | class CombFilter : public Reverb |
MikamiUitOpen | 0:fa74b1130cc3 | 54 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 55 | public: |
MikamiUitOpen | 0:fa74b1130cc3 | 56 | // Constructor |
MikamiUitOpen | 0:fa74b1130cc3 | 57 | CombFilter(float g, int delay) |
MikamiUitOpen | 0:fa74b1130cc3 | 58 | : Reverb(delay), G0_(g) {} |
MikamiUitOpen | 0:fa74b1130cc3 | 59 | |
MikamiUitOpen | 0:fa74b1130cc3 | 60 | // Execute comb filter |
MikamiUitOpen | 0:fa74b1130cc3 | 61 | virtual float Execute(float x) |
MikamiUitOpen | 0:fa74b1130cc3 | 62 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 63 | float yn = Reverb::Get(); |
MikamiUitOpen | 0:fa74b1130cc3 | 64 | Reverb::Set(x + G0_*yn); |
MikamiUitOpen | 0:fa74b1130cc3 | 65 | return yn; |
MikamiUitOpen | 0:fa74b1130cc3 | 66 | } |
MikamiUitOpen | 0:fa74b1130cc3 | 67 | |
MikamiUitOpen | 0:fa74b1130cc3 | 68 | private: |
MikamiUitOpen | 0:fa74b1130cc3 | 69 | const float G0_; |
MikamiUitOpen | 0:fa74b1130cc3 | 70 | }; |
MikamiUitOpen | 0:fa74b1130cc3 | 71 | |
MikamiUitOpen | 0:fa74b1130cc3 | 72 | // Reverb unit using allpass filter |
MikamiUitOpen | 0:fa74b1130cc3 | 73 | class AllPassFilter : public Reverb |
MikamiUitOpen | 0:fa74b1130cc3 | 74 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 75 | public: |
MikamiUitOpen | 0:fa74b1130cc3 | 76 | // Constructor |
MikamiUitOpen | 0:fa74b1130cc3 | 77 | AllPassFilter(float g, int delay) |
MikamiUitOpen | 0:fa74b1130cc3 | 78 | : Reverb(delay), G0_(g) {} |
MikamiUitOpen | 0:fa74b1130cc3 | 79 | |
MikamiUitOpen | 0:fa74b1130cc3 | 80 | // Execute allpass filter |
MikamiUitOpen | 0:fa74b1130cc3 | 81 | virtual float Execute(float x) |
MikamiUitOpen | 0:fa74b1130cc3 | 82 | { |
MikamiUitOpen | 0:fa74b1130cc3 | 83 | float un = x + G0_*Reverb::Get(); |
MikamiUitOpen | 0:fa74b1130cc3 | 84 | float yn = -G0_*un + Reverb::Get(); |
MikamiUitOpen | 0:fa74b1130cc3 | 85 | Reverb::Set(un); |
MikamiUitOpen | 0:fa74b1130cc3 | 86 | return yn; |
MikamiUitOpen | 0:fa74b1130cc3 | 87 | } |
MikamiUitOpen | 5:503bd366fd73 | 88 | |
MikamiUitOpen | 0:fa74b1130cc3 | 89 | private: |
MikamiUitOpen | 0:fa74b1130cc3 | 90 | const float G0_; |
MikamiUitOpen | 0:fa74b1130cc3 | 91 | }; |
MikamiUitOpen | 0:fa74b1130cc3 | 92 | } |
MikamiUitOpen | 0:fa74b1130cc3 | 93 | #endif // REVERB_UNIT_HPP |