Mercurial > hg > nnls-chroma
comparison NNLSBase.cpp @ 122:21181297da99 monophonicness
replacing unsigned/size_t iterators by int and casting others to int
author | matthiasm |
---|---|
date | Fri, 15 Apr 2011 11:31:37 +0000 |
parents | 7a8956e903e1 |
children | b547e7238bf5 |
comparison
equal
deleted
inserted
replaced
121:072327bbb1a2 | 122:21181297da99 |
---|---|
24 #include <fstream> | 24 #include <fstream> |
25 #include <cmath> | 25 #include <cmath> |
26 | 26 |
27 #include <algorithm> | 27 #include <algorithm> |
28 | 28 |
29 const bool debug_on = false; | 29 static bool debug_on = false; |
30 | 30 |
31 NNLSBase::NNLSBase(float inputSampleRate) : | 31 NNLSBase::NNLSBase(float inputSampleRate) : |
32 Plugin(inputSampleRate), | 32 Plugin(inputSampleRate), |
33 m_frameCount(0), | 33 m_frameCount(0), |
34 m_logSpectrum(0), | 34 m_logSpectrum(0), |
56 cosvalues(0) | 56 cosvalues(0) |
57 { | 57 { |
58 if (debug_on) cerr << "--> NNLSBase" << endl; | 58 if (debug_on) cerr << "--> NNLSBase" << endl; |
59 // make the *note* dictionary matrix | 59 // make the *note* dictionary matrix |
60 m_dict = new float[nNote * 84]; | 60 m_dict = new float[nNote * 84]; |
61 for (unsigned i = 0; i < nNote * 84; ++i) m_dict[i] = 0.0; | 61 for (int i = 0; i < nNote * 84; ++i) m_dict[i] = 0.0; |
62 } | 62 } |
63 | 63 |
64 | 64 |
65 NNLSBase::~NNLSBase() | 65 NNLSBase::~NNLSBase() |
66 { | 66 { |
402 m_kernelValue.clear(); | 402 m_kernelValue.clear(); |
403 m_kernelFftIndex.clear(); | 403 m_kernelFftIndex.clear(); |
404 m_kernelNoteIndex.clear(); | 404 m_kernelNoteIndex.clear(); |
405 int countNonzero = 0; | 405 int countNonzero = 0; |
406 for (int iNote = 0; iNote < nNote; ++iNote) { // I don't know if this is wise: manually making a sparse matrix | 406 for (int iNote = 0; iNote < nNote; ++iNote) { // I don't know if this is wise: manually making a sparse matrix |
407 for (size_t iFFT = 0; iFFT < blockSize/2; ++iFFT) { | 407 for (int iFFT = 0; iFFT < static_cast<int>(blockSize/2); ++iFFT) { |
408 if (tempkernel[iFFT + blockSize/2 * iNote] > 0) { | 408 if (tempkernel[iFFT + blockSize/2 * iNote] > 0) { |
409 m_kernelValue.push_back(tempkernel[iFFT + blockSize/2 * iNote]); | 409 m_kernelValue.push_back(tempkernel[iFFT + blockSize/2 * iNote]); |
410 if (tempkernel[iFFT + blockSize/2 * iNote] > 0) { | 410 if (tempkernel[iFFT + blockSize/2 * iNote] > 0) { |
411 countNonzero++; | 411 countNonzero++; |
412 } | 412 } |
453 | 453 |
454 const float *fbuf = inputBuffers[0]; | 454 const float *fbuf = inputBuffers[0]; |
455 float energysum = 0; | 455 float energysum = 0; |
456 // make magnitude | 456 // make magnitude |
457 float maxmag = -10000; | 457 float maxmag = -10000; |
458 for (size_t iBin = 0; iBin < m_blockSize/2; iBin++) { | 458 for (int iBin = 0; iBin < static_cast<int>(m_blockSize/2); iBin++) { |
459 magnitude[iBin] = sqrt(fbuf[2 * iBin] * fbuf[2 * iBin] + | 459 magnitude[iBin] = sqrt(fbuf[2 * iBin] * fbuf[2 * iBin] + |
460 fbuf[2 * iBin + 1] * fbuf[2 * iBin + 1]); | 460 fbuf[2 * iBin + 1] * fbuf[2 * iBin + 1]); |
461 if (magnitude[iBin]>m_blockSize*1.0) magnitude[iBin] = m_blockSize; // a valid audio signal (between -1 and 1) should not be limited here. | 461 if (magnitude[iBin]>m_blockSize*1.0) magnitude[iBin] = m_blockSize; // a valid audio signal (between -1 and 1) should not be limited here. |
462 if (maxmag < magnitude[iBin]) maxmag = magnitude[iBin]; | 462 if (maxmag < magnitude[iBin]) maxmag = magnitude[iBin]; |
463 if (m_rollon > 0) { | 463 if (m_rollon > 0) { |
465 } | 465 } |
466 } | 466 } |
467 | 467 |
468 float cumenergy = 0; | 468 float cumenergy = 0; |
469 if (m_rollon > 0) { | 469 if (m_rollon > 0) { |
470 for (size_t iBin = 2; iBin < m_blockSize/2; iBin++) { | 470 for (int iBin = 2; iBin < static_cast<int>(m_blockSize/2); iBin++) { |
471 cumenergy += pow(magnitude[iBin],2); | 471 cumenergy += pow(magnitude[iBin],2); |
472 if (cumenergy < energysum * m_rollon / 100) magnitude[iBin-2] = 0; | 472 if (cumenergy < energysum * m_rollon / 100) magnitude[iBin-2] = 0; |
473 else break; | 473 else break; |
474 } | 474 } |
475 } | 475 } |
476 | 476 |
477 if (maxmag < 2) { | 477 if (maxmag < 2) { |
478 // cerr << "timestamp " << timestamp << ": very low magnitude, setting magnitude to all zeros" << endl; | 478 // cerr << "timestamp " << timestamp << ": very low magnitude, setting magnitude to all zeros" << endl; |
479 for (size_t iBin = 0; iBin < m_blockSize/2; iBin++) { | 479 for (int iBin = 0; iBin < static_cast<int>(m_blockSize/2); iBin++) { |
480 magnitude[iBin] = 0; | 480 magnitude[iBin] = 0; |
481 } | 481 } |
482 } | 482 } |
483 | 483 |
484 // note magnitude mapping using pre-calculated matrix | 484 // note magnitude mapping using pre-calculated matrix |