00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "common.h"
00020 #include "NormalizeAbs.h"
00021
00022 using std::ostringstream;
00023 using namespace Marsyas;
00024
00025 NormalizeAbs::NormalizeAbs(mrs_string name) : MarSystem("NormalizeAbs", name)
00026 {
00028 addControls();
00029 }
00030
00031 NormalizeAbs::NormalizeAbs(const NormalizeAbs& a) : MarSystem(a)
00032 {
00035 ctrl_target_ = getctrl("mrs_real/target");
00036 }
00037
00038
00039 NormalizeAbs::~NormalizeAbs()
00040 {
00041 }
00042
00043 MarSystem*
00044 NormalizeAbs::clone() const
00045 {
00046 return new NormalizeAbs(*this);
00047 }
00048
00049 void
00050 NormalizeAbs::addControls()
00051 {
00053
00054 addctrl("mrs_real/target", 1.0, ctrl_target_);
00055
00056 }
00057
00058 void
00059 NormalizeAbs::myUpdate(MarControlPtr sender)
00060 {
00061 MRSDIAG("NormalizeAbs.cpp - NormalizeAbs:myUpdate");
00062
00064 MarSystem::myUpdate(sender);
00065 }
00066
00067 void
00068 NormalizeAbs::myProcess(realvec& in, realvec& out)
00069 {
00070 mrs_natural t,o;
00071 const mrs_real& target = ctrl_target_->to<mrs_real>();
00072
00074 for (o = 0; o < inObservations_; o++)
00075 {
00076
00077 mrs_real max_val = 0.0;
00078 for (t = 0; t < inSamples_; t++)
00079 if (max_val < fabs(in(o,t)))
00080 max_val = fabs(in(o,t));
00081 mrs_real gain = 0.0;
00082 if (max_val > 0)
00083 gain = target / max_val;
00084 for (t = 0; t < inSamples_; t++)
00085 out(o, t) = gain * in(o, t);
00086 }
00087 }