Marsyas  0.2
/home/gperciva/src/marsyas/src/marsyas/MemorySource.cpp
00001 /*
00002 ** Copyright (C) 1998-2007 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 "MemorySource.h"
00020 
00021 using std::ostringstream;
00022 using namespace Marsyas;
00023 
00024 MemorySource::MemorySource(mrs_string name):MarSystem("MemorySource",name)
00025 {
00026   //type_ = "MemorySource";
00027   //name_ = name;
00028   
00029     count_= 0;
00030 
00031     addControls();
00032 }
00033 
00034 
00035 MemorySource::~MemorySource()
00036 {
00037 }
00038 
00039 
00040 MarSystem* 
00041 MemorySource::clone() const 
00042 {
00043   return new MemorySource(*this);
00044 }
00045 
00046 void 
00047 MemorySource::addControls()
00048 {
00049   samplesToUse_ = (mrs_natural)MRS_DEFAULT_SLICE_NSAMPLES;
00050   addctrl("mrs_natural/samplesToUse", (mrs_natural)MRS_DEFAULT_SLICE_NSAMPLES);
00051   setctrlState("mrs_natural/samplesToUse", true);
00052   addctrl("mrs_bool/done", false);
00053   setctrlState("mrs_bool/done", true);
00054 }
00055 
00056 
00057 void
00058 MemorySource::myUpdate(MarControlPtr sender)
00059 {
00060     (void) sender;
00061   MRSDIAG("MemorySource.cpp - MemorySource:myUpdate");
00062   
00063   setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations")  );
00064   setctrl("mrs_real/osrate", getctrl("mrs_real/israte")->to<mrs_real>());
00065   samplesToUse_ = getctrl("mrs_natural/samplesToUse")->to<mrs_natural>();
00066   
00067   if( getctrl("mrs_bool/done")->isTrue()){
00068     count_ = 0;
00069     setctrl("mrs_bool/done", false);
00070   }
00071 }
00072 
00073 void 
00074 MemorySource::myProcess(realvec& in, realvec& out)
00075 {
00076     mrs_natural t,o;
00077   //checkFlow(in,out);
00078 
00079   if( count_ < 1 + (samplesToUse_ -1) / onSamples_ ){
00080     
00081     for (o=0; o < inObservations_; o++){
00082       for (t = 0 ; t < onSamples_ && count_*onSamples_+t < samplesToUse_ ; t++)
00083         {
00084           out(o,t) = in(o,count_*onSamples_+t);
00085         }
00086       
00087       for( ; t < onSamples_ ; t++ )
00088         {
00089           out(o,t) = 0.;
00090         }
00091     }
00092     count_++;
00093   }
00094   
00095   if( count_ >= 1 + (samplesToUse_ -1) / onSamples_ )
00096     setctrl("mrs_bool/done", true);  
00097 }