Marsyas
0.6.0-alpha
|
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 "../common_source.h" 00020 #include "RemoveObservations.h" 00021 00022 using std::ostringstream; 00023 using namespace Marsyas; 00024 00025 RemoveObservations::RemoveObservations(mrs_string name) : MarSystem("RemoveObservations", name) 00026 { 00028 addControls(); 00029 lowestObs_ = 0; 00030 numObs_ = inObservations_; 00031 } 00032 00033 RemoveObservations::RemoveObservations(const RemoveObservations& a) : MarSystem(a) 00034 { 00035 lowestObs_ = 0; 00036 numObs_ = inObservations_; 00037 } 00038 00039 00040 RemoveObservations::~RemoveObservations() 00041 { 00042 } 00043 00044 MarSystem* 00045 RemoveObservations::clone() const 00046 { 00047 return new RemoveObservations(*this); 00048 } 00049 00050 void 00051 RemoveObservations::addControls() 00052 { 00054 00055 addctrl("mrs_real/lowCutoff", 0.0); 00056 addctrl("mrs_real/highCutoff", 1.0); 00057 00058 } 00059 00060 void 00061 RemoveObservations::myUpdate(MarControlPtr sender) 00062 { 00063 MRSDIAG("RemoveObservations.cpp - RemoveObservations:myUpdate"); 00064 00065 MarSystem::myUpdate(sender); 00066 00067 // round down is the default with C math 00068 lowestObs_ = (mrs_natural) (inObservations_ 00069 * getctrl("mrs_real/lowCutoff")->to<mrs_real>()); 00070 // round up with ceil() 00071 numObs_ = (mrs_natural) (ceil( inObservations_ 00072 * getctrl("mrs_real/highCutoff")->to<mrs_real>() 00073 ) - lowestObs_); 00074 00075 ctrl_onObservations_->setValue(numObs_, NOUPDATE); 00076 00077 // remove unused observation names, so they don't 00078 // overwrite other observations from other parts 00079 // of the network 00080 mrs_string names = ctrl_inObsNames_->to<mrs_string>(); 00081 std::string::size_type lowNamePos = 0; 00082 std::string::size_type highNamePos = 0; 00083 for (int i=0; i < lowestObs_; i++) { 00084 lowNamePos = names.find(",", lowNamePos) + 1; 00085 } 00086 for (int i=0; i < numObs_; i++) { 00087 highNamePos = names.find(",", highNamePos) + 1; 00088 } 00089 if (highNamePos > 0) { 00090 names = names.substr(lowNamePos, highNamePos); 00091 ctrl_onObsNames_->setValue(names, NOUPDATE); 00092 } 00093 } 00094 00095 void 00096 RemoveObservations::myProcess(realvec& in, realvec& out) 00097 { 00098 mrs_natural t,o; 00099 00101 for (o = 0; o < numObs_; o++) 00102 { 00103 for (t = 0; t < inSamples_; t++) 00104 { 00105 out(o, t) = in(o+lowestObs_, t); 00106 } 00107 } 00108 }