comparison src/Silvet.cpp @ 45:e92376d450b0 preshift

Get notes out using pre-shifted templates (not working properly)
author Chris Cannam
date Mon, 07 Apr 2014 13:01:08 +0100
parents b49597c93132
children ccb1a437a828
comparison
equal deleted inserted replaced
44:eec530c4300d 45:e92376d450b0
32 32
33 static int processingSampleRate = 44100; 33 static int processingSampleRate = 44100;
34 static int processingBPO = 60; 34 static int processingBPO = 60;
35 static int processingHeight = 545; 35 static int processingHeight = 545;
36 static int processingNotes = 88; 36 static int processingNotes = 88;
37 static int processingShifts = 5;
38 static int processingPitches = processingNotes * processingShifts;
37 39
38 Silvet::Silvet(float inputSampleRate) : 40 Silvet::Silvet(float inputSampleRate) :
39 Plugin(inputSampleRate), 41 Plugin(inputSampleRate),
40 m_resampler(0), 42 m_resampler(0),
41 m_cq(0) 43 m_cq(0)
211 d.identifier = "pitchdistribution"; 213 d.identifier = "pitchdistribution";
212 d.name = "Pitch distribution"; 214 d.name = "Pitch distribution";
213 d.description = "The estimated pitch contribution matrix"; 215 d.description = "The estimated pitch contribution matrix";
214 d.unit = ""; 216 d.unit = "";
215 d.hasFixedBinCount = true; 217 d.hasFixedBinCount = true;
216 d.binCount = processingNotes; 218 d.binCount = processingPitches;
217 d.binNames.clear(); 219 d.binNames.clear();
218 for (int i = 0; i < processingNotes; ++i) { 220 for (int i = 0; i < processingPitches; ++i) {
219 d.binNames.push_back(noteName(i)); 221 d.binNames.push_back(noteName(i));
220 } 222 }
221 d.hasKnownExtents = false; 223 d.hasKnownExtents = false;
222 d.isQuantized = false; 224 d.isQuantized = false;
223 d.sampleType = OutputDescriptor::FixedSampleRate; 225 d.sampleType = OutputDescriptor::FixedSampleRate;
371 em.iterate(filtered[i]); 373 em.iterate(filtered[i]);
372 } 374 }
373 375
374 vector<double> pitches = em.getPitchDistribution(); 376 vector<double> pitches = em.getPitchDistribution();
375 377
376 for (int j = 0; j < processingNotes; ++j) { 378 for (int j = 0; j < processingPitches; ++j) {
377 pitches[j] *= sum; 379 pitches[j] *= sum;
378 } 380 }
379 381
380 Feature f; 382 Feature f;
381 for (int j = 0; j < processingNotes; ++j) { 383 for (int j = 0; j < processingPitches; ++j) {
382 f.values.push_back(float(pitches[j])); 384 f.values.push_back(float(pitches[j]));
383 } 385 }
384 fs[m_pitchOutputNo].push_back(f); 386 fs[m_pitchOutputNo].push_back(f);
385 387
386 FeatureList noteFeatures = postProcess(pitches); 388 FeatureList noteFeatures = postProcess(pitches);
389
387 for (FeatureList::const_iterator fi = noteFeatures.begin(); 390 for (FeatureList::const_iterator fi = noteFeatures.begin();
388 fi != noteFeatures.end(); ++fi) { 391 fi != noteFeatures.end(); ++fi) {
389 fs[m_notesOutputNo].push_back(*fi); 392 fs[m_notesOutputNo].push_back(*fi);
390 } 393 }
391 } 394 }
465 Silvet::postProcess(const vector<double> &pitches) 468 Silvet::postProcess(const vector<double> &pitches)
466 { 469 {
467 vector<double> filtered; 470 vector<double> filtered;
468 471
469 for (int j = 0; j < processingNotes; ++j) { 472 for (int j = 0; j < processingNotes; ++j) {
470 m_postFilter[j]->push(pitches[j]); 473 double noteMax = 0.0;
474 for (int s = 0; s < processingShifts; ++s) {
475 double val = pitches[j * processingShifts + s];
476 if (val > noteMax) noteMax = val;
477 }
478 m_postFilter[j]->push(noteMax);
471 filtered.push_back(m_postFilter[j]->get()); 479 filtered.push_back(m_postFilter[j]->get());
472 } 480 }
473 481
474 // Threshold for level and reduce number of candidate pitches 482 // Threshold for level and reduce number of candidate pitches
475 483
483 strengths.insert(ValueIndexMap::value_type(filtered[j], j)); 491 strengths.insert(ValueIndexMap::value_type(filtered[j], j));
484 } 492 }
485 493
486 set<int> active; 494 set<int> active;
487 ValueIndexMap::const_iterator si = strengths.end(); 495 ValueIndexMap::const_iterator si = strengths.end();
488 for (int j = 0; j < polyphony; ++j) { 496 while (int(active.size()) < polyphony) {
489 --si; 497 --si;
490 if (si->first < threshold) break; 498 if (si->first < threshold) break;
491 cerr << si->second << " : " << si->first << endl; 499 cerr << si->second << " : " << si->first << endl;
492 active.insert(si->second); 500 active.insert(si->second);
501 if (si == strengths.begin()) break;
493 } 502 }
494 503
495 // Minimum duration pruning, and conversion to notes. We can only 504 // Minimum duration pruning, and conversion to notes. We can only
496 // report notes that have just ended (i.e. that are absent in the 505 // report notes that have just ended (i.e. that are absent in the
497 // latest active set but present in the last set in the piano 506 // latest active set but present in the last set in the piano