Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/Median.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 "Median.h"
00020 #include "../common_source.h"
00021 
00022 
00023 
00024 
00025 
00026 using std::ostringstream;
00027 using namespace Marsyas;
00028 
00029 Median::Median(mrs_string name):MarSystem("Median", name)
00030 {
00031   addControls();
00032 }
00033 
00034 Median::Median(const Median& a) : MarSystem(a)
00035 {
00036 }
00037 
00038 
00039 Median::~Median()
00040 {
00041 }
00042 
00043 MarSystem*
00044 Median::clone() const
00045 {
00046   return new Median(*this);
00047 }
00048 
00049 void
00050 Median::addControls()
00051 {
00052 }
00053 
00054 void
00055 Median::myUpdate(MarControlPtr sender)
00056 {
00057   (void) sender;  //suppress warning of unused parameter(s)
00058   MRSDIAG("Median.cpp - Median:myUpdate");
00059 
00060   ctrl_onSamples_->setValue((mrs_natural)1, NOUPDATE);
00061   ctrl_onObservations_->setValue(ctrl_inObservations_, NOUPDATE);
00062   ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE);
00063 
00064   obsrow_.create(ctrl_inSamples_->to<mrs_natural>());
00065 
00066   //defaultUpdate(); [!]
00067   inObservations_ = ctrl_inObservations_->to<mrs_natural>();
00068 
00069   ostringstream oss;
00070   mrs_string inObsNames = ctrl_inObsNames_->to<mrs_string>();
00071   for (int i = 0; i < inObservations_; ++i)
00072   {
00073     mrs_string inObsName;
00074     mrs_string temp;
00075     inObsName = inObsNames.substr(0, inObsNames.find(","));
00076     temp = inObsNames.substr(inObsNames.find(",")+1, inObsNames.length());
00077     inObsNames = temp;
00078     oss << "Median" << "_" << inObsName << ",";
00079   }
00080   ctrl_onObsNames_->setValue(oss.str(),NOUPDATE);
00081 }
00082 
00083 void
00084 Median::myProcess(realvec& in, realvec& out)
00085 {
00086   mrs_natural t,o;
00087   out.setval(0.0);
00088   for (o=0; o < inObservations_; o++) {
00089     for (t = 0; t < inSamples_; t++) {
00090       obsrow_(t) = in(o,t);
00091     }
00092     out(o,0) = obsrow_.median();
00093   }
00094 
00095 }