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 #include "RealvecSource.h" 00020 #include "../common_source.h" 00021 00022 using namespace std; 00023 using namespace Marsyas; 00024 00025 RealvecSource::RealvecSource(mrs_string name):MarSystem("RealvecSource",name) 00026 { 00027 count_= 0; 00028 addControls(); 00029 } 00030 00031 RealvecSource::RealvecSource(const RealvecSource& a):MarSystem(a) 00032 { 00033 count_ = 0; 00034 ctrl_data_ = getctrl("mrs_realvec/data"); 00035 } 00036 00037 00038 RealvecSource::~RealvecSource() 00039 { 00040 } 00041 00042 00043 MarSystem* 00044 RealvecSource::clone() const 00045 { 00046 return new RealvecSource(*this); 00047 } 00048 00049 void 00050 RealvecSource::addControls() 00051 { 00052 samplesToUse_ = (mrs_natural)MRS_DEFAULT_SLICE_NSAMPLES; 00053 addctrl("mrs_bool/done", false); 00054 setctrlState("mrs_bool/done", true); 00055 addctrl("mrs_realvec/data", realvec(), ctrl_data_); 00056 setctrlState("mrs_realvec/data", true); 00057 setctrlState("mrs_real/israte", true); 00058 } 00059 00060 00061 void 00062 RealvecSource::myUpdate(MarControlPtr sender) 00063 { 00064 (void)sender; 00065 MRSDIAG("RealvecSource.cpp - RealvecSource:myUpdate"); 00066 00067 inSamples_ = getctrl("mrs_natural/inSamples")->to<mrs_natural>(); 00068 inObservations_ = getctrl("mrs_natural/inObservations")->to<mrs_natural>(); 00069 israte_ = getctrl("mrs_real/israte")->to<mrs_real>(); 00070 00071 const realvec& data = ctrl_data_->to<realvec> (); 00072 00073 setctrl("mrs_natural/onObservations", data.getRows()); 00074 setctrl("mrs_natural/onSamples", inSamples_); 00075 setctrl("mrs_real/osrate", israte_); 00076 samplesToUse_ = data.getCols(); 00077 00078 count_ = 0; 00079 00080 if( getctrl("mrs_bool/done")->isTrue()) { 00081 setctrl("mrs_bool/done", false); 00082 } 00083 } 00084 00085 void 00086 RealvecSource::myProcess(realvec& in, realvec& out) 00087 { 00088 mrs_natural o,t; 00089 (void) in; 00090 //checkFlow(in,out); 00091 const realvec& data = ctrl_data_->to<realvec> (); 00092 00093 if( count_ < samplesToUse_) 00094 { 00095 for (o=0; o < onObservations_; o++) 00096 { 00097 for (t=0; t < onSamples_; t++) 00098 { 00099 out(o,t) = data(o,count_ + t); 00100 } 00101 } 00102 count_ += onSamples_; 00103 } 00104 else 00105 setctrl("mrs_bool/done", true); 00106 00107 if (count_ >= samplesToUse_) 00108 { 00109 setctrl("mrs_bool/done", true); 00110 } 00111 00112 //out.dump(); 00113 }