Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2010 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 #include "Fanin.h" 00020 00021 00022 using std::ostringstream; 00023 using std::vector; 00024 00025 00026 using namespace Marsyas; 00027 00028 Fanin::Fanin(mrs_string name):MarSystem("Fanin", name) 00029 { 00030 isComposite_ = true; 00031 } 00032 00033 Fanin::Fanin(const Fanin & other): 00034 MarSystem(other) 00035 { 00036 // do not copy slices 00037 } 00038 00039 Fanin::~Fanin() 00040 { 00041 deleteSlices(); 00042 } 00043 00044 void 00045 Fanin::deleteSlices() 00046 { 00047 vector<realvec *>::const_iterator iter; 00048 for (iter= slices_.begin(); iter != slices_.end(); iter++) 00049 { 00050 delete *(iter); 00051 } 00052 slices_.clear(); 00053 } 00054 00055 MarSystem* 00056 Fanin::clone() const 00057 { 00058 return new Fanin(*this); 00059 } 00060 00061 void 00062 Fanin::myUpdate(MarControlPtr sender) 00063 { 00064 child_count_t child_count = marsystems_.size(); 00065 if (child_count) 00066 { 00067 //propagate in flow controls to first child 00068 marsystems_[0]->setctrl("mrs_natural/inSamples", inSamples_); 00069 marsystems_[0]->setctrl("mrs_real/israte", israte_); 00070 //marsystems_[0]->setctrl("mrs_natural/inObservations", inObservations_); 00071 //marsystems_[0]->setctrl("mrs_string/inObsNames", inObsNames_); 00072 marsystems_[0]->update(sender); 00073 00074 ostringstream oss; 00075 oss << name_ <<"_mix_0, "; 00076 00077 mrs_natural inObservations = marsystems_[0]->getctrl("mrs_natural/inObservations")->to<mrs_natural>(); 00078 00079 for (child_count_t i=1; i < child_count; ++i) 00080 { 00081 marsystems_[i]->setctrl("mrs_natural/inSamples", marsystems_[0]->getctrl("mrs_natural/inSamples")); 00082 marsystems_[i]->setctrl("mrs_real/israte", marsystems_[0]->getctrl("mrs_real/israte")); //[!] israte 00083 marsystems_[i]->update(sender); 00084 inObservations += marsystems_[i]->getctrl("mrs_natural/inObservations")->to<mrs_natural>(); 00085 oss << name_ << "_mix_" << i << ", "; 00086 } 00087 00088 // forward flow propagation 00089 setctrl(ctrl_onSamples_, marsystems_[0]->getctrl("mrs_natural/onSamples")); 00090 setctrl(ctrl_onObservations_, 1); 00091 setctrl(ctrl_osrate_, marsystems_[0]->getctrl("mrs_real/osrate")); 00092 setctrl(ctrl_onObsNames_, oss.str()); 00093 00094 // update slices for child MarSystems 00095 if (slices_.size() < child_count) 00096 slices_.resize(child_count, NULL); 00097 00098 for (child_count_t i=0; i< child_count; ++i) 00099 { 00100 if (slices_[i] != NULL) 00101 { 00102 if ((slices_[i])->getRows() != marsystems_[i]->getctrl("mrs_natural/onObservations")->to<mrs_natural>() || 00103 (slices_[i])->getCols() != marsystems_[i]->getctrl("mrs_natural/onSamples")->to<mrs_natural>()) 00104 { 00105 delete slices_[i]; 00106 slices_[i] = new realvec(marsystems_[i]->getctrl("mrs_natural/onObservations")->to<mrs_natural>(), 00107 marsystems_[i]->getctrl("mrs_natural/onSamples")->to<mrs_natural>()); 00108 } 00109 } 00110 else 00111 { 00112 slices_[i] = new realvec(marsystems_[i]->getctrl("mrs_natural/onObservations")->to<mrs_natural>(), 00113 marsystems_[i]->getctrl("mrs_natural/onSamples")->to<mrs_natural>()); 00114 } 00115 (slices_[i])->setval(0.0); 00116 } 00117 } 00118 else //if composite is empty... 00119 MarSystem::myUpdate(sender); 00120 00121 } 00122 00123 void 00124 Fanin::myProcess(realvec& in, realvec& out) 00125 { 00126 mrs_natural o,t; 00127 child_count_t child_count = marsystems_.size(); 00128 if(child_count) 00129 { 00130 out.setval(0.0); 00131 00132 // Add assertions about sizes 00133 realvec ob(1,inSamples_); 00134 00135 for (o=0; o < inObservations_; o++) 00136 { 00137 // process each observation 00138 for (t=0; t < inSamples_; t++) 00139 ob(0,t) = in(o,t); 00140 marsystems_[o]->process(ob, *(slices_[o])); 00141 for (t=0; t < onSamples_; t++) 00142 out(0,t) += (*(slices_[o]))(0,t); 00143 } 00144 } 00145 else //composite has no children! 00146 { 00147 MRSWARN("Fanin::process: composite has no children MarSystems - passing input to output without changes."); 00148 out = in; 00149 } 00150 }