00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "Limiter.h"
00020
00021 using std::ostringstream;
00022 using namespace Marsyas;
00023
00024 Limiter::Limiter(mrs_string name):MarSystem("Limiter",name)
00025 {
00026
00027
00028
00029 xdprev_ = 0.0;
00030 alpha_ = 0.0;
00031
00032 addControls();
00033 }
00034
00035
00036 Limiter::~Limiter()
00037 {
00038 }
00039
00040
00041 MarSystem*
00042 Limiter::clone() const
00043 {
00044 return new Limiter(*this);
00045 }
00046
00047 void
00048 Limiter::addControls()
00049 {
00050 addctrl("mrs_real/thresh", 1.0);
00051 addctrl("mrs_real/at", 0.0001);
00052 addctrl("mrs_real/rt", 0.130);
00053 addctrl("mrs_real/slope", 1.0);
00054 }
00055
00056
00057 void
00058 Limiter::myUpdate(MarControlPtr sender)
00059 {
00060 MRSDIAG("Limiter.cpp - Limiter:myUpdate");
00061
00062
00063
00064
00065
00066 MarSystem::myUpdate(sender);
00067
00068
00069 inSamples_ = getctrl("mrs_natural/inSamples")->to<mrs_natural>();
00070
00071 xd_.create(inSamples_);
00072 gains_.create(inSamples_);
00073 }
00074
00075
00076 void
00077 Limiter::myProcess(realvec& in, realvec& out)
00078 {
00079
00080 mrs_natural o,t;
00081 mrs_real thresh = getctrl("mrs_real/thresh")->to<mrs_real>();
00082 mrs_real at = getctrl("mrs_real/at")->to<mrs_real>();
00083 mrs_real rt = getctrl("mrs_real/rt")->to<mrs_real>();
00084 mrs_real slope = getctrl("mrs_real/slope")->to<mrs_real>();
00085
00086
00087 at = 1 - exp(-2.2/(22050*at));
00088 rt = 1 - exp(-2.2/(22050*rt));
00089
00090 for (o = 0; o < inObservations_; o++)
00091 for (t = 0; t < inSamples_; t++)
00092 {
00093
00094
00095 alpha_ = fabs(in(o,t)) - xdprev_;
00096
00097 if (alpha_<0)
00098 {
00099 alpha_ = 0;
00100 }
00101
00102 xd_(o,t)=xdprev_*(1-rt)+at*alpha_;
00103 xdprev_ = xd_(o,t);
00104
00105
00106 if (xd_(o,t) > thresh)
00107 {
00108 gains_(o,t) = pow((mrs_real)10.0,-slope*(log10(xd_(o,t))-log10(thresh)));
00109
00110 }
00111 else
00112 {
00113 gains_(o,t) = 1;
00114 }
00115
00116 out(o,t) = gains_(o,t) * in(o,t);
00117 }
00118 }
00119
00120
00121
00122
00123
00124
00125
00126