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