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