00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "common.h"
00020 #include "DelaySamples.h"
00021
00022 using std::ostringstream;
00023 using namespace Marsyas;
00024
00025 DelaySamples::DelaySamples(mrs_string name) :
00026 MarSystem("DelaySamples", name)
00027 {
00029 addControls();
00030 }
00031
00032 DelaySamples::DelaySamples(const DelaySamples& a) :
00033 MarSystem(a)
00034 {
00037 ctrl_delay_ = getctrl("mrs_natural/delay");
00038 }
00039
00040 DelaySamples::~DelaySamples()
00041 {
00042 }
00043
00044 MarSystem*
00045 DelaySamples::clone() const
00046 {
00047 return new DelaySamples(*this);
00048 }
00049
00051 void DelaySamples::addControls()
00052 {
00053 addctrl("mrs_natural/delay", 0, ctrl_delay_);
00054 setctrlState("mrs_natural/delay", true);
00055 }
00056
00057 void DelaySamples::myUpdate(MarControlPtr sender)
00058 {
00060 MarSystem::myUpdate(sender);
00061
00062
00063 delay_ = ctrl_delay_->to<mrs_natural> ();
00064 if (delay_ < 0)
00065 {
00066 setctrl("mrs_natural/delay", 0);
00067 delay_ = 0;
00068 }
00069
00070
00071 mrs_string inObsNames = ctrl_inObsNames_->to<mrs_string>();
00072 ostringstream oss;
00073 oss << "DelaySamples" << delay_ << "_";
00074 mrs_string onObsNames = obsNamesAddPrefix(inObsNames, oss.str());
00075 ctrl_onObsNames_->setValue(onObsNames, NOUPDATE);
00076
00077
00078 this->memory_.stretch(inObservations_, delay_);
00079 this->memory_.setval(0.0);
00080 }
00081
00082 void DelaySamples::myProcess(realvec& in, realvec& out)
00083 {
00084 mrs_natural t, o;
00085
00086 mrs_natural memory_part = delay_ < inSamples_ ? delay_ : inSamples_;
00087 for (o = 0; o < inObservations_; o++)
00088 {
00089
00090 for (t = 0; t < memory_part; t++)
00091 {
00092 out(o, t) = memory_(o, t);
00093 }
00094
00095 for (t = delay_; t < inSamples_; t++)
00096 {
00097 out(o, t) = in(o, t - delay_);
00098 }
00099
00100 for (t = 0; t < delay_ - inSamples_; t++)
00101 {
00102 memory_(o, t) = memory_(o, t + inSamples_);
00103 }
00104
00105 for (t = 0; t < memory_part; t++)
00106 {
00107 memory_(o, delay_ - 1 - t) = in(o, inSamples_ - 1 - t);
00108 }
00109 }
00110 }