Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/Inject.cpp
Go to the documentation of this file.
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 "Inject.h"
00020 
00021 using std::ostringstream;
00022 using namespace Marsyas;
00023 
00024 Inject::Inject(mrs_string name) : MarSystem("Inject", name)
00025 {
00027   addControls();
00028   prev_injectSize_ = 0;
00029 }
00030 
00031 Inject::Inject(const Inject& a) : MarSystem(a)
00032 {
00033   ctrl_inject_ = getctrl("mrs_realvec/inject");
00034   ctrl_injectSize_ = getctrl("mrs_natural/injectSize");
00035   ctrl_injectNames_ = getctrl("mrs_string/injectNames");
00036   prev_injectSize_ = 0;
00037 }
00038 
00039 
00040 
00041 Inject::~Inject()
00042 {
00043 }
00044 
00045 MarSystem*
00046 Inject::clone() const
00047 {
00048   return new Inject(*this);
00049 }
00050 
00051 void
00052 Inject::addControls()
00053 {
00054   addctrl("mrs_realvec/inject", realvec(), ctrl_inject_);
00055   addctrl("mrs_natural/injectSize", 1, ctrl_injectSize_);
00056   setctrlState("mrs_natural/injectSize", true);
00057   addctrl("mrs_string/injectNames", "t1,t2,t3,t4,t5,t6,t7,t8", ctrl_injectNames_);
00058 }
00059 
00060 
00061 
00062 void
00063 Inject::myUpdate(MarControlPtr sender)
00064 {
00065   (void) sender;  //suppress warning of unused parameter(s)
00066   ctrl_onSamples_->setValue(ctrl_inSamples_, NOUPDATE);
00067   ctrl_onObservations_->setValue(ctrl_inObservations_->to<mrs_natural>() + ctrl_injectSize_->to<mrs_natural>(), NOUPDATE);
00068   ctrl_osrate_->setValue(ctrl_israte_->to<mrs_real>(), NOUPDATE);
00069   mrs_string onObsNames = ctrl_inObsNames_->to<mrs_string>();
00070   mrs_string injectNames = ctrl_injectNames_->to<mrs_string>();
00071   ctrl_onObsNames_->setValue(onObsNames + injectNames, NOUPDATE);
00072 
00073 
00074   mrs_natural injectSize = ctrl_injectSize_->to<mrs_natural>();
00075 
00076   if (prev_injectSize_ != injectSize)
00077   {
00078     MarControlAccessor acc(ctrl_inject_);
00079     mrs_realvec& inject = acc.to<mrs_realvec>();
00080 
00081 
00082     inject.stretch(injectSize);
00083   }
00084 
00085 
00086 
00087 
00088   prev_injectSize_ = injectSize;
00089 
00090 }
00091 
00092 void
00093 Inject::myProcess(realvec& in, realvec& out)
00094 {
00095   mrs_natural t,o;
00096   MarControlAccessor acc(ctrl_inject_);
00097   mrs_realvec& inject = acc.to<mrs_realvec>();
00098 
00100   for (o = 0; o < inObservations_; o++)
00101   {
00102     for (t = 0; t < inSamples_; t++)
00103     {
00104 
00105       out(o, t) = in(o, t);
00106     }
00107   }
00108 
00109 
00110 
00111   for (o = inObservations_; o < onObservations_; o++)
00112   {
00113     for (t = 0; t < inSamples_; t++)
00114     {
00115       out(o, t) = inject(o-inObservations_);
00116     }
00117   }
00118 
00119 }