Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/AMDF.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 "AMDF.h"
00020 #include "../common_source.h"
00021 
00022 
00023 using std::ostringstream;
00024 
00025 using namespace Marsyas;
00026 
00027 AMDF::AMDF(mrs_string name):MarSystem("AMDF", name)
00028 {
00029   //type_ = "AMDF";
00030   //name_ = name;
00031 }
00032 
00033 
00034 AMDF::~AMDF()
00035 {
00036 }
00037 
00038 
00039 MarSystem*
00040 AMDF::clone() const
00041 {
00042   return new AMDF(*this);
00043 }
00044 
00045 void
00046 AMDF::myUpdate(MarControlPtr sender)
00047 {
00048   (void) sender;  //suppress warning of unused parameter(s)
00049   MRSDIAG("AMDF.cpp - AMDF:myUpdate");
00050 
00051   setctrl("mrs_natural/onSamples", getctrl("mrs_natural/inSamples"));
00052   setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations"));
00053   setctrl("mrs_real/osrate", getctrl("mrs_real/israte"));
00054 
00055   setctrl("mrs_string/onObsNames", getctrl("mrs_string/inObsNames"));
00056 }
00057 
00058 void
00059 AMDF::myProcess(realvec& in, realvec& out)
00060 {
00061   mrs_natural o,t;
00062   //checkFlow(in,out);
00063 
00064   // FIXME This value is defined but (possibly) not used
00065   // mrs_real gain = getctrl("mrs_real/gain")->to<mrs_real>();
00066   mrs_natural i,k;
00067   mrs_real temp;
00068 
00069   for (o=0; o < inObservations_; o++)
00070     for (t = 0; t < inSamples_; t++)
00071     {
00072       out(o,t) = 0.0;
00073       for (i=t, k=0; i < inSamples_; ++i, k++)
00074       {
00075         temp = in(o,i) - in(o,k);
00076         if (temp < 0)
00077           out(o,t) -= temp;
00078         else
00079           out(o,t) += temp;
00080       }
00081     }
00082 
00083 }
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092