Mercurial > hg > nnls-chroma
comparison NNLSChroma.cpp @ 12:54f28d8ac098 matthiasm-plugin
consecutive chords with the same label are merged
author | matthiasm |
---|---|
date | Wed, 09 Jun 2010 03:33:36 +0000 |
parents | a02d56ac1464 |
children | 9ae90fa5fa74 |
comparison
equal
deleted
inserted
replaced
11:9a5d190828ac | 12:54f28d8ac098 |
---|---|
389 m_kernelNoteIndex(0), | 389 m_kernelNoteIndex(0), |
390 m_dict(0), | 390 m_dict(0), |
391 m_tuneLocal(false), | 391 m_tuneLocal(false), |
392 m_dictID(0), | 392 m_dictID(0), |
393 m_chorddict(0), | 393 m_chorddict(0), |
394 m_chordnames(0) | 394 m_chordnames(0), |
395 m_doNormalizeChroma(0) | |
395 { | 396 { |
396 if (debug_on) cerr << "--> NNLSChroma" << endl; | 397 if (debug_on) cerr << "--> NNLSChroma" << endl; |
397 | 398 |
398 // make the *note* dictionary matrix | 399 // make the *note* dictionary matrix |
399 m_dict = new float[nNote * 84]; | 400 m_dict = new float[nNote * 84]; |
560 // d2.minValue = 0.0; | 561 // d2.minValue = 0.0; |
561 // d2.maxValue = 1.0; | 562 // d2.maxValue = 1.0; |
562 // d2.defaultValue = 1.0; | 563 // d2.defaultValue = 1.0; |
563 // d2.isQuantized = false; | 564 // d2.isQuantized = false; |
564 // list.push_back(d2); | 565 // list.push_back(d2); |
566 ParameterDescriptor d4; | |
567 d4.identifier = "chromanormalize"; | |
568 d4.name = "chroma normalization"; | |
569 d4.description = "How shall the chroma vector be normalized?"; | |
570 d4.unit = ""; | |
571 d4.minValue = 0; | |
572 d4.maxValue = 1; | |
573 d4.defaultValue = 0; | |
574 d4.isQuantized = true; | |
575 d4.valueNames.push_back("no normalization"); | |
576 d4.valueNames.push_back("maximum normalization"); | |
577 d4.quantizeStep = 1.0; | |
578 list.push_back(d4); | |
565 | 579 |
566 return list; | 580 return list; |
567 } | 581 } |
568 | 582 |
569 float | 583 float |
586 } | 600 } |
587 } | 601 } |
588 if (identifier == "preset") { | 602 if (identifier == "preset") { |
589 return m_preset; | 603 return m_preset; |
590 } | 604 } |
605 if (identifier == "chromanormalize") { | |
606 return m_doNormalizeChroma; | |
607 } | |
591 return 0; | 608 return 0; |
592 | 609 |
593 } | 610 } |
594 | 611 |
595 void | 612 void |
624 m_tuneLocal = false; | 641 m_tuneLocal = false; |
625 m_paling = 0.7; | 642 m_paling = 0.7; |
626 m_dictID = 0.0; | 643 m_dictID = 0.0; |
627 } | 644 } |
628 } | 645 } |
646 if (identifier == "chromanormalize") { | |
647 m_doNormalizeChroma = value; | |
648 } | |
629 } | 649 } |
630 | 650 |
631 NNLSChroma::ProgramList | 651 NNLSChroma::ProgramList |
632 NNLSChroma::getPrograms() const | 652 NNLSChroma::getPrograms() const |
633 { | 653 { |
1178 basschroma[signifIndex[iNote] % 12] += x[iNote] * basswindow[signifIndex[iNote]]; | 1198 basschroma[signifIndex[iNote] % 12] += x[iNote] * basswindow[signifIndex[iNote]]; |
1179 } | 1199 } |
1180 } | 1200 } |
1181 } | 1201 } |
1182 | 1202 |
1183 f4.values = chroma; | 1203 |
1204 if (m_doNormalizeChroma > 0) { | |
1205 float chromamax = *max_element(chroma.begin(), chroma.end()); | |
1206 for (int i = 0; i < chroma.size(); i++) { | |
1207 chroma[i] /= chromamax; | |
1208 } | |
1209 } | |
1210 f4.values = chroma; | |
1184 f5.values = basschroma; | 1211 f5.values = basschroma; |
1185 chroma.insert(chroma.begin(), basschroma.begin(), basschroma.end()); // just stack the both chromas | 1212 chroma.insert(chroma.begin(), basschroma.begin(), basschroma.end()); // just stack the both chromas |
1186 f6.values = chroma; | 1213 f6.values = chroma; |
1187 | 1214 |
1188 // local chord estimation | 1215 // local chord estimation |
1322 cerr << "******* mode filter done *******" << endl; | 1349 cerr << "******* mode filter done *******" << endl; |
1323 | 1350 |
1324 | 1351 |
1325 // mode filter on chordSequence | 1352 // mode filter on chordSequence |
1326 count = 0; | 1353 count = 0; |
1327 int oldChordIndex = -1; | 1354 string oldChord = ""; |
1328 for (FeatureList::iterator it = fsOut[6].begin(); it != fsOut[6].end(); ++it) { | 1355 for (FeatureList::iterator it = fsOut[6].begin(); it != fsOut[6].end(); ++it) { |
1329 Feature f6 = *it; | 1356 Feature f6 = *it; |
1330 Feature f7; // chord estimate | 1357 Feature f7; // chord estimate |
1331 f7.hasTimestamp = true; | 1358 f7.hasTimestamp = true; |
1332 f7.timestamp = f6.timestamp; | 1359 f7.timestamp = f6.timestamp; |
1333 vector<int> chordCount = vector<int>(nChord,0); | 1360 vector<int> chordCount = vector<int>(nChord,0); |
1334 int maxChordCount = 0; | 1361 int maxChordCount = 0; |
1335 int maxChordIndex = nChord-1; | 1362 int maxChordIndex = nChord-1; |
1363 string maxChord; | |
1336 int startIndex = max(count - halfwindowlength/2,0); | 1364 int startIndex = max(count - halfwindowlength/2,0); |
1337 int endIndex = min(int(chordogram.size()), count + halfwindowlength/2); | 1365 int endIndex = min(int(chordogram.size()), count + halfwindowlength/2); |
1338 for (int i = startIndex; i < endIndex; i++) { | 1366 for (int i = startIndex; i < endIndex; i++) { |
1339 chordCount[chordSequence[i]]++; | 1367 chordCount[chordSequence[i]]++; |
1340 if (chordCount[chordSequence[i]] > maxChordCount) { | 1368 if (chordCount[chordSequence[i]] > maxChordCount) { |
1341 // cerr << "start index " << startIndex << endl; | 1369 // cerr << "start index " << startIndex << endl; |
1342 maxChordCount++; | 1370 maxChordCount++; |
1343 maxChordIndex = chordSequence[i]; | 1371 maxChordIndex = chordSequence[i]; |
1372 maxChord = m_chordnames[maxChordIndex]; | |
1344 } | 1373 } |
1345 } | 1374 } |
1346 // chordSequence[count] = maxChordIndex; | 1375 // chordSequence[count] = maxChordIndex; |
1347 // cerr << maxChordIndex << endl; | 1376 // cerr << maxChordIndex << endl; |
1348 if (oldChordIndex != maxChordIndex) { | 1377 if (oldChord != maxChord) { |
1349 oldChordIndex = maxChordIndex; | 1378 oldChord = maxChord; |
1350 | 1379 |
1351 // char buffer1 [50]; | 1380 // char buffer1 [50]; |
1352 // if (maxChordIndex < nChord - 1) { | 1381 // if (maxChordIndex < nChord - 1) { |
1353 // sprintf(buffer1, "%s%s", notenames[maxChordIndex % 12 + 12], chordtypes[maxChordIndex]); | 1382 // sprintf(buffer1, "%s%s", notenames[maxChordIndex % 12 + 12], chordtypes[maxChordIndex]); |
1354 // } else { | 1383 // } else { |