comparison NNLSBase.cpp @ 77:ba930176df5b matthiasm-plugin

fixed. warning: I added some arrays with variable length (though not at runtime).
author Matthias Mauch <mail@matthiasmauch.net>
date Thu, 11 Nov 2010 10:27:58 +0900
parents d398e73b46e0
children 026a5c0ee2c2
comparison
equal deleted inserted replaced
76:d398e73b46e0 77:ba930176df5b
356 float hamwinsum = 0; 356 float hamwinsum = 0;
357 for (int i = 0; i < hamwinlength; ++i) { 357 for (int i = 0; i < hamwinlength; ++i) {
358 hw.push_back(0.54 - 0.46 * cos((2*M_PI*i)/(hamwinlength-1))); 358 hw.push_back(0.54 - 0.46 * cos((2*M_PI*i)/(hamwinlength-1)));
359 hamwinsum += 0.54 - 0.46 * cos((2*M_PI*i)/(hamwinlength-1)); 359 hamwinsum += 0.54 - 0.46 * cos((2*M_PI*i)/(hamwinlength-1));
360 } 360 }
361 for (int i = 0; i < hamwinlength; ++i) hw[i] = round(hw[i] / hamwinsum * 10000)*1.0/10000; 361 for (int i = 0; i < hamwinlength; ++i) hw[i] = hw[i] / hamwinsum;
362 362
363 if (channels < getMinChannelCount() || 363 if (channels < getMinChannelCount() ||
364 channels > getMaxChannelCount()) return false; 364 channels > getMaxChannelCount()) return false;
365 m_blockSize = blockSize; 365 m_blockSize = blockSize;
366 m_stepSize = stepSize; 366 m_stepSize = stepSize;
367 m_frameCount = 0; 367 m_frameCount = 0;
368 int tempn = 256 * m_blockSize/2; 368 int tempn = nNote * m_blockSize/2;
369 // cerr << "length of tempkernel : " << tempn << endl; 369 // cerr << "length of tempkernel : " << tempn << endl;
370 float *tempkernel; 370 float *tempkernel;
371 371
372 tempkernel = new float[tempn]; 372 tempkernel = new float[tempn];
373 373
575 } 575 }
576 576
577 f2.values.push_back(0.0); f2.values.push_back(0.0); f2.values.push_back(0.0); // upper edge 577 f2.values.push_back(0.0); f2.values.push_back(0.0); f2.values.push_back(0.0); // upper edge
578 vector<float> runningmean = SpecialConvolution(f2.values,hw); 578 vector<float> runningmean = SpecialConvolution(f2.values,hw);
579 vector<float> runningstd; 579 vector<float> runningstd;
580 for (int i = 0; i < 256; i++) { // first step: squared values into vector (variance) 580 for (int i = 0; i < nNote; i++) { // first step: squared values into vector (variance)
581 runningstd.push_back((f2.values[i] - runningmean[i]) * (f2.values[i] - runningmean[i])); 581 runningstd.push_back((f2.values[i] - runningmean[i]) * (f2.values[i] - runningmean[i]));
582 } 582 }
583 runningstd = SpecialConvolution(runningstd,hw); // second step convolve 583 runningstd = SpecialConvolution(runningstd,hw); // second step convolve
584 for (int i = 0; i < 256; i++) { 584 for (int i = 0; i < nNote; i++) {
585 runningstd[i] = sqrt(runningstd[i]); // square root to finally have running std 585 runningstd[i] = sqrt(runningstd[i]); // square root to finally have running std
586 if (runningstd[i] > 0) { 586 if (runningstd[i] > 0) {
587 // f2.values[i] = (f2.values[i] / runningmean[i]) > thresh ? 587 // f2.values[i] = (f2.values[i] / runningmean[i]) > thresh ?
588 // (f2.values[i] - runningmean[i]) / pow(runningstd[i],m_whitening) : 0; 588 // (f2.values[i] - runningmean[i]) / pow(runningstd[i],m_whitening) : 0;
589 f2.values[i] = (f2.values[i] - runningmean[i]) > 0 ? 589 f2.values[i] = (f2.values[i] - runningmean[i]) > 0 ?
635 f5.timestamp = f2.timestamp; 635 f5.timestamp = f2.timestamp;
636 636
637 f6.hasTimestamp = true; 637 f6.hasTimestamp = true;
638 f6.timestamp = f2.timestamp; 638 f6.timestamp = f2.timestamp;
639 639
640 float b[256]; 640 float b[nNote];
641 641
642 bool some_b_greater_zero = false; 642 bool some_b_greater_zero = false;
643 float sumb = 0; 643 float sumb = 0;
644 for (int i = 0; i < 256; i++) { 644 for (int i = 0; i < nNote; i++) {
645 // b[i] = m_dict[(256 * count + i) % (256 * 84)]; 645 // b[i] = m_dict[(nNote * count + i) % (nNote * 84)];
646 b[i] = f2.values[i]; 646 b[i] = f2.values[i];
647 sumb += b[i]; 647 sumb += b[i];
648 if (b[i] > 0) { 648 if (b[i] > 0) {
649 some_b_greater_zero = true; 649 some_b_greater_zero = true;
650 } 650 }
688 float rnorm; 688 float rnorm;
689 float w[84+1000]; 689 float w[84+1000];
690 float zz[84+1000]; 690 float zz[84+1000];
691 int indx[84+1000]; 691 int indx[84+1000];
692 int mode; 692 int mode;
693 int dictsize = 256*signifIndex.size(); 693 int dictsize = nNote*signifIndex.size();
694 // cerr << "dictsize is " << dictsize << "and values size" << f3.values.size()<< endl; 694 // cerr << "dictsize is " << dictsize << "and values size" << f3.values.size()<< endl;
695 float *curr_dict = new float[dictsize]; 695 float *curr_dict = new float[dictsize];
696 for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { 696 for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) {
697 for (unsigned iBin = 0; iBin < 256; iBin++) { 697 for (unsigned iBin = 0; iBin < nNote; iBin++) {
698 curr_dict[iNote * 256 + iBin] = 1.0 * m_dict[signifIndex[iNote] * 256 + iBin]; 698 curr_dict[iNote * nNote + iBin] = 1.0 * m_dict[signifIndex[iNote] * nNote + iBin];
699 } 699 }
700 } 700 }
701 nnls(curr_dict, nNote, nNote, signifIndex.size(), b, x, &rnorm, w, zz, indx, &mode); 701 nnls(curr_dict, nNote, nNote, signifIndex.size(), b, x, &rnorm, w, zz, indx, &mode);
702 delete [] curr_dict; 702 delete [] curr_dict;
703 for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { 703 for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) {