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