Mercurial > hg > silvet
comparison src/Silvet.cpp @ 189:3de7c871d9c8 noteagent
Fixes to mono feeder; use it for monophonic instruments
author | Chris Cannam |
---|---|
date | Thu, 29 May 2014 10:30:08 +0100 |
parents | 462b165c8c0f |
children | 28cbc7eaf415 |
comparison
equal
deleted
inserted
replaced
188:462b165c8c0f | 189:3de7c871d9c8 |
---|---|
18 | 18 |
19 #include <cq/CQSpectrogram.h> | 19 #include <cq/CQSpectrogram.h> |
20 | 20 |
21 #include "MedianFilter.h" | 21 #include "MedianFilter.h" |
22 #include "AgentFeederPoly.h" | 22 #include "AgentFeederPoly.h" |
23 #include "AgentFeederMono.h" | |
23 #include "NoteHypothesis.h" | 24 #include "NoteHypothesis.h" |
24 | 25 |
25 #include "constant-q-cpp/src/dsp/Resampler.h" | 26 #include "constant-q-cpp/src/dsp/Resampler.h" |
26 | 27 |
27 #include <vector> | 28 #include <vector> |
403 | 404 |
404 for (int i = 0; i < (int)m_postFilter.size(); ++i) { | 405 for (int i = 0; i < (int)m_postFilter.size(); ++i) { |
405 delete m_postFilter[i]; | 406 delete m_postFilter[i]; |
406 } | 407 } |
407 m_postFilter.clear(); | 408 m_postFilter.clear(); |
408 for (int i = 0; i < m_instruments[0].templateNoteCount; ++i) { | 409 for (int i = 0; i < m_instruments[m_instrument].templateNoteCount; ++i) { |
409 //!!! m_postFilter.push_back(new MedianFilter<double>(3)); | 410 //!!! m_postFilter.push_back(new MedianFilter<double>(3)); |
410 m_postFilter.push_back(new MedianFilter<double>(1));//!!! | 411 m_postFilter.push_back(new MedianFilter<double>(1));//!!! |
411 } | 412 } |
412 | 413 |
413 m_columnCountIn = 0; | 414 m_columnCountIn = 0; |
414 m_columnCountOut = 0; | 415 m_columnCountOut = 0; |
415 m_startTime = RealTime::zeroTime; | 416 m_startTime = RealTime::zeroTime; |
416 | 417 |
417 m_agentFeeder = new AgentFeederPoly<NoteHypothesis>(); | 418 if (m_instruments[m_instrument].maxPolyphony == 1) { |
419 m_agentFeeder = new AgentFeederMono<NoteHypothesis>(); | |
420 } else { | |
421 m_agentFeeder = new AgentFeederPoly<NoteHypothesis>(); | |
422 } | |
418 } | 423 } |
419 | 424 |
420 Silvet::FeatureSet | 425 Silvet::FeatureSet |
421 Silvet::process(const float *const *inputBuffers, Vamp::RealTime timestamp) | 426 Silvet::process(const float *const *inputBuffers, Vamp::RealTime timestamp) |
422 { | 427 { |
694 Vamp::Plugin::FeatureList | 699 Vamp::Plugin::FeatureList |
695 Silvet::obtainNotes() | 700 Silvet::obtainNotes() |
696 { | 701 { |
697 FeatureList noteFeatures; | 702 FeatureList noteFeatures; |
698 | 703 |
699 typedef AgentFeederPoly<NoteHypothesis> NoteFeeder; | 704 std::set<NoteHypothesis> hh; |
700 | 705 |
701 NoteFeeder *feeder = dynamic_cast<NoteFeeder *>(m_agentFeeder); | 706 AgentFeederPoly<NoteHypothesis> *polyFeeder = |
702 | 707 dynamic_cast<AgentFeederPoly<NoteHypothesis> *>(m_agentFeeder); |
703 if (!feeder) { | 708 |
704 cerr << "INTERNAL ERROR: Feeder is not a poly-note-hypothesis-feeder!" | 709 AgentFeederMono<NoteHypothesis> *monoFeeder = |
705 << endl; | 710 dynamic_cast<AgentFeederMono<NoteHypothesis> *>(m_agentFeeder); |
711 | |
712 if (polyFeeder) { | |
713 | |
714 hh = polyFeeder->retrieveAcceptedHypotheses(); | |
715 | |
716 } else if (monoFeeder) { | |
717 | |
718 hh = monoFeeder->retrieveAcceptedHypotheses(); | |
719 | |
720 } else { | |
721 | |
722 cerr << "INTERNAL ERROR: Feeder is neither poly- nor " | |
723 << "mono-note-hypothesis-feeder!" << endl; | |
706 return noteFeatures; | 724 return noteFeatures; |
707 } | 725 } |
708 | 726 |
709 std::set<NoteHypothesis> hh = feeder->retrieveAcceptedHypotheses(); | |
710 | |
711 //!!! inefficient | |
712 for (std::set<NoteHypothesis>::const_iterator hi = hh.begin(); | 727 for (std::set<NoteHypothesis>::const_iterator hi = hh.begin(); |
713 hi != hh.end(); ++hi) { | 728 hi != hh.end(); ++hi) { |
714 | 729 |
715 NoteHypothesis h(*hi); | 730 NoteHypothesis h(*hi); |
716 | 731 |