Mercurial > hg > silvet
changeset 188:462b165c8c0f noteagent
Emit "MIDI-compatible" frequencies only, unless in fine tuning mode
author | Chris Cannam |
---|---|
date | Thu, 29 May 2014 09:21:15 +0100 |
parents | 1697457458b7 |
children | 3de7c871d9c8 |
files | src/AgentFeederPoly.h src/NoteHypothesis.cpp src/Silvet.cpp src/Silvet.h |
diffstat | 4 files changed, 22 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/AgentFeederPoly.h Wed May 28 15:16:00 2014 +0100 +++ b/src/AgentFeederPoly.h Thu May 29 09:21:15 2014 +0100 @@ -22,7 +22,7 @@ #include <cassert> #include <stdexcept> -#define DEBUG_FEEDER 1 +//#define DEBUG_FEEDER 1 /** * Take a series of observations or estimates (one at a time) and feed
--- a/src/NoteHypothesis.cpp Wed May 28 15:16:00 2014 +0100 +++ b/src/NoteHypothesis.cpp Thu May 29 09:21:15 2014 +0100 @@ -28,7 +28,7 @@ using std::cerr; using std::endl; -#define DEBUG_NOTE_HYPOTHESIS 1 +//#define DEBUG_NOTE_HYPOTHESIS 1 NoteHypothesis::NoteHypothesis() { @@ -119,6 +119,7 @@ return ((int)m_pending.size() > lengthRequired); } +#ifdef DEBUG_NOTE_HYPOTHESIS static void printState(NoteHypothesis::State s) { switch (s) { @@ -129,6 +130,7 @@ case NoteHypothesis::Expired: cerr << "Expired"; break; } } +#endif bool NoteHypothesis::accept(Observation s)
--- a/src/Silvet.cpp Wed May 28 15:16:00 2014 +0100 +++ b/src/Silvet.cpp Thu May 29 09:21:15 2014 +0100 @@ -334,6 +334,15 @@ return float(27.5 * pow(2.0, (note + pshift) / 12.0)); } +float +Silvet::roundToMidiFrequency(float freq) const +{ + // n is our note number, not actually MIDI note number as we have + // a different origin + float n = 12.0 * (log(freq / 27.5) / log(2.0)); + return 27.5 * pow(2.0, round(n) / 12.0); +} + bool Silvet::initialise(size_t channels, size_t stepSize, size_t blockSize) { @@ -397,7 +406,8 @@ } m_postFilter.clear(); for (int i = 0; i < m_instruments[0].templateNoteCount; ++i) { - m_postFilter.push_back(new MedianFilter<double>(3)); +//!!! m_postFilter.push_back(new MedianFilter<double>(3)); + m_postFilter.push_back(new MedianFilter<double>(1));//!!! } m_columnCountIn = 0; @@ -709,13 +719,18 @@ int velocity = n.confidence * 127; if (velocity > 127) velocity = 127; + float freq = n.freq; + if (!m_fineTuning) { + freq = roundToMidiFrequency(freq); + } + Feature f; f.hasTimestamp = true; f.hasDuration = true; f.timestamp = n.time; f.duration = n.duration; f.values.clear(); - f.values.push_back(n.freq); + f.values.push_back(freq); f.values.push_back(velocity); // f.label = noteName(note, partShift, shiftCount); noteFeatures.push_back(f);
--- a/src/Silvet.h Wed May 28 15:16:00 2014 +0100 +++ b/src/Silvet.h Thu May 29 09:21:15 2014 +0100 @@ -102,6 +102,7 @@ string noteName(int n, int shift, int shiftCount) const; float noteFrequency(int n, int shift, int shiftCount) const; + float roundToMidiFrequency(float f) const; int m_blockSize; int m_columnCountIn;