Reverb system using parallel structure of comb filters and cascade structure of allpass filters for ST Nucleo F401RE.
Dependencies: UITDSP_ADDA mbed
Diff: reverb_unit.hpp
- Revision:
- 0:72e321f29769
- Child:
- 1:51c85e0a6e1e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/reverb_unit.hpp Thu Oct 23 03:53:29 2014 +0000 @@ -0,0 +1,74 @@ +//-------------------------------------------------------------- +// Comb filter +// 2014/10/23, Copyright (c) 2014 MIKAMI, Naoki +//-------------------------------------------------------------- + +#ifndef REVERB_UNIT_HPP +#define REVERB_UNIT_HPP + +#include "mbed.h" + +// Base class for reverb unit +template<int delay> class Reverb +{ +private: + int ptr_; + float un_[delay]; // for delay +protected: + float Get() { return un_[ptr_]; } + void Set(float x) + { + un_[ptr_] = x; + if (++ptr_ >= delay) ptr_ = 0; + } +public: + // Constructor + Reverb() : ptr_(0) { Clear(); } + + // Execute of filter (pure virtual function) + virtual float Execute(float x) = 0; + + // Clear internal delay elements + void Clear() + { for (int n=0; n<delay; n++) un_[n] = 0; } +}; + +// Comb filter +template<int delay> class CombFilter : public Reverb<delay> +{ +private: + const float G0_; +public: + // Constructor + CombFilter(float g) : G0_(g) {} + + // Execute comb filter + virtual float Execute(float x) + { + float yn = Reverb<delay>::Get(); + Reverb<delay>::Set(x + G0_*yn); + return yn; + } +}; + +// Allpass filter +template<int delay> class AllpassFilter : public Reverb<delay> +{ +private: + const float G0_; +public: + // Constructor + AllpassFilter(float g) : G0_(g) {} + + // Execute comb filter + virtual float Execute(float x) + { + float un = x + G0_*Reverb<delay>::Get(); + float yn = -G0_*un + Reverb<delay>::Get(); + Reverb<delay>::Set(un); + return yn; + } +}; + +#endif // REVERB_UNIT_HPP +