00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "Rms.h"
00020
00021 using namespace std;
00022 using namespace Marsyas;
00023
00024 Rms::Rms(mrs_string name):MarSystem("Rms",name)
00025 {
00026
00027
00028 }
00029
00030 Rms::~Rms()
00031 {
00032 }
00033
00034 MarSystem*
00035 Rms::clone() const
00036 {
00037 return new Rms(*this);
00038 }
00039
00040 void
00041 Rms::myUpdate(MarControlPtr sender)
00042 {
00043 (void) sender;
00044 setctrl("mrs_natural/onSamples", (mrs_natural)1);
00045 setctrl("mrs_natural/onObservations", (mrs_natural)1);
00046 setctrl("mrs_real/osrate", getctrl("mrs_real/israte")->to<mrs_real>() / getctrl("mrs_natural/inSamples")->to<mrs_natural>());
00047
00048
00049 mrs_string inObsNames = ctrl_inObsNames_->to<mrs_string>();
00050 ctrl_onObsNames_->setValue(obsNamesAddPrefix(inObsNames, "Rms_"), NOUPDATE);
00051 }
00052
00053 void
00054 Rms::myProcess(realvec& in, realvec& out)
00055 {
00056 mrs_natural t;
00057 mrs_natural o;
00058 mrs_real val;
00059 mrs_real rmsEnergy;
00060
00061 for (o = 0; o < inObservations_; o++) {
00062 rmsEnergy = 0.0;
00063 for (t = 0; t < inSamples_; t++) {
00064 val = in(o, t);
00065 rmsEnergy += (val * val);
00066 }
00067 if (rmsEnergy != 0.0)
00068 {
00069 rmsEnergy /= inSamples_;
00070 rmsEnergy = sqrt(rmsEnergy);
00071 }
00072 out(o, 0) = (mrs_real) rmsEnergy;
00073 }
00074 }