Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/Mean.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 "Mean.h"
00020 #include "../common_source.h"
00021 
00022 using std::ostringstream;
00023 using namespace Marsyas;
00024 
00025 Mean::Mean(mrs_string name): MarSystem("Mean", name)
00026 {
00027 }
00028 
00029 
00030 Mean::~Mean()
00031 {
00032 }
00033 
00034 
00035 MarSystem*
00036 Mean::clone() const
00037 {
00038   return new Mean(*this);
00039 }
00040 
00041 void
00042 Mean::myUpdate(MarControlPtr sender)
00043 {
00044   (void) sender;  //suppress warning of unused parameter(s)
00045   MRSDIAG("Mean.cpp - Mean:myUpdate");
00046 
00047   ctrl_onSamples_->setValue((mrs_natural)1, NOUPDATE);
00048   ctrl_onObservations_->setValue(ctrl_inObservations_, NOUPDATE);
00049   ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE);
00050 
00051   // Allocate memory for the row buffer.
00052   obsrow_.create(ctrl_inSamples_->to<mrs_natural>());
00053 
00054   //defaultUpdate(); [!]
00055   // \todo what is this doing here?
00056   inObservations_ = ctrl_inObservations_->to<mrs_natural>();
00057 
00058   // Add prefix to the observation names.
00059   mrs_string inObsNames = ctrl_inObsNames_->to<mrs_string>();
00060   ctrl_onObsNames_->setValue(obsNamesAddPrefix(inObsNames, "Mean_"), NOUPDATE);
00061 }
00062 
00063 void
00064 Mean::myProcess(realvec& in, realvec& out)
00065 {
00066   mrs_natural t,o;
00067   out.setval(0.0);
00068   for (o=0; o < inObservations_; o++)
00069   {
00070     for (t = 0; t < inSamples_; t++)
00071     {
00072       // Calculate mean
00073       obsrow_(t) = in(o,t);
00074     }
00075     out(o,0) = obsrow_.mean();
00076   }
00077   // INEFFICIENT A LOT OF MEMORY COPYING AT EVERY TICK
00078   // out = in.meanObs();
00079 }