Mercurial > hg > nnls-chroma
diff NNLSChroma.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 | f50f701df33e 026a5c0ee2c2 |
line wrap: on
line diff
--- 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);