00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "HarmonicEnhancer.h"
00020
00021 using std::ostringstream;
00022 using namespace Marsyas;
00023
00024
00025 HarmonicEnhancer::HarmonicEnhancer(mrs_string name):MarSystem("HarmonicEnhancer",name)
00026 {
00027
00028
00029 }
00030
00031 HarmonicEnhancer::~HarmonicEnhancer()
00032 {
00033 }
00034
00035
00036 MarSystem*
00037 HarmonicEnhancer::clone() const
00038 {
00039 return new HarmonicEnhancer(*this);
00040 }
00041
00042
00043 void
00044 HarmonicEnhancer::myUpdate(MarControlPtr sender)
00045 {
00046 (void) sender;
00047 MRSDIAG("HarmonicEnhancer.cpp - HarmonicEnhancer:myUpdate");
00048
00049 setctrl("mrs_natural/onSamples", (mrs_natural)1);
00050 setctrl("mrs_natural/onObservations", (mrs_natural)4);
00051 setctrl("mrs_real/osrate", getctrl("mrs_real/israte"));
00052
00053 flag_.create(getctrl("mrs_natural/inSamples")->to<mrs_natural>());
00054
00055 setctrl("mrs_string/onObsNames", getctrl("mrs_string/inObsNames"));
00056 }
00057
00058 void
00059 HarmonicEnhancer::harm_prob(mrs_real& pmax, mrs_real factor,
00060 mrs_real& s1, mrs_natural& t1,
00061 mrs_real& s2, mrs_natural& t2,
00062 mrs_natural tmx,
00063 mrs_natural size,
00064 realvec& in)
00065 {
00066
00067 mrs_natural index = (mrs_natural) floor(factor * tmx + 0.5);
00068
00069
00070
00071 mrs_real prob;
00072 mrs_real c;
00073
00074 if (index > 100.0)
00075 c = 1.0;
00076 else
00077 c = 0.75;
00078
00079 mrs_real a;
00080
00081 if ((tmx > 50)&&(tmx < 100))
00082 a = 1.5;
00083 else
00084 a = 0.75;
00085
00086
00087
00088
00089 if (index < size)
00090 {
00091 prob = a * in(0,tmx) + c *(in(0, index));
00092
00093
00094 if ((index-1 > 0) && (index-1 < size))
00095 prob += (c * in(0, index-1));
00096 if ((index+1 > 0) && (index+1 < size))
00097 prob += (c * in(0, index+1));
00098
00099
00100 if ((index-2 > 0) && (index-2 < size))
00101 prob += (c * in(0, index-2));
00102 if ((index+2 > 0) && (index+2 < size))
00103 prob += (c * in(0, index+2));
00104
00105 if ((index-3 > 0) && (index-3 < size))
00106 prob += (c * in(0, index-3));
00107 if ((index+3 > 0) && (index+3 < size))
00108 prob += (c * in(0, index+3));
00109
00110 if (index > 150.0)
00111 {
00112
00113 if ((index-4 > 0) && (index-4 < size))
00114 prob += (c * in(0, index-4));
00115 if ((index+4 > 0) && (index+4 < size))
00116 prob += (c * in(0, index+4));
00117
00118 if ((index-5 > 0) && (index-5 < size))
00119 prob += (c * in(0, index-5));
00120 if ((index+5 > 0) && (index+5 < size))
00121 prob += (c * in(0, index+5));
00122
00123
00124 if ((index-6 > 0) && (index-6 < size))
00125 prob += (c * in(0, index-6));
00126 if ((index+6 > 0) && (index+6 < size))
00127 prob += (c * in(0, index+6));
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 }
00154 else
00155 prob = 0;
00156
00157
00158
00159 if (prob > pmax)
00160 {
00161 if (tmx < index)
00162 {
00163 s1 = in(0,tmx);
00164 s2 = in(0,index);
00165 if ((index-1 > 0) && (index-1 < size))
00166 s2 += in(0,index-1);
00167 if ((index+1 > 0) && (index+1 < size))
00168 s2 += in(0,index+1);
00169
00170 if ((index-2 > 0) && (index-2 < size))
00171 s2 += in(0,index-2);
00172 if ((index+2 > 0) && (index+2 < size))
00173 s2 += in(0,index+2);
00174
00175 if ((index-3 > 0) && (index-3 < size))
00176 s2 += in(0,index-3);
00177 if ((index+3 > 0) && (index+3 < size))
00178 s2 += in(0,index+3);
00179
00180 t1 = tmx+1;
00181 t2 = (mrs_natural)(factor * t1);
00182 pmax = prob;
00183 }
00184 else
00185 {
00186 s1 = in(0,index);
00187 if ((index-1 > 0) && (index-1 < size))
00188 s1 += in(0,index-1);
00189 if ((index+1 > 0) && (index+1 < size))
00190 s1 += in(0,index+1);
00191
00192 if ((index-2 > 0) && (index-2 < size))
00193 s1 += in(0,index-2);
00194 if ((index+2 > 0) && (index+2 < size))
00195 s1 += in(0,index+2);
00196
00197 if ((index-3 > 0) && (index-3 < size))
00198 s1 += in(0,index-3);
00199 if ((index+3 > 0) && (index+3 < size))
00200 s1 += in(0,index+3);
00201
00202
00203
00204 s2 = in(0,tmx);
00205 t1 = index+1;
00206 t2 = (mrs_natural)(factor * t1);
00207 pmax = prob;
00208 }
00209 }
00210
00211
00212
00213
00214 }
00215
00216
00217
00218 void
00219 HarmonicEnhancer::myProcess(realvec& in, realvec& out)
00220 {
00221
00222
00223 mrs_real mx = DBL_MIN;
00224 mrs_natural tmx = 0;
00225 mrs_natural o,t,c;
00226
00227
00228 mrs_real pmax = DBL_MIN;
00229 mrs_natural t1;
00230 mrs_natural t2;
00231 mrs_real s1;
00232 mrs_real s2;
00233
00234
00235 flag_.setval(0.0);
00236
00237 for (c=0; c < 3; ++c)
00238 {
00239
00240 for (o=0; o < inObservations_; o++)
00241 for (t = 0; t < inSamples_; t++)
00242 {
00243 if ((in(o,t) > mx)&&(flag_(t) == 0.0)&&(t > 40) && (t < 120))
00244 {
00245 mx = in(o,t);
00246 tmx = t;
00247 }
00248 }
00249
00250
00251 flag_(tmx) = 1.0;
00252 mx = DBL_MIN;
00253
00254
00255
00256 if (tmx < 120.0)
00257 {
00258 harm_prob(pmax, 2, s1, t1, s2, t2, tmx, inSamples_, in);
00259 harm_prob(pmax, 3.0, s1, t1, s2, t2, tmx, inSamples_, in);
00260 }
00261 else
00262 {
00263 harm_prob(pmax, 0.5, s1, t1, s2, t2, tmx, inSamples_, in);
00264 harm_prob(pmax, 0.33333, s1, t1, s2, t2, tmx, inSamples_, in);
00265 }
00266
00267 }
00268
00269 flag_.setval(0.0);
00270
00271
00272
00273
00274 out(0,0) = s1;
00275 out(1,0) = t1;
00276 out(2,0) = s2;
00277 out(3,0) = t2;
00278
00279
00280
00281
00282
00283
00284 }
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294