The experiment using this program is introduced on "Interface" No.3, CQ publishing Co.,Ltd, 2015. 本プログラムを使った実験は,CQ出版社のインターフェース 2015年3月号で紹介しています.
Dependencies: DSProcessingIO mbed
Revision 0:47656a949b95, committed 2014-07-15
- Comitter:
- CQpub0Mikami
- Date:
- Tue Jul 15 09:26:17 2014 +0000
- Child:
- 1:4fa3cb574a57
- Commit message:
- 1
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DSProcessingIO.lib Tue Jul 15 09:26:17 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/CQpub0Mikami/code/DSProcessingIO/#c3f647a89947
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Echo.cpp Tue Jul 15 09:26:17 2014 +0000 @@ -0,0 +1,46 @@ +//-------------------------------------------------------------- +// Echo generation system +// Copyright (c) 2014 MIKAMI, Naoki, 2014/06/28 +//-------------------------------------------------------------- + +#include "mbed.h" +#include "AdcInternal.hpp" +#include "MCP4922Single.hpp" +#include "ReverbUnit.hpp" + +using namespace Mikami; + +const float FS_ = 10.0e3f; +Adc adc_(A0); +Dac dac_(Dac::DAC_A); + +Ticker timer_; // for timer interrupt + +const float G_C_ = 0.8f; +const float G_A_ = 0.6f; +const float G0_ = 1.0f - G_C_; +CombFilter<887> cmF1(G_C_); +CombFilter<1153> cmF2(G_C_); +CombFilter<1499> cmF3(G_C_); +AllPassFilter<97> apF1(G_A_); +AllPassFilter<131> apF2(G_A_); + +void TimerIsr() +{ + float xn = adc_.Read(); // input + + xn = G0_*xn; + float yn = cmF1.Execute(xn) + cmF2.Execute(xn) + + cmF3.Execute(xn); + yn = apF2.Execute(apF1.Execute(yn)); + yn = yn + xn; // add direct input signal + + dac_.Write(yn); // output +} + +int main() +{ + timer_.attach_us(&TimerIsr, 1.0e6f/FS_); + while (true) {} // infinite loop +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ReverbUnit.hpp Tue Jul 15 09:26:17 2014 +0000 @@ -0,0 +1,78 @@ +//-------------------------------------------------------------- +// Reverb unit +// Copyright (c) 2014 MIKAMI, Naoki, 2014/06/28 +//-------------------------------------------------------------- + +#ifndef REVERB_UNIT_HPP +#define REVERB_UNIT_HPP + +#include "mbed.h" + +namespace Mikami +{ + // Base class for reverb unit + template<int delay> class Reverb + { + private: + int ptr_; + float un_[delay]; // for delay + + Reverb(const Reverb&); + Reverb& operator=(const Reverb&); + 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; } + }; + + // Reverb unit using 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; + } + }; + + // Reverb unit using allpass filter + template<int delay> class AllPassFilter : public Reverb<delay> + { + private: + const float G0_; + public: + // Constructor + AllPassFilter(float g) : G0_(g) {} + + // Execute allpass 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jul 15 09:26:17 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae \ No newline at end of file