Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2006 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 00020 00021 #include "Shredder.h" 00022 #include "../common_source.h" 00023 00024 using namespace std; 00025 using namespace Marsyas; 00026 00027 Shredder::Shredder(mrs_string name):MarSystem("Shredder", name) 00028 { 00029 isComposite_ = true; 00030 addControls(); 00031 nTimes_ = 5; 00032 } 00033 00034 Shredder::Shredder(const Shredder& a) : MarSystem(a) 00035 { 00036 ctrl_nTimes_ = getctrl("mrs_natural/nTimes"); 00037 ctrl_accumulate_ = getctrl("mrs_bool/accumulate"); 00038 nTimes_ = a.nTimes_; 00039 } 00040 00041 Shredder::~Shredder() 00042 { 00043 } 00044 00045 MarSystem* 00046 Shredder::clone() const 00047 { 00048 return new Shredder(*this); 00049 } 00050 00051 void 00052 Shredder::addControls() 00053 { 00054 addctrl("mrs_natural/nTimes", 5, ctrl_nTimes_); 00055 setctrlState("mrs_natural/nTimes", true); 00056 00057 addctrl("mrs_bool/accumulate", false, ctrl_accumulate_); 00058 ctrl_accumulate_->setState(true); 00059 } 00060 00061 void 00062 Shredder::myUpdate(MarControlPtr sender) 00063 { 00064 MRSDIAG("Shredder.cpp - Shredder:myUpdate"); 00065 00066 nTimes_ = ctrl_nTimes_->to<mrs_natural>(); 00067 00068 // update dataflow component MarSystems in order 00069 if (marsystems_.size()) 00070 { 00071 //propagate in flow controls to first child 00072 marsystems_[0]->setctrl("mrs_natural/inObservations", inObservations_); 00073 marsystems_[0]->setctrl("mrs_natural/inSamples", inSamples_ / nTimes_); 00074 marsystems_[0]->setctrl("mrs_real/israte", israte_); 00075 marsystems_[0]->setctrl("mrs_string/inObsNames", inObsNames_); 00076 marsystems_[0]->update(); 00077 00078 childOnSamples_ = marsystems_[0]->getctrl("mrs_natural/onSamples")->to<mrs_natural>(); 00079 00080 // forward flow propagation 00081 if(ctrl_accumulate_->isTrue()) 00082 { 00083 setctrl("mrs_natural/onSamples", childOnSamples_*nTimes_); 00084 } 00085 else 00086 { 00087 setctrl("mrs_natural/onSamples", childOnSamples_); 00088 } 00089 setctrl("mrs_natural/onObservations", 00090 marsystems_[0]->getctrl("mrs_natural/onObservations")->to<mrs_natural>()); 00091 setctrl("mrs_real/osrate", 00092 marsystems_[0]->getctrl("mrs_real/osrate")); 00093 setctrl("mrs_string/onObsNames", 00094 marsystems_[0]->getctrl("mrs_string/onObsNames")); 00095 00096 childIn_.create(marsystems_[0]->getctrl("mrs_natural/inObservations")->to<mrs_natural>(), 00097 marsystems_[0]->getctrl("mrs_natural/inSamples")->to<mrs_natural>()); 00098 00099 if(ctrl_accumulate_->isTrue()) 00100 childOut_.create(marsystems_[0]->getctrl("mrs_natural/onObservations")->to<mrs_natural>(), 00101 childOnSamples_); 00102 else 00103 childOut_.create(0,0); //just to save memory... 00104 } 00105 else //if composite is empty... 00106 MarSystem::myUpdate(sender); 00107 } 00108 00109 void 00110 Shredder::myProcess(realvec& in, realvec& out) 00111 { 00112 mrs_natural t,o,c; 00113 if(marsystems_.size()) 00114 { 00115 for (c = 0; c < nTimes_; ++c) 00116 { 00117 //shred input 00118 for (o=0; o < inObservations_; o++) 00119 for (t = 0; t < inSamples_/nTimes_; t++) 00120 { 00121 childIn_(o,t) = in(o, t + c * (inSamples_/nTimes_)) ; 00122 } 00123 00124 if(ctrl_accumulate_->isTrue()) //accumulate child output 00125 { 00126 marsystems_[0]->process(childIn_, childOut_); 00127 00128 for (o=0; o < onObservations_; o++) 00129 for (t = 0; t < childOnSamples_; t++) 00130 { 00131 out(o, t + c * childOnSamples_) = childOut_(o,t); 00132 } 00133 } 00134 else //no child output accumulation 00135 { 00136 marsystems_[0]->process(childIn_, out); 00137 } 00138 } 00139 } 00140 else //composite has no children! 00141 { 00142 MRSWARN("Shredder::process: composite has no children MarSystems - passing input to output without changes."); 00143 out = in; 00144 } 00145 00146 /* 00147 MATLAB_PUT(in, "Schredder_in"); 00148 MATLAB_PUT(out, "Schredder_out"); 00149 MATLAB_EVAL("figure(1);imagesc(Schredder_in(1:2:end, :))"); 00150 MATLAB_EVAL("figure(2);plot(Schredder_out)"); 00151 */ 00152 }