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 "PeUtilities.h" 00020 00021 #include "AudioSink.h" 00022 #include "SoundFileSink.h" 00023 #include "SoundFileSource.h" 00024 #include "NumericLib.h" 00025 00026 using std::ostringstream; 00027 using std::abs; 00028 00029 using namespace Marsyas; 00030 00031 //[TODO] -> deprecate all this junk!! 00032 00033 00034 // //online --> matrix 00035 // int 00036 // Marsyas::peaks2M(realvec& in, realvec& first, realvec& out, mrs_natural maxNbPeaks, mrs_natural *nbPkFrame, mrs_natural start) 00037 // { 00038 // int i,j,k,l=start,m=0; 00039 // 00040 // if(&first != NULL && first(0)) //[WTF] 00041 // for (i=0 ; i<maxNbPeaks ; ++i) 00042 // { 00043 // if(first(i) != 0.0) 00044 // { 00045 // for(k=0;k<nbPkParameters;k++) 00046 // out(l, k) = first(k*maxNbPeaks+i);//[WTF] 00047 // l++; 00048 // m++; 00049 // } 00050 // } 00051 // *nbPkFrame = m; 00052 // 00053 // for (j=0 ; j<in.getCols() ; j++) 00054 // for (i=0 ; i<maxNbPeaks ; ++i) 00055 // { 00056 // if(in(i, j) != 0.0) 00057 // { 00058 // for(k=0;k<nbPkParameters;k++) 00059 // out(l, k) = in(k*maxNbPeaks+i, j); 00060 // l++; 00061 // } 00062 // } 00063 // out.stretch(l, nbPkParameters); 00064 // return l-start; 00065 // } 00066 // 00067 // void 00068 // Marsyas::peaks2V (realvec& in, realvec& last, realvec& out, mrs_natural maxNbPeaks, mrs_natural label) 00069 // { 00070 // mrs_natural i, j, k=0, start=0, iStart=0; 00071 // mrs_natural frameIndex=-1, startIndex = (mrs_natural) in(0, pkFrame); 00072 // 00073 // out.setval(0); 00074 // 00075 // // on-line case with first init 00076 // if(label == -1 && last(0)) 00077 // { 00078 // start=1; 00079 // startIndex +=1; 00080 // } 00081 // // if coming from a saved realvec first elts contain config so should be avoided 00082 // if(in(0) == -1) 00083 // { 00084 // iStart = 1; 00085 // } 00086 // 00087 // for (i=iStart ; i<in.getRows() ; ++i, k++) 00088 // { 00089 // if(frameIndex != in(i, 5)) 00090 // { 00091 // frameIndex = (mrs_natural) in(i, 5); 00092 // k=0; 00093 // } 00094 // if((!start || (start && in(i, 5) >= startIndex))) 00095 // if(label < 0 || label == in(i, pkGroup)) 00096 // for (j=0 ; j<in.getCols() ; j++) 00097 // { 00098 // out(j*maxNbPeaks+k, frameIndex-startIndex) = in(i, j); 00099 // /* if(peakFile) 00100 // peakFile << in(i, j);*/ 00101 // } 00102 // } 00103 // //on-line case 00104 // if(label == -1) 00105 // { 00106 // for (j=0 ; j<out.getRows() ; j++) 00107 // { 00108 // last(j) = out(j, out.getCols()-1); 00109 // } 00110 // } 00111 // } 00112 // 00113 // 00114 // void Marsyas::updateLabels(realvec& peakSet, realvec& conversion) 00115 // { 00116 // for (mrs_natural i=0 ; i<peakSet.getRows() ; ++i) 00117 // peakSet(i, pkGroup) = conversion((mrs_natural) peakSet(i, pkGroup)+2); 00118 // } 00119 // 00120 // 00121 // void Marsyas::extractParameter(realvec&in, std::vector<realvec>& out, pkParameter type, mrs_natural kmax) 00122 // { 00123 // mrs_natural i, index, k=0; 00124 // mrs_natural frameIndex=-1; 00125 // mrs_natural startIndex = (mrs_natural)in(0, pkFrame); 00126 // mrs_natural endIndex = (mrs_natural) in(in.getRows()-1, pkFrame); 00127 // mrs_natural nbFrames = endIndex-startIndex+1; 00128 // mrs_natural* l = new mrs_natural[nbFrames]; 00129 // realvec vec(kmax); 00130 // vec.setval(0); 00131 // 00132 // // allocate vector of realvec 00133 // for (i=0 ; i < nbFrames ; ++i) 00134 // { 00135 // out.push_back(vec); 00136 // l[i]=0; 00137 // } 00138 // 00139 // // fill vector 00140 // for (i=0 ; i<in.getRows() ; ++i) 00141 // { 00142 // index = (mrs_natural) in(i, pkFrame) - startIndex; 00143 // if( in(i, pkGroup) >= 0) 00144 // { 00145 // out[index](l[index]) = in(i, type); 00146 // l[index]++; 00147 // } 00148 // } 00149 // // stretch realvecs 00150 // for (i=0 ; i < nbFrames ; ++i) 00151 // { 00152 // out[i].stretch(l[i]); 00153 // } 00154 // 00155 // delete [] l; 00156 // ////out.setval(0); 00157 // //for (i=0 ; i<in.getRows() ; ++i) 00158 // //{ 00159 // // if(frameIndex != in(i, pkFrame)) 00160 // // { 00161 // // if(k) 00162 // // { 00163 // // vec.stretch(k); 00164 // // // put inside vector 00165 // // out.push_back(vec); 00166 // // vec.stretch(kmax); 00167 // // } 00168 // // else 00169 // // out.push_back(realvec()); 00170 // // frameIndex = (mrs_natural) in(i, pkFrame); 00171 // // k=0; 00172 // // } 00173 // // if(in(i, pkFrame) == frameIndex) 00174 // // { 00175 // // vec(k++) = in(i, type); 00176 // // } 00177 // //} 00178 // //if(k) 00179 // //{ 00180 // // vec.stretch(k); 00181 // // // put inside vector 00182 // // out.push_back(vec); 00183 // //} 00184 // } 00185 // 00186 // 00187 // mrs_real 00188 // Marsyas::compareTwoPeakSets(realvec&f1, realvec&a1, realvec&f2, realvec&a2) 00189 // { 00190 // mrs_natural nb=0; 00191 // mrs_real res=0; 00192 // realvec i1(f1.getSize()); 00193 // realvec i2(f2.getSize()); 00194 // i1.setval(1); 00195 // i2.setval(1); 00196 // 00197 // //cout << f1 << a1 << f2 << a2 ; 00198 // // while the smallest set is not empty 00199 // MATLAB_EVAL("Acc=[];"); 00200 // while (1) 00201 // { 00202 // 00203 // 00204 // //cout << i1<<i2; 00205 // mrs_natural ind1=-1, ind2=0; 00206 // mrs_real A1, A2, F1, F2; 00207 // // minDiff = 10000000000000, maxVal = -100000000000000; 00208 // mrs_real maxVal = 0, minDiff =100; 00209 // // take the highest amplitude peak 00210 // for (mrs_natural i=0 ; i<a1.getSize() ; ++i) 00211 // { 00212 // A1 = a1(i); 00213 // if(i1(i) && A1 > maxVal) 00214 // { 00215 // maxVal= A1; 00216 // ind1 = i; 00217 // } 00218 // } 00219 // if(ind1 == -1) break; 00220 // 00221 // F1 = f1(ind1); 00222 // A1 = a1(ind1); 00223 // // find the closest frequency peak in the second set 00224 // for (mrs_natural i=0 ; i<f2.getSize() ; ++i) 00225 // { 00226 // F2 = f2(i); 00227 // if(i2(i) && abs(F1-F2) < minDiff) 00228 // { 00229 // minDiff= abs(F1-F2); // or product of fDiff and aDiff 00230 // ind2 = i; 00231 // } 00232 // } 00233 // A2 = a2(ind2); 00234 // // acc the amplitude difference 00235 // res += abs(A1-A2)*abs(F1-F2); // or product of fDiff and aDiff 00236 // nb++; 00237 // // remove the two peaks 00238 // i1(ind1) = 0; 00239 // i2(ind2) = 0; 00240 // 00241 // MATLAB_PUT(f1, "f1"); 00242 // MATLAB_PUT(a1, "a1"); 00243 // MATLAB_PUT(i1, "i1"); 00244 // MATLAB_PUT(i2, "i2"); 00245 // MATLAB_PUT(f2, "f2"); 00246 // MATLAB_PUT(a2, "a2"); 00247 // MATLAB_PUT(abs(A1-A2)*abs(F1-F2), "acc"); 00248 // MATLAB_EVAL("Acc=[Acc acc] ;subplot(2, 1, 1) ; plot(f1, a1.*i1, '*r', f2, a2.*i2, 'k+'); subplot(2, 1, 2); plot(Acc)"); 00249 // 00250 // } 00251 // return res/nb; 00252 // } 00253 // 00254 // mrs_real 00255 // Marsyas::compareTwoPeakSets2(realvec&f1, realvec&a1, realvec&f2, realvec&a2) 00256 // { 00257 // mrs_real res = 0; 00258 // for (mrs_natural i = 0 ; i < f1.getSize() ; ++i) 00259 // for (mrs_natural j = 0 ; j < f2.getSize() ; j++) 00260 // { 00261 // res += abs(f1(i)-f2(j))* abs(a1(i)-a2(j)); 00262 // } 00263 // return res/(f1.getSize()*f2.getSize()); 00264 // } 00265 // 00266 // mrs_real 00267 // Marsyas::compareTwoPeakSets3(realvec&f1, realvec&a1, realvec&f2, realvec&a2) 00268 // { 00269 // mrs_natural nb=0; 00270 // mrs_real res=0; 00271 // realvec i1(f1.getSize()); 00272 // realvec i2(f2.getSize()); 00273 // i1.setval(1); 00274 // i2.setval(1); 00275 // 00276 // //cout << f1 << a1 << f2 << a2 ; 00277 // // while the smallest set is not empty 00278 // while (1) 00279 // { 00280 // //cout << i1<<i2; 00281 // mrs_natural ind1=-1, ind2=0; 00282 // // mrs_real minDiff = 10000000000000, minVal = 100000000000000; 00283 // 00284 // mrs_real minVal = 0; 00285 // // 00286 // // 00287 // // look for the smallest couple 00288 // for (mrs_natural i=0 ; i<a1.getSize() ; ++i) 00289 // for (mrs_natural j=0 ; j<a2.getSize() ; j++) 00290 // { 00291 // mrs_real val = abs(f1(i)-f2(j)); 00292 // if(i1(i) && i2(j) && val < minVal) 00293 // { 00294 // minVal= val; 00295 // ind1 = i; 00296 // ind2 = j; 00297 // } 00298 // } 00299 // 00300 // if(ind1 == -1 || ind2 == -1) break; 00301 // 00302 // mrs_real val = abs(a1(ind1)-a2(ind2))*abs(f1(ind1)-f2(ind2)); 00303 // res += val; // or product of fDiff and aDiff 00304 // nb++; 00305 // // remove the two peaks 00306 // i1(ind1) = 0; 00307 // i2(ind2) = 0; 00308 // 00309 // MATLAB_PUT(f1, "f1"); 00310 // MATLAB_PUT(a1, "a1"); 00311 // MATLAB_PUT(i1, "i1"); 00312 // MATLAB_PUT(i2, "i2"); 00313 // MATLAB_PUT(f2, "f2"); 00314 // MATLAB_PUT(a2, "a2"); 00315 // MATLAB_EVAL("subplot(2, 1, 1) ; plot(f1, a1.*i1, '*r', f2, a2.*i2, 'k+'); subplot(2, 1, 2); plot(Acc)"); 00316 // 00317 // } 00318 // return res/nb; 00319 // } 00320 // 00321 // mrs_real 00322 // Marsyas::correlatePeakSets(realvec&f1, realvec&a1, realvec&f2, realvec&a2) 00323 // { 00324 // mrs_real res=0; 00325 // realvec i1(f1.getSize()); 00326 // realvec i2(f2.getSize()); 00327 // i1.setval(1); 00328 // i2.setval(1); 00329 // 00330 // //cout << f1 << a1 << f2 << a2 ; 00331 // for (mrs_natural k=0; k<f1.getSize() ; k++) 00332 // { 00333 // //cout << i1<<i2; 00334 // mrs_natural ind1=-1, ind2=-1; 00335 // mrs_real minDiff = 2; 00336 // // look for the couple closest in frequency 00337 // for (mrs_natural i=0 ; i<f1.getSize() ; ++i) 00338 // for (mrs_natural j=0 ; j<f2.getSize() ; j++) 00339 // if(i1(i) && i2(j)) 00340 // { 00341 // mrs_real fa = f1(i), fb = f2(j); 00342 // if(fa>fb) 00343 // { 00344 // fa = f2(j); 00345 // fb = f1(i); 00346 // } 00347 // mrs_real df = fb-fa; 00348 // if(df>1-fb+fa) 00349 // df = 1-fb+fa; 00350 // 00351 // if(df < minDiff) 00352 // { 00353 // minDiff= df; 00354 // ind1 = i; 00355 // ind2 = j; 00356 // } 00357 // } 00358 // 00359 // 00360 // 00361 // 00362 // cout << i1; 00363 // cout << i2; 00364 // 00365 // 00366 // 00367 // mrs_real val = a1(ind1)*a2(ind2)/(minDiff*minDiff+0.0000000000000001); 00368 // cout << ind1 << " " << ind2 << " " << val << endl; 00369 // res += val; // or product of fDiff and aDiff 00370 // // remove the two peaks 00371 // if(ind1 != -1) 00372 // { 00373 // i1(ind1) = 0; 00374 // i2(ind2) = 0; 00375 // } 00376 // else 00377 // { 00378 // cout << i1 << i2; 00379 // } 00380 // /* MATLAB_PUT(f1, "f1"); 00381 // MATLAB_PUT(a1, "a1"); 00382 // MATLAB_PUT(i1, "i1"); 00383 // MATLAB_PUT(i2, "i2"); 00384 // MATLAB_PUT(f2, "f2"); 00385 // MATLAB_PUT(a2, "a2"); 00386 // MATLAB_PUT(val, "acc"); 00387 // MATLAB_EVAL("plotHarmo");*/ 00388 // // cout << ind1 <<" " << ind2<<endl; 00389 // } 00390 // return res/f1.getSize(); 00391 // } 00392 // 00393 // mrs_real 00394 // Marsyas::cosinePeakSets(realvec&f1, realvec&a1, realvec&f2, realvec&a2, realvec&a3, realvec&a4, realvec&x1, realvec&x2, realvec&x3, realvec&x4, mrs_natural length) 00395 // { 00396 // mrs_natural index; 00397 // mrs_real res1=0, res2=0, res3=0, res; 00398 // 00399 // x1.setval(0); 00400 // x2.setval(0); 00401 // x3.setval(0); 00402 // x4.setval(0); 00403 // // first discrete Harmonically Wrapped Spectrum 00404 // for (mrs_natural i=0 ; i<f1.getSize() ; ++i) 00405 // { 00406 // index= (mrs_natural) fmod(floor(f1(i)*length+.5), length); 00407 // x1(index) += a1(i); 00408 // x3(index) += a3(i); 00409 // } 00410 // // second discrete Harmonically Wrapped Spectrum 00411 // for (mrs_natural i=0 ; i<f2.getSize() ; ++i) 00412 // { 00413 // index= (mrs_natural) fmod(floor(f2(i)*length+.5), length); 00414 // // cout << endl << "index " << index << endl; 00415 // x2(index) += a2(i); 00416 // x4(index) += a4(i); 00417 // } 00418 // // cosine metric 00419 // for (mrs_natural i=0 ; i<x1.getSize() ; ++i) 00420 // { 00421 // res1 += x1(i)*x2(i); 00422 // res2 += x3(i)*x3(i); 00423 // res3 += x4(i)*x4(i); 00424 // } 00425 // if (res2 && res3) 00426 // res = res1/(sqrt(res2)*sqrt(res3)); 00427 // else 00428 // res = 0; 00429 // /*if(res3==0) 00430 // { 00431 // cout << a4 ; 00432 // cout << res1 << " " << res2 << " " << res3 << " " << x1.getSize() << endl; 00433 // 00434 // }*/ 00435 // 00436 // //MATLAB_PUT(x1, "x1"); 00437 // //MATLAB_PUT(x2, "x2"); 00438 // //MATLAB_EVAL("plotHarmo"); 00439 // 00440 // return res; 00441 // } 00442 00443 void Marsyas::synthNetCreate(MarSystemManager *mng, mrs_string outsfname, bool microphone, mrs_natural synType, bool residual) 00444 { 00445 //create Shredder series 00446 MarSystem* postNet = mng->create("Series", "postNet"); 00447 // postNet->addMarSystem(mng->create("PeOverlapadd", "ob")); 00448 if (synType < 3) 00449 { 00450 if(synType == 0) 00451 { 00452 postNet->addMarSystem(mng->create("PeakSynthOsc", "pso")); 00453 postNet->addMarSystem(mng->create("Windowing", "wiSyn")); 00454 } 00455 else 00456 { 00457 // put a fake object for probing the series 00458 postNet->addMarSystem(mng->create("Gain", "fakeGain")); 00459 postNet->addMarSystem(mng->create("FlowCutSource", "fcs")); 00460 // put the original source 00461 if (microphone) 00462 postNet->addMarSystem(mng->create("AudioSource", "srcSyn")); 00463 else 00464 postNet->addMarSystem(mng->create("SoundFileSource", "srcSyn")); 00465 // set the correct buffer size 00466 postNet->addMarSystem(mng->create("ShiftInput", "siSyn")); 00467 // perform an FFT 00468 postNet->addMarSystem(mng->create("Spectrum", "specSyn")); 00469 // convert to polar 00470 postNet->addMarSystem(mng->create("Cartesian2Polar", "c2p")); 00471 // perform amplitude and panning change 00472 postNet->addMarSystem(mng->create("PeakSynthFFT", "psf")); 00473 // convert back to cartesian 00474 postNet->addMarSystem(mng->create("Polar2Cartesian", "p2c")); 00475 // perform an IFFT 00476 // postNet->addMarSystem(mng->create("PlotSink", "plot")); 00477 postNet->addMarSystem(mng->create("InvSpectrum", "invSpecSyn")); 00478 // postNet->addMarSystem(mng->create("PlotSink", "plot2")); 00479 postNet->addMarSystem(mng->create("Windowing", "wiSyn")); 00480 } 00481 00482 postNet->addMarSystem(mng->create("OverlapAdd", "ov")); 00483 } 00484 else 00485 { 00486 postNet->addMarSystem(mng->create("PeakSynthOscBank", "pso")); 00487 // postNet->addMarSystem(mng->create("ShiftOutput", "so")); 00488 } 00489 00490 postNet->addMarSystem(mng->create("Gain", "outGain")); 00491 00492 MarSystem *dest; 00493 if (outsfname == "MARSYAS_EMPTY") 00494 dest = new AudioSink("dest"); 00495 else 00496 { 00497 dest = new SoundFileSink("dest"); 00498 //dest->updControl("mrs_string/filename", outsfname); 00499 } 00500 00501 if(residual) 00502 { 00503 MarSystem* fanout = mng->create("Fanout", "fano"); 00504 fanout->addMarSystem(dest); 00505 MarSystem* fanSeries = mng->create("Series", "fanSeries"); 00506 00507 if (microphone) 00508 fanSeries->addMarSystem(mng->create("AudioSource", "src2")); 00509 else 00510 fanSeries->addMarSystem(mng->create("SoundFileSource", "src2")); 00511 00512 fanSeries->addMarSystem(mng->create("Delay", "delay")); 00513 fanout->addMarSystem(fanSeries); 00514 00515 postNet->addMarSystem(fanout); 00516 postNet->addMarSystem(mng->create("PeakResidual", "res")); 00517 00518 MarSystem *destRes; 00519 if (outsfname == "MARSYAS_EMPTY") 00520 destRes = new AudioSink("destRes"); 00521 else 00522 { 00523 destRes = new SoundFileSink("destRes"); 00524 //dest->updControl("mrs_string/filename", outsfname); 00525 } 00526 postNet->addMarSystem(destRes); 00527 } 00528 else 00529 postNet->addMarSystem(dest); 00530 00531 MarSystem* shredNet = mng->create("Shredder", "shredNet"); 00532 shredNet->addMarSystem(postNet); 00533 00534 mng->registerPrototype("PeSynthetize", shredNet); 00535 } 00536 00537 void 00538 Marsyas::synthNetConfigure(MarSystem *pvseries, mrs_string sfName, mrs_string outsfname, mrs_string ressfname, std::string panningInfo, mrs_natural nbChannels, mrs_natural Nw, 00539 mrs_natural D, mrs_natural S, mrs_natural accSize, bool microphone, mrs_natural synType, mrs_natural bopt, mrs_natural delay, mrs_real fs, bool residual) 00540 { 00541 // FIXME Unused parameters 00542 (void) nbChannels; 00543 (void) S; 00544 00545 pvseries->updControl("PeSynthetize/synthNet/mrs_natural/nTimes", accSize); 00546 00547 if (synType < 3) 00548 { 00549 if(synType==0) 00550 { 00551 //pvseries->updControl("PeSynthetize/synthNet/Series/postNet/PeakSynthOsc/pso/mrs_natural/nbSinusoids", S); 00552 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/PeakSynthOsc/pso/mrs_natural/delay", delay); // Nw/2+1 00553 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/PeakSynthOsc/pso/mrs_natural/synSize", D*2); 00554 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/PeakSynthOsc/pso/mrs_real/samplingFreq", fs); 00555 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/Windowing/wiSyn/mrs_string/type", "Hanning"); 00556 } 00557 else 00558 { 00559 // linking between the first slice and the psf 00560 pvseries->linkControl("PeSynthetize/synthNet/Series/postNet/mrs_realvec/processedData", "PeSynthetize/synthNet/Series/postNet/PeakSynthFFT/psf/mrs_realvec/peaks"); 00561 // 00562 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/Windowing/wiSyn/mrs_string/type", "Hanning"); 00563 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/FlowCutSource/fcs/mrs_natural/setSamples", D); 00564 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/FlowCutSource/fcs/mrs_natural/setObservations", 1); 00565 // setting the panning mode mono/stereo 00566 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/PeakSynthFFT/psf/mrs_natural/nbChannels", synType); 00567 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/PeakSynthFFT/psf/mrs_string/panning", panningInfo); 00568 // setting the FFT size 00569 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/ShiftInput/siSyn/mrs_natural/winSize", D*2); 00570 // setting the name of the original file 00571 if (microphone) 00572 { 00573 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/AudioSource/srcSyn/mrs_natural/inSamples", D); 00574 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/AudioSource/srcSyn/mrs_natural/inObservations", 1); 00575 } 00576 else 00577 { 00578 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/SoundFileSource/srcSyn/mrs_string/filename", sfName); 00579 // pvseries->updControl("PeSynthetize/synthNet/Series/postNet/SoundFileSource/srcSyn/mrs_natural/pos", 0); 00580 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/SoundFileSource/srcSyn/mrs_natural/onSamples", D); 00581 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/SoundFileSource/srcSyn/mrs_natural/onObservations", 1); 00582 } 00583 // setting the synthesis starting time (default 0) 00584 } 00585 } 00586 else 00587 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/PeakSynthOscBank/pso/mrs_natural/Interpolation", D); 00588 00589 // pvseries->updControl("PeSynthetize/synthNet/Series/postNet/ShiftOutput/so/mrs_natural/Interpolation", D); //[WTF] 00590 00591 if (outsfname == "MARSYAS_EMPTY") 00592 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/AudioSink/dest/mrs_natural/bufferSize", bopt); 00593 00594 if(residual) 00595 { 00596 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/Fanout/fano/Series/fanSeries/Delay/delay/mrs_natural/delay", delay); // Nw+1-D 00597 00598 if (microphone) 00599 { 00600 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/Fanout/fano/Series/fanSeries/AudioSource/src2/mrs_natural/inSamples", D); 00601 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/Fanout/fano/Series/fanSeries/AudioSource/src2/mrs_natural/inObservations", 1); 00602 } 00603 else 00604 { 00605 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/Fanout/fano/Series/fanSeries/SoundFileSource/src2/mrs_string/filename", sfName); 00606 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/Fanout/fano/Series/fanSeries/SoundFileSource/src2/mrs_natural/pos", 0); 00607 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/Fanout/fano/Series/fanSeries/SoundFileSource/src2/mrs_natural/inSamples", D); 00608 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/Fanout/fano/Series/fanSeries/SoundFileSource/src2/mrs_natural/inObservations", 1); 00609 } 00610 00611 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/Fanout/fano/SoundFileSink/dest/mrs_string/filename", outsfname);//[!] 00612 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/SoundFileSink/destRes/mrs_string/filename", ressfname);//[!] 00613 } 00614 else 00615 pvseries->updControl("PeSynthetize/synthNet/Series/postNet/SoundFileSink/dest/mrs_string/filename", outsfname);//[!] 00616 00617 } 00618 00619 // mrs_real Marsyas::harmonicWeighting(mrs_real f, mrs_real h, mrs_real w) 00620 // { 00621 // if(f < h) 00622 // return 1; 00623 // else 00624 // return pow(harmonicWeightingBasic(f, h), -w/log(harmonicWeightingBasic(1,h))); 00625 // } 00626 // 00627 // 00628 // mrs_real Marsyas::harmonicWeightingBasic(mrs_real f, mrs_real h) 00629 // { 00630 // return (1+cos(2*PI*f/h))/2; 00631 // } 00632 // 00633 // //[WTF] 00634 // void Marsyas::discrete2labels(realvec &labels, realvec& n, mrs_natural nbClusters, mrs_natural nbPeaks) 00635 // { 00636 // for(mrs_natural i=0 ; i<nbPeaks ; ++i) 00637 // for(mrs_natural j=0 ; j<nbClusters ; j++) 00638 // if(n(i*nbClusters+j) == 1) 00639 // labels(i) = j; 00640 // } 00641 // 00642 // void Marsyas::peakStore(realvec &peaks, mrs_string filename, mrs_real sf, mrs_natural hopSize) 00643 // { 00644 // mrs_natural nbFrames_ = peaks.getCols(); 00645 // 00646 // if(!nbFrames_) //i.e. if(nbFrames == 0) 00647 // { 00648 // // search from a file //[WTF] 00649 // peaks.read(filename) ; 00650 // peaks.transpose(); 00651 // nbFrames_ = peaks.getCols(); 00652 // } 00653 // realvec peakSetM_.create(peaks.getRows()/nbPkParameters*nbFrames_+1, nbPkParameters); 00654 // peakSetM_(0, 0) = -1; 00655 // peakSetM_(0, 1) = sf; 00656 // peakSetM_(0, 2) = hopSize; 00657 // peakSetM_(0, 3) = peaks.getRows()/nbPkParameters; 00658 // peakSetM_(0, 4) = nbFrames_; 00659 // peakSetM_(0, 5) = -1; 00660 // peakSetM_(0, pkGroup) = -2; //isn't this overwritten below?!? [WTF] 00661 // for (mrs_natural i=pkGroup ; i< nbPkParameters ; ++i) 00662 // peakSetM_(0, i)=0; 00663 // realvec tmp(1); 00664 // tmp.setval(0); 00665 // mrs_natural tmp2; 00666 // 00667 // peaks2M(peaks, tmp, peakSetM_, peaks.getRows()/nbPkParameters, &tmp2, 1); 00668 // 00669 // //cout << peakSetM_; 00670 // //cout << sf << " " << peakSetM_(0, 1) << endl ; 00671 // 00672 // //cout << peaks.getSize() << endl; 00673 // ofstream peakFile; 00674 // peakFile.open(filename.c_str()); 00675 // if(!peakFile) 00676 // cout << "Unable to open output Peaks File " << filename << endl; 00677 // peakFile << peakSetM_; 00678 // peakFile.close(); 00679 // } 00680 // 00681 // void Marsyas::peakLoad(realvec &peaks, mrs_string filename, mrs_real &fs, mrs_natural &nbSines, mrs_natural &nbFrames, mrs_natural &hopSize, bool tf_format) 00682 // { 00683 // realvec peakSet; 00684 // peakSet.read(filename); 00685 // 00686 // fs = peakSet(0, 1); 00687 // hopSize = peakSet(0, 2); 00688 // nbSines = peakSet(0, 3); 00689 // nbFrames = peakSet(0, 4); 00690 // 00691 // peakSet(0, 5) = -1; //HACK!!!!! [!] 00692 // 00693 // if(tf_format) 00694 // { 00695 // peaks.stretch(nbSines*nbPkParameters, nbFrames); 00696 // peaks.setval(0); 00697 // peaks2V(peakSet, peaks, peaks, nbSines); 00698 // } 00699 // else 00700 // peaks = peakSet; 00701 // } 00702 // 00703 // /* 00704 // mrs_real gaussian(mrs_real x, mrs_real v, mrs_real m) 00705 // { 00706 // return exp(-(x-m)*(x-m)/(2*v*v))/(v*sqrt(2*PI)); 00707 // }*/ 00708 // 00709 // 00710 // void Marsyas::computeHarmonicityMap(realvec& map, mrs_natural nbBins) 00711 // { 00712 // mrs_natural i, j; 00713 // realvec tmp(nbBins, nbBins); 00714 // map.stretch(nbBins, nbBins); 00715 // map.setval(0); 00716 // 00717 // for (i=0 ; i<nbBins ; ++i) 00718 // for (j=0 ; j<nbBins ; j++) 00719 // { 00720 // mrs_real val=0; 00721 // if((i+1)%(j+1) == 0 || (j+1)%(i+1) == 0) 00722 // val = 1; 00723 // tmp(i, j) = val; 00724 // } 00725 // 00726 // mrs_natural kSize=5, k, l; 00727 // mrs_real sum=0; 00728 // for (i=0 ; i<nbBins ; ++i) 00729 // for (j=0 ; j<nbBins ; j++) 00730 // for (k=max( (mrs_natural) 0, i-kSize); k<min(nbBins, i+kSize) ; k++) 00731 // for (l=max((mrs_natural) 0, j-kSize) ; l<min(nbBins, j+kSize) ; l++) 00732 // { 00733 // mrs_real val1 = NumericLib::gaussian (i+1, (k+1)/10.0, k+1); 00734 // mrs_real val2 = NumericLib::gaussian (j+1, (l+1)/10.0, l+1); 00735 // map(i, j) += tmp(k, l)*val1*val2; 00736 // sum += tmp(k, l)*val1*val2; 00737 // } 00738 // map/=sum; 00739 // }
1.5.6