Marsyas  0.2
/home/gperciva/src/marsyas/src/marsyas/SliceDelta.cpp
00001 /*
00002 ** Copyright (C) 2009 Stefaan Lippens
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 "SliceDelta.h"
00020 
00021 using namespace std;
00022 using namespace Marsyas;
00023 
00024 MarSystem*
00025 SliceDelta::clone() const
00026 {
00027     return new SliceDelta(*this);
00028 }
00029 
00030 void
00031 SliceDelta::myUpdate(MarControlPtr sender)
00032 {
00033     // Use the default MarSystem setup of equal input/output stream formats.
00034     MarSystem::myUpdate(sender);
00035 
00036     // Allocate the previousInput_ buffer based on inObservations and inSamples.
00037     mrs_natural rows = getctrl("mrs_natural/inObservations")->to<mrs_natural>();
00038     mrs_natural cols = getctrl("mrs_natural/inSamples")->to<mrs_natural>();
00039     this->previousInputSlice_.stretch(rows, cols);
00040     this->previousInputSlice_.setval(0.0);
00041 }
00042 
00043 void
00044 SliceDelta::myProcess(realvec& in, realvec& out)
00045 {
00046     mrs_natural t,o;
00047     // Iterate over observations and samples.
00048     for (o=0; o < inObservations_; o++)
00049     {
00050         for (t = 0; t < inSamples_; t++)
00051         {
00052             // Output the difference with the previous slice.
00053             out(o, t) = in(o, t) - this->previousInputSlice_(o, t);
00054             // Store as previous input sample for later.
00055             this->previousInputSlice_(o, t) = in(o, t);
00056         }
00057     }
00058 }