00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "Shredder.h"
00022
00023 using namespace std;
00024 using namespace Marsyas;
00025
00026 Shredder::Shredder(mrs_string name):MarSystem("Shredder", name)
00027 {
00028 isComposite_ = true;
00029 addControls();
00030 nTimes_ = 5;
00031 }
00032
00033 Shredder::Shredder(const Shredder& a) : MarSystem(a)
00034 {
00035 ctrl_nTimes_ = getctrl("mrs_natural/nTimes");
00036 ctrl_accumulate_ = getctrl("mrs_bool/accumulate");
00037 nTimes_ = a.nTimes_;
00038 }
00039
00040 Shredder::~Shredder()
00041 {
00042 }
00043
00044 MarSystem*
00045 Shredder::clone() const
00046 {
00047 return new Shredder(*this);
00048 }
00049
00050 void
00051 Shredder::addControls()
00052 {
00053 addctrl("mrs_natural/nTimes", 5, ctrl_nTimes_);
00054 setctrlState("mrs_natural/nTimes", true);
00055
00056 addctrl("mrs_bool/accumulate", false, ctrl_accumulate_);
00057 ctrl_accumulate_->setState(true);
00058 }
00059
00060 void
00061 Shredder::myUpdate(MarControlPtr sender)
00062 {
00063 MRSDIAG("Shredder.cpp - Shredder:myUpdate");
00064
00065 nTimes_ = ctrl_nTimes_->to<mrs_natural>();
00066
00067
00068 if (marsystemsSize_ > 0)
00069 {
00070
00071 marsystems_[0]->setctrl("mrs_natural/inObservations", inObservations_);
00072 marsystems_[0]->setctrl("mrs_natural/inSamples", inSamples_ / nTimes_);
00073 marsystems_[0]->setctrl("mrs_real/israte", israte_);
00074 marsystems_[0]->setctrl("mrs_string/inObsNames", inObsNames_);
00075 marsystems_[0]->update();
00076
00077 childOnSamples_ = marsystems_[0]->getctrl("mrs_natural/onSamples")->to<mrs_natural>();
00078
00079
00080 if(ctrl_accumulate_->isTrue())
00081 {
00082 setctrl("mrs_natural/onSamples", childOnSamples_*nTimes_);
00083 }
00084 else
00085 {
00086 setctrl("mrs_natural/onSamples", childOnSamples_);
00087 }
00088 setctrl("mrs_natural/onObservations",
00089 marsystems_[0]->getctrl("mrs_natural/onObservations")->to<mrs_natural>());
00090 setctrl("mrs_real/osrate",
00091 marsystems_[0]->getctrl("mrs_real/osrate"));
00092 setctrl("mrs_string/onObsNames",
00093 marsystems_[0]->getctrl("mrs_string/onObsNames"));
00094
00095 childIn_.create(marsystems_[0]->getctrl("mrs_natural/inObservations")->to<mrs_natural>(),
00096 marsystems_[0]->getctrl("mrs_natural/inSamples")->to<mrs_natural>());
00097
00098 if(ctrl_accumulate_->isTrue())
00099 childOut_.create(marsystems_[0]->getctrl("mrs_natural/onObservations")->to<mrs_natural>(),
00100 childOnSamples_);
00101 else
00102 childOut_.create(0,0);
00103 }
00104 else
00105 MarSystem::myUpdate(sender);
00106 }
00107
00108 void
00109 Shredder::myProcess(realvec& in, realvec& out)
00110 {
00111 mrs_natural t,o,c;
00112 if(marsystemsSize_>0)
00113 {
00114 for (c = 0; c < nTimes_; ++c)
00115 {
00116
00117 for (o=0; o < inObservations_; o++)
00118 for (t = 0; t < inSamples_/nTimes_; t++)
00119 {
00120 childIn_(o,t) = in(o, t + c * (inSamples_/nTimes_)) ;
00121 }
00122
00123 if(ctrl_accumulate_->isTrue())
00124 {
00125 marsystems_[0]->process(childIn_, childOut_);
00126
00127 for (o=0; o < onObservations_; o++)
00128 for (t = 0; t < childOnSamples_; t++)
00129 {
00130 out(o, t + c * childOnSamples_) = childOut_(o,t);
00131 }
00132 }
00133 else
00134 {
00135 marsystems_[0]->process(childIn_, out);
00136 }
00137 }
00138 }
00139 else
00140 {
00141 MRSWARN("Shredder::process: composite has no children MarSystems - passing input to output without changes.");
00142 out = in;
00143 }
00144
00145
00146
00147
00148
00149
00150
00151 }