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 "SilenceRemove.h" 00020 #include "../common_source.h" 00021 00022 using namespace std; 00023 using namespace Marsyas; 00024 00025 SilenceRemove::SilenceRemove(mrs_string name):MarSystem("SilenceRemove",name) 00026 { 00027 isComposite_ = true; 00028 addControls(); 00029 } 00030 00031 SilenceRemove::SilenceRemove(const SilenceRemove& a): MarSystem(a) 00032 { 00033 ctrl_threshold_ = getctrl("mrs_real/threshold"); 00034 } 00035 00036 SilenceRemove::~SilenceRemove() 00037 { 00038 00039 } 00040 00041 MarSystem* 00042 SilenceRemove::clone() const 00043 { 00044 return new SilenceRemove(*this); 00045 } 00046 00047 void 00048 SilenceRemove::addControls() 00049 { 00050 addctrl("mrs_real/threshold", 0.01, ctrl_threshold_); 00051 setctrlState("mrs_real/threshold", true); 00052 } 00053 00054 void 00055 SilenceRemove::myUpdate(MarControlPtr sender) 00056 { 00057 MRSDIAG("SilenceRemove.cpp - SilenceRemove:myUpdate"); 00058 00059 threshold_ = ctrl_threshold_->to<mrs_real>(); 00060 00061 if (marsystems_.size()) 00062 { 00063 //propagate in flow controls to first child 00064 marsystems_[0]->setctrl("mrs_natural/inObservations", inObservations_); 00065 marsystems_[0]->setctrl("mrs_natural/inSamples", inSamples_); 00066 marsystems_[0]->setctrl("mrs_real/israte", israte_); 00067 marsystems_[0]->setctrl("mrs_string/inObsNames", inObsNames_); 00068 marsystems_[0]->update(); 00069 00070 // forward flow propagation 00071 ctrl_onSamples_->setValue(ctrl_inSamples_, NOUPDATE); 00072 ctrl_onObservations_->setValue(ctrl_inObservations_, NOUPDATE); 00073 ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE); 00074 ctrl_onObsNames_->setValue(ctrl_inObsNames_, NOUPDATE); 00075 00076 //marsystems_[0]->update(); //lmartins: shouldn't this have already been called?! [?] 00077 00078 if (ctrl_hasData_.isInvalid()) 00079 ctrl_hasData_ = marsystems_[0]->getctrl("mrs_bool/hasData"); 00080 } 00081 else //if composite is empty... 00082 MarSystem::myUpdate(sender); 00083 } 00084 00085 void 00086 SilenceRemove::myProcess(realvec& in, realvec& out) 00087 { 00088 mrs_real rms = 0.0; 00089 mrs_natural count = 0; 00090 mrs_natural t,o; 00091 00092 if(marsystems_.size()) 00093 { 00094 do 00095 { 00096 marsystems_[0]->process(in, out); 00097 00098 for (o=0; o < onObservations_; o++) 00099 for (t = 0; t < onSamples_; t++) 00100 { 00101 rms += (out(o,t) * out(o,t)); 00102 count++; 00103 } 00104 rms /= count; 00105 rms = sqrt(rms); 00106 count = 0; 00107 } while (rms < threshold_ && (ctrl_hasData_->isTrue())); 00108 } 00109 else //composite has no children! 00110 { 00111 MRSWARN("SilenceRemove::process: composite has no children MarSystems - passing input to output without changes."); 00112 out = in; 00113 } 00114 }