Mercurial > hg > nnls-chroma
changeset 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 | d52884de7d79 |
files | Chordino.cpp NNLSBase.cpp NNLSChroma.cpp chromamethods.cpp chromamethods.h |
diffstat | 5 files changed, 34 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/Chordino.cpp Wed Nov 10 22:52:46 2010 +0900 +++ b/Chordino.cpp Thu Nov 11 10:27:58 2010 +0900 @@ -298,11 +298,11 @@ currentTunedSpec.values.push_back(0.0); currentTunedSpec.values.push_back(0.0); currentTunedSpec.values.push_back(0.0); // upper edge vector<float> runningmean = SpecialConvolution(currentTunedSpec.values,hw); vector<float> runningstd; - for (int i = 0; i < 256; i++) { // first step: squared values into vector (variance) + for (int i = 0; i < nNote; i++) { // first step: squared values into vector (variance) runningstd.push_back((currentTunedSpec.values[i] - runningmean[i]) * (currentTunedSpec.values[i] - runningmean[i])); } runningstd = SpecialConvolution(runningstd,hw); // second step convolve - for (int i = 0; i < 256; i++) { + for (int i = 0; i < nNote; i++) { runningstd[i] = sqrt(runningstd[i]); // square root to finally have running std if (runningstd[i] > 0) { // currentTunedSpec.values[i] = (currentTunedSpec.values[i] / runningmean[i]) > thresh ? @@ -348,12 +348,12 @@ currentChromas.hasTimestamp = true; currentChromas.timestamp = currentTunedSpec.timestamp; - float b[256]; + float b[nNote]; bool some_b_greater_zero = false; float sumb = 0; - for (int i = 0; i < 256; i++) { - // b[i] = m_dict[(256 * count + i) % (256 * 84)]; + for (int i = 0; i < nNote; i++) { + // b[i] = m_dict[(nNote * count + i) % (nNote * 84)]; b[i] = currentTunedSpec.values[i]; sumb += b[i]; if (b[i] > 0) { @@ -399,11 +399,11 @@ float zz[84+1000]; int indx[84+1000]; int mode; - int dictsize = 256*signifIndex.size(); + int dictsize = nNote*signifIndex.size(); float *curr_dict = new float[dictsize]; for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { - for (unsigned iBin = 0; iBin < 256; iBin++) { - curr_dict[iNote * 256 + iBin] = 1.0 * m_dict[signifIndex[iNote] * 256 + iBin]; + for (unsigned iBin = 0; iBin < nNote; iBin++) { + curr_dict[iNote * nNote + iBin] = 1.0 * m_dict[signifIndex[iNote] * nNote + iBin]; } } nnls(curr_dict, nNote, nNote, signifIndex.size(), b, x, &rnorm, w, zz, indx, &mode);
--- a/NNLSBase.cpp Wed Nov 10 22:52:46 2010 +0900 +++ b/NNLSBase.cpp Thu Nov 11 10:27:58 2010 +0900 @@ -358,14 +358,14 @@ hw.push_back(0.54 - 0.46 * cos((2*M_PI*i)/(hamwinlength-1))); hamwinsum += 0.54 - 0.46 * cos((2*M_PI*i)/(hamwinlength-1)); } - for (int i = 0; i < hamwinlength; ++i) hw[i] = round(hw[i] / hamwinsum * 10000)*1.0/10000; + for (int i = 0; i < hamwinlength; ++i) hw[i] = hw[i] / hamwinsum; if (channels < getMinChannelCount() || channels > getMaxChannelCount()) return false; m_blockSize = blockSize; m_stepSize = stepSize; m_frameCount = 0; - int tempn = 256 * m_blockSize/2; + int tempn = nNote * m_blockSize/2; // cerr << "length of tempkernel : " << tempn << endl; float *tempkernel; @@ -577,11 +577,11 @@ f2.values.push_back(0.0); f2.values.push_back(0.0); f2.values.push_back(0.0); // upper edge vector<float> runningmean = SpecialConvolution(f2.values,hw); vector<float> runningstd; - for (int i = 0; i < 256; i++) { // first step: squared values into vector (variance) + for (int i = 0; i < nNote; i++) { // first step: squared values into vector (variance) runningstd.push_back((f2.values[i] - runningmean[i]) * (f2.values[i] - runningmean[i])); } runningstd = SpecialConvolution(runningstd,hw); // second step convolve - for (int i = 0; i < 256; i++) { + for (int i = 0; i < nNote; i++) { runningstd[i] = sqrt(runningstd[i]); // square root to finally have running std if (runningstd[i] > 0) { // f2.values[i] = (f2.values[i] / runningmean[i]) > thresh ? @@ -637,12 +637,12 @@ f6.hasTimestamp = true; f6.timestamp = f2.timestamp; - float b[256]; + float b[nNote]; bool some_b_greater_zero = false; float sumb = 0; - for (int i = 0; i < 256; i++) { - // b[i] = m_dict[(256 * count + i) % (256 * 84)]; + for (int i = 0; i < nNote; i++) { + // b[i] = m_dict[(nNote * count + i) % (nNote * 84)]; b[i] = f2.values[i]; sumb += b[i]; if (b[i] > 0) { @@ -690,12 +690,12 @@ float zz[84+1000]; int indx[84+1000]; int mode; - int dictsize = 256*signifIndex.size(); + int dictsize = nNote*signifIndex.size(); // cerr << "dictsize is " << dictsize << "and values size" << f3.values.size()<< endl; float *curr_dict = new float[dictsize]; for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { - for (unsigned iBin = 0; iBin < 256; iBin++) { - curr_dict[iNote * 256 + iBin] = 1.0 * m_dict[signifIndex[iNote] * 256 + iBin]; + for (unsigned iBin = 0; iBin < nNote; iBin++) { + curr_dict[iNote * nNote + iBin] = 1.0 * m_dict[signifIndex[iNote] * nNote + iBin]; } } nnls(curr_dict, nNote, nNote, signifIndex.size(), b, x, &rnorm, w, zz, indx, &mode);
--- a/NNLSChroma.cpp Wed Nov 10 22:52:46 2010 +0900 +++ b/NNLSChroma.cpp Thu Nov 11 10:27:58 2010 +0900 @@ -99,7 +99,7 @@ d2.description = "A Log-Frequency Spectrum (constant Q) that is obtained by cosine filter mapping, then its tuned using the estimated tuning frequency."; d2.unit = ""; d2.hasFixedBinCount = true; - d2.binCount = 256; + d2.binCount = nNote; d2.hasKnownExtents = false; d2.isQuantized = false; d2.sampleType = OutputDescriptor::FixedSampleRate; @@ -243,6 +243,9 @@ float thresh = pow(10,dbThreshold/20); // cerr << "tune local ? " << m_tuneLocal << endl; int count = 0; + + cerr << nNote; + cerr << endl << "-------------------------------------"<< endl; for (FeatureList::iterator i = m_logSpectrum.begin(); i != m_logSpectrum.end(); ++i) { Feature f1 = *i; @@ -264,13 +267,14 @@ } f2.values.push_back(0.0); f2.values.push_back(0.0); f2.values.push_back(0.0); // upper edge + vector<float> runningmean = SpecialConvolution(f2.values,hw); vector<float> runningstd; - for (int i = 0; i < 256; i++) { // first step: squared values into vector (variance) + for (int i = 0; i < nNote; i++) { // first step: squared values into vector (variance) runningstd.push_back((f2.values[i] - runningmean[i]) * (f2.values[i] - runningmean[i])); } runningstd = SpecialConvolution(runningstd,hw); // second step convolve - for (int i = 0; i < 256; i++) { + for (int i = 0; i < nNote; i++) { runningstd[i] = sqrt(runningstd[i]); // square root to finally have running std if (runningstd[i] > 0) { // f2.values[i] = (f2.values[i] / runningmean[i]) > thresh ? @@ -323,12 +327,12 @@ f6.hasTimestamp = true; f6.timestamp = f2.timestamp; - float b[256]; + float b[nNote]; bool some_b_greater_zero = false; float sumb = 0; - for (int i = 0; i < 256; i++) { - // b[i] = m_dict[(256 * count + i) % (256 * 84)]; + for (int i = 0; i < nNote; i++) { + // b[i] = m_dict[(nNote * count + i) % (nNote * 84)]; b[i] = f2.values[i]; sumb += b[i]; if (b[i] > 0) { @@ -376,12 +380,12 @@ float zz[84+1000]; int indx[84+1000]; int mode; - int dictsize = 256*signifIndex.size(); + int dictsize = nNote*signifIndex.size(); // cerr << "dictsize is " << dictsize << "and values size" << f3.values.size()<< endl; float *curr_dict = new float[dictsize]; for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { - for (unsigned iBin = 0; iBin < 256; iBin++) { - curr_dict[iNote * 256 + iBin] = 1.0 * m_dict[signifIndex[iNote] * 256 + iBin]; + for (unsigned iBin = 0; iBin < nNote; iBin++) { + curr_dict[iNote * nNote + iBin] = 1.0 * m_dict[signifIndex[iNote] * nNote + iBin]; } } nnls(curr_dict, nNote, nNote, signifIndex.size(), b, x, &rnorm, w, zz, indx, &mode);
--- a/chromamethods.cpp Wed Nov 10 22:52:46 2010 +0900 +++ b/chromamethods.cpp Thu Nov 11 10:27:58 2010 +0900 @@ -50,7 +50,7 @@ int lenConvolvee = convolvee.size(); int lenKernel = kernel.size(); - vector<float> Z(256,0); + vector<float> Z(nNote,0); assert(lenKernel % 2 != 0); // no exception handling !!! for (n = lenKernel - 1; n < lenConvolvee; n++) { @@ -206,7 +206,7 @@ // cerr << "curramp" << curr_amp << endl; for (unsigned iNote = 0; iNote < nNote; ++iNote) { if (abs(iNote+1.0-floatbin)<2) { - dm[iNote + 256 * iOut] += cospuls(iNote+1.0, floatbin, binspersemitone + 0.0) * curr_amp; + dm[iNote + nNote * iOut] += cospuls(iNote+1.0, floatbin, binspersemitone + 0.0) * curr_amp; // dm[iNote + nNote * iOut] += 1 * curr_amp; } }
--- a/chromamethods.h Wed Nov 10 22:52:46 2010 +0900 +++ b/chromamethods.h Thu Nov 11 10:27:58 2010 +0900 @@ -24,7 +24,7 @@ const int nBPS = 3; // bins per semitone const int nOctave = 7; -const int nNote = nOctave * 12 * nBPS + 2 * (nBPS/2); // a core over all octaves, plus some overlap at top and bottom +const int nNote = nOctave * 12 * nBPS + 2 * (nBPS/2+1); // a core over all octaves, plus some overlap at top and bottom extern std::vector<float> SpecialConvolution(std::vector<float> convolvee, std::vector<float> kernel); extern void dictionaryMatrix(float* dm, float s_param);