Mercurial > hg > nnls-chroma
comparison Chordino.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 |
---|---|
296 } | 296 } |
297 | 297 |
298 currentTunedSpec.values.push_back(0.0); currentTunedSpec.values.push_back(0.0); currentTunedSpec.values.push_back(0.0); // upper edge | 298 currentTunedSpec.values.push_back(0.0); currentTunedSpec.values.push_back(0.0); currentTunedSpec.values.push_back(0.0); // upper edge |
299 vector<float> runningmean = SpecialConvolution(currentTunedSpec.values,hw); | 299 vector<float> runningmean = SpecialConvolution(currentTunedSpec.values,hw); |
300 vector<float> runningstd; | 300 vector<float> runningstd; |
301 for (int i = 0; i < 256; i++) { // first step: squared values into vector (variance) | 301 for (int i = 0; i < nNote; i++) { // first step: squared values into vector (variance) |
302 runningstd.push_back((currentTunedSpec.values[i] - runningmean[i]) * (currentTunedSpec.values[i] - runningmean[i])); | 302 runningstd.push_back((currentTunedSpec.values[i] - runningmean[i]) * (currentTunedSpec.values[i] - runningmean[i])); |
303 } | 303 } |
304 runningstd = SpecialConvolution(runningstd,hw); // second step convolve | 304 runningstd = SpecialConvolution(runningstd,hw); // second step convolve |
305 for (int i = 0; i < 256; i++) { | 305 for (int i = 0; i < nNote; i++) { |
306 runningstd[i] = sqrt(runningstd[i]); // square root to finally have running std | 306 runningstd[i] = sqrt(runningstd[i]); // square root to finally have running std |
307 if (runningstd[i] > 0) { | 307 if (runningstd[i] > 0) { |
308 // currentTunedSpec.values[i] = (currentTunedSpec.values[i] / runningmean[i]) > thresh ? | 308 // currentTunedSpec.values[i] = (currentTunedSpec.values[i] / runningmean[i]) > thresh ? |
309 // (currentTunedSpec.values[i] - runningmean[i]) / pow(runningstd[i],m_whitening) : 0; | 309 // (currentTunedSpec.values[i] - runningmean[i]) / pow(runningstd[i],m_whitening) : 0; |
310 currentTunedSpec.values[i] = (currentTunedSpec.values[i] - runningmean[i]) > 0 ? | 310 currentTunedSpec.values[i] = (currentTunedSpec.values[i] - runningmean[i]) > 0 ? |
346 Feature currentChromas; // treble and bass chromagram | 346 Feature currentChromas; // treble and bass chromagram |
347 | 347 |
348 currentChromas.hasTimestamp = true; | 348 currentChromas.hasTimestamp = true; |
349 currentChromas.timestamp = currentTunedSpec.timestamp; | 349 currentChromas.timestamp = currentTunedSpec.timestamp; |
350 | 350 |
351 float b[256]; | 351 float b[nNote]; |
352 | 352 |
353 bool some_b_greater_zero = false; | 353 bool some_b_greater_zero = false; |
354 float sumb = 0; | 354 float sumb = 0; |
355 for (int i = 0; i < 256; i++) { | 355 for (int i = 0; i < nNote; i++) { |
356 // b[i] = m_dict[(256 * count + i) % (256 * 84)]; | 356 // b[i] = m_dict[(nNote * count + i) % (nNote * 84)]; |
357 b[i] = currentTunedSpec.values[i]; | 357 b[i] = currentTunedSpec.values[i]; |
358 sumb += b[i]; | 358 sumb += b[i]; |
359 if (b[i] > 0) { | 359 if (b[i] > 0) { |
360 some_b_greater_zero = true; | 360 some_b_greater_zero = true; |
361 } | 361 } |
397 float rnorm; | 397 float rnorm; |
398 float w[84+1000]; | 398 float w[84+1000]; |
399 float zz[84+1000]; | 399 float zz[84+1000]; |
400 int indx[84+1000]; | 400 int indx[84+1000]; |
401 int mode; | 401 int mode; |
402 int dictsize = 256*signifIndex.size(); | 402 int dictsize = nNote*signifIndex.size(); |
403 float *curr_dict = new float[dictsize]; | 403 float *curr_dict = new float[dictsize]; |
404 for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { | 404 for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { |
405 for (unsigned iBin = 0; iBin < 256; iBin++) { | 405 for (unsigned iBin = 0; iBin < nNote; iBin++) { |
406 curr_dict[iNote * 256 + iBin] = 1.0 * m_dict[signifIndex[iNote] * 256 + iBin]; | 406 curr_dict[iNote * nNote + iBin] = 1.0 * m_dict[signifIndex[iNote] * nNote + iBin]; |
407 } | 407 } |
408 } | 408 } |
409 nnls(curr_dict, nNote, nNote, signifIndex.size(), b, x, &rnorm, w, zz, indx, &mode); | 409 nnls(curr_dict, nNote, nNote, signifIndex.size(), b, x, &rnorm, w, zz, indx, &mode); |
410 delete [] curr_dict; | 410 delete [] curr_dict; |
411 for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { | 411 for (unsigned iNote = 0; iNote < signifIndex.size(); ++iNote) { |