Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/Shifter.cpp
Go to the documentation of this file.
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 "Shifter.h"
00020 #include "../common_source.h"
00021 
00022 using namespace std;
00023 using namespace Marsyas;
00024 
00025 Shifter::Shifter(mrs_string name):MarSystem("Shifter", name)
00026 {
00027   addControls();
00028 }
00029 
00030 
00031 Shifter::~Shifter()
00032 {
00033 }
00034 
00035 MarSystem*
00036 Shifter::clone() const
00037 {
00038   return new Shifter(*this);
00039 }
00040 
00041 void
00042 Shifter::addControls()
00043 {
00044   addctrl("mrs_natural/shift", 0);
00045   setctrlState("mrs_natural/shift", true);
00046 }
00047 
00048 void
00049 Shifter::myUpdate(MarControlPtr sender)
00050 {
00051   (void) sender;  //suppress warning of unused parameter(s)
00052   MRSDIAG("Shifter.cpp - Shifter:myUpdate");
00053 
00054   shift_ = getctrl("mrs_natural/shift")->to<mrs_natural>();
00055 
00056   mrs_natural onsamples = getctrl("mrs_natural/inSamples")->to<mrs_natural>()- shift_;
00057   //for too big shifts (> inSamples), do a zero shift
00058   if(onsamples < 0)
00059     onsamples = inSamples_;
00060 
00061   setctrl("mrs_natural/onSamples", onsamples);
00062   setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations")->to<mrs_natural>()*2);
00063   setctrl("mrs_real/osrate", getctrl("mrs_real/israte"));
00064   setctrl("mrs_string/onObsNames", getctrl("mrs_string/inObsNames"));
00065 }
00066 
00067 void
00068 Shifter::myProcess(realvec& in, realvec& out)
00069 {
00070   mrs_natural t,o;
00071   int delta = 0;
00072   for (o=0; o < onObservations_; o++)
00073   {
00074     for (t = 0; t < onSamples_; t++)
00075     {
00076       out(o,t) =  in(0,t+delta);
00077     }
00078     delta +=shift_;
00079   }
00080 
00081   //MATLAB_PUT(out, "in");
00082   //MATLAB_EVAL("figure(1);plot(mag)");
00083   //MATLAB_EAVL("figure(2);plot(peaks(1:2:end))");
00084 }