00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "OnePole.h"
00020
00021 using std::ostringstream;
00022 using namespace Marsyas;
00023
00024
00025 OnePole::OnePole(mrs_string name) : MarSystem("OnePole", name)
00026 {
00027 addControls();
00028 }
00029
00030
00031 OnePole::~OnePole()
00032 {
00033 }
00034
00035
00036 MarSystem*
00037 OnePole::clone() const
00038 {
00039 return new OnePole(*this);
00040 }
00041
00042 void
00043 OnePole::addControls()
00044 {
00045 addControl("mrs_real/alpha", 0.9);
00046 setControlState("mrs_real/alpha", true);
00047 }
00048
00049
00050 void
00051 OnePole::myUpdate(MarControlPtr sender)
00052 {
00053
00054 MarSystem::myUpdate(sender);
00055
00056
00057 alpha_ = getControl("mrs_real/alpha")->to<mrs_real>();
00058 gain_ = 1.0 - alpha_;
00059
00060
00061 mrs_natural rows = ctrl_inObservations_->to<mrs_natural>();
00062 previousOutputSamples_.stretch(rows, 1);
00063 previousOutputSamples_.setval(0.0);
00064 }
00065
00066 void
00067 OnePole::myProcess(realvec& in, realvec& out)
00068 {
00069 mrs_natural t,o;
00070 for (o = 0; o < inObservations_; o++)
00071 {
00072
00073
00074 t = 0;
00075 out(o, t) = gain_ * in(o, t) + alpha_ * previousOutputSamples_(o, 0);
00076
00077
00078 for (t = 1; t < inSamples_; t++)
00079 {
00080 out(o, t) = gain_ * in(o, t) + alpha_ * out(o, t - 1);
00081 }
00082
00083
00084 previousOutputSamples_(o, 0) = out(o, inSamples_ - 1);
00085 }
00086 }