Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2006 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #include "Reassign.h" 00020 #include "../common_source.h" 00021 00022 #include <cfloat> 00023 00024 using namespace std; 00025 using namespace Marsyas; 00026 00027 Reassign::Reassign(mrs_string name):MarSystem("Reassign",name) 00028 { 00029 //type_ = "Reassign"; 00030 //name_ = name; 00031 } 00032 00033 00034 Reassign::~Reassign() 00035 { 00036 } 00037 00038 00039 MarSystem* 00040 Reassign::clone() const 00041 { 00042 return new Reassign(*this); 00043 } 00044 00045 void 00046 Reassign::myUpdate(MarControlPtr sender) 00047 { 00048 MRSDIAG("Reassign.cpp - Reassign:myUpdate"); 00049 00050 // setctrl("mrs_natural/onSamples", getctrl("mrs_natural/inSamples")); 00051 // setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations")); 00052 // setctrl("mrs_real/osrate", getctrl("mrs_real/israte")); 00053 MarSystem::myUpdate(sender); 00054 00055 flag_.create(getctrl("mrs_natural/inSamples")->to<mrs_natural>()); 00056 00057 setctrl("mrs_string/onObsNames", getctrl("mrs_string/inObsNames")); 00058 } 00059 00060 void 00061 Reassign::myProcess(realvec& in, realvec& out) 00062 { 00063 mrs_natural o,t,c; 00064 mrs_real mx = DBL_MIN; 00065 mrs_natural tmx = 0; 00066 flag_.setval(0.0); 00067 00068 00069 for (c=0; c < 5; ++c) 00070 { 00071 00072 for (o=0; o < inObservations_; o++) 00073 for (t = 0; t < inSamples_/2; t++) 00074 { 00075 if ((in(o,t) > mx)&&(flag_(t) == 0.0)) 00076 { 00077 mx = in(o,t); 00078 tmx = t; 00079 } 00080 } 00081 00082 00083 flag_(tmx) = 1.0; 00084 mx = DBL_MIN; 00085 out(0,tmx) = in(0,tmx); 00086 00087 00088 if ((tmx-1 > 0) && (tmx-1 < inSamples_)) 00089 { 00090 out(0, tmx) += in(0,tmx-1); 00091 out(0,tmx-1) = 0.0; 00092 flag_(tmx-1) = 1.0; 00093 } 00094 00095 00096 if ((tmx+1 > 0) && (tmx+1 < inSamples_)) 00097 { 00098 out(0, tmx) += in(0, tmx+1); 00099 out(0,tmx+1) = 0.0; 00100 flag_(tmx+1) = 1.0; 00101 } 00102 00103 if ((tmx-2 > 0) && (tmx-2 < inSamples_)) 00104 { 00105 out(0, tmx) += in(0, tmx-2); 00106 out(0,tmx-2) = 0.0; 00107 flag_(tmx-2) = 1.0; 00108 } 00109 00110 00111 if ((tmx+2 > 0) && (tmx+2 < inSamples_)) 00112 { 00113 out(0, tmx) += in(0, tmx+2); 00114 out(0,tmx+2) = 0.0; 00115 flag_(tmx+2) = 1.0; 00116 } 00117 00118 00119 if ((tmx-3 > 0) && (tmx-3 < inSamples_)) 00120 { 00121 out(0, tmx) += in(0, tmx-3); 00122 out(0,tmx-3) = 0.0; 00123 flag_(tmx-3) = 1.0; 00124 } 00125 00126 00127 if ((tmx+3 > 0) && (tmx+3 < inSamples_)) 00128 { 00129 out(0, tmx) += in(0, tmx+3); 00130 out(0,tmx+3) = 0.0; 00131 flag_(tmx+3) = 1.0; 00132 } 00133 00134 00135 if ((tmx-4 > 0) && (tmx-4 < inSamples_)) 00136 { 00137 out(0, tmx) += in(0, tmx-4); 00138 out(0,tmx-4) = 0.0; 00139 flag_(tmx-4) = 1.0; 00140 } 00141 00142 00143 if ((tmx+4 > 0) && (tmx+4 < inSamples_)) 00144 { 00145 out(0, tmx) += in(0, tmx+4); 00146 out(0,tmx+4) = 0.0; 00147 flag_(tmx+4) = 1.0; 00148 } 00149 00150 00151 if ((tmx-5 > 0) && (tmx-5 < inSamples_)) 00152 { 00153 out(0, tmx) += in(0, tmx-5); 00154 out(0,tmx-5) = 0.0; 00155 flag_(tmx-5) = 1.0; 00156 } 00157 00158 00159 if ((tmx+5 > 0) && (tmx+5 < inSamples_)) 00160 { 00161 out(0, tmx) += in(0, tmx+5); 00162 out(0,tmx+5) = 0.0; 00163 flag_(tmx+5) = 1.0; 00164 } 00165 00166 00167 } 00168 00169 00170 flag_.setval(0.0); 00171 00172 00173 for (c=0; c < 4; ++c) 00174 { 00175 00176 for (o=0; o < inObservations_; o++) 00177 for (t = inSamples_/2; t < inSamples_; t++) 00178 { 00179 if ((in(o,t) > mx)&&(flag_(t) == 0.0)) 00180 { 00181 mx = in(o,t); 00182 tmx = t; 00183 } 00184 } 00185 00186 00187 flag_(tmx) = 1.0; 00188 mx = DBL_MIN; 00189 out(0,tmx) = in(0,tmx); 00190 00191 00192 if ((tmx-1 > 0) && (tmx-1 < inSamples_)) 00193 { 00194 out(0, tmx) += in(0,tmx-1); 00195 out(0,tmx-1) = 0.0; 00196 flag_(tmx-1) = 1.0; 00197 } 00198 00199 00200 if ((tmx+1 > 0) && (tmx+1 < inSamples_)) 00201 { 00202 out(0, tmx) += in(0, tmx+1); 00203 out(0,tmx+1) = 0.0; 00204 flag_(tmx+1) = 1.0; 00205 } 00206 00207 if ((tmx-2 > 0) && (tmx-2 < inSamples_)) 00208 { 00209 out(0, tmx) += in(0, tmx-2); 00210 out(0,tmx-2) = 0.0; 00211 flag_(tmx-2) = 1.0; 00212 } 00213 00214 00215 if ((tmx+2 > 0) && (tmx+2 < inSamples_)) 00216 { 00217 out(0, tmx) += in(0, tmx+2); 00218 out(0,tmx+2) = 0.0; 00219 flag_(tmx+2) = 1.0; 00220 } 00221 00222 00223 if ((tmx-3 > 0) && (tmx-3 < inSamples_)) 00224 { 00225 out(0, tmx) += in(0, tmx-3); 00226 out(0,tmx-3) = 0.0; 00227 flag_(tmx-3) = 1.0; 00228 } 00229 00230 00231 if ((tmx+3 > 0) && (tmx+3 < inSamples_)) 00232 { 00233 out(0, tmx) += in(0, tmx+3); 00234 out(0,tmx+3) = 0.0; 00235 flag_(tmx+3) = 1.0; 00236 } 00237 00238 00239 if ((tmx-4 > 0) && (tmx-4 < inSamples_)) 00240 { 00241 out(0, tmx) += in(0, tmx-4); 00242 out(0,tmx-4) = 0.0; 00243 flag_(tmx-4) = 1.0; 00244 } 00245 00246 00247 if ((tmx+4 > 0) && (tmx+4 < inSamples_)) 00248 { 00249 out(0, tmx) += in(0, tmx+4); 00250 out(0,tmx+4) = 0.0; 00251 flag_(tmx+4) = 1.0; 00252 } 00253 00254 00255 if ((tmx-5 > 0) && (tmx-5 < inSamples_)) 00256 { 00257 out(0, tmx) += in(0, tmx-5); 00258 out(0,tmx-5) = 0.0; 00259 flag_(tmx-5) = 1.0; 00260 } 00261 00262 00263 if ((tmx+5 > 0) && (tmx+5 < inSamples_)) 00264 { 00265 out(0, tmx) += in(0, tmx+5); 00266 out(0,tmx+5) = 0.0; 00267 flag_(tmx+5) = 1.0; 00268 } 00269 00270 00271 } 00272 00273 00274 00275 00276 00277 } 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287