Mercurial > hg > silvet
comparison src/Silvet.cpp @ 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 |
comparison
equal
deleted
inserted
replaced
187:1697457458b7 | 188:462b165c8c0f |
---|---|
332 } | 332 } |
333 | 333 |
334 return float(27.5 * pow(2.0, (note + pshift) / 12.0)); | 334 return float(27.5 * pow(2.0, (note + pshift) / 12.0)); |
335 } | 335 } |
336 | 336 |
337 float | |
338 Silvet::roundToMidiFrequency(float freq) const | |
339 { | |
340 // n is our note number, not actually MIDI note number as we have | |
341 // a different origin | |
342 float n = 12.0 * (log(freq / 27.5) / log(2.0)); | |
343 return 27.5 * pow(2.0, round(n) / 12.0); | |
344 } | |
345 | |
337 bool | 346 bool |
338 Silvet::initialise(size_t channels, size_t stepSize, size_t blockSize) | 347 Silvet::initialise(size_t channels, size_t stepSize, size_t blockSize) |
339 { | 348 { |
340 if (channels < getMinChannelCount() || | 349 if (channels < getMinChannelCount() || |
341 channels > getMaxChannelCount()) return false; | 350 channels > getMaxChannelCount()) return false; |
395 for (int i = 0; i < (int)m_postFilter.size(); ++i) { | 404 for (int i = 0; i < (int)m_postFilter.size(); ++i) { |
396 delete m_postFilter[i]; | 405 delete m_postFilter[i]; |
397 } | 406 } |
398 m_postFilter.clear(); | 407 m_postFilter.clear(); |
399 for (int i = 0; i < m_instruments[0].templateNoteCount; ++i) { | 408 for (int i = 0; i < m_instruments[0].templateNoteCount; ++i) { |
400 m_postFilter.push_back(new MedianFilter<double>(3)); | 409 //!!! m_postFilter.push_back(new MedianFilter<double>(3)); |
410 m_postFilter.push_back(new MedianFilter<double>(1));//!!! | |
401 } | 411 } |
402 | 412 |
403 m_columnCountIn = 0; | 413 m_columnCountIn = 0; |
404 m_columnCountOut = 0; | 414 m_columnCountOut = 0; |
405 m_startTime = RealTime::zeroTime; | 415 m_startTime = RealTime::zeroTime; |
707 NoteHypothesis::Note n = h.getAveragedNote(); | 717 NoteHypothesis::Note n = h.getAveragedNote(); |
708 | 718 |
709 int velocity = n.confidence * 127; | 719 int velocity = n.confidence * 127; |
710 if (velocity > 127) velocity = 127; | 720 if (velocity > 127) velocity = 127; |
711 | 721 |
722 float freq = n.freq; | |
723 if (!m_fineTuning) { | |
724 freq = roundToMidiFrequency(freq); | |
725 } | |
726 | |
712 Feature f; | 727 Feature f; |
713 f.hasTimestamp = true; | 728 f.hasTimestamp = true; |
714 f.hasDuration = true; | 729 f.hasDuration = true; |
715 f.timestamp = n.time; | 730 f.timestamp = n.time; |
716 f.duration = n.duration; | 731 f.duration = n.duration; |
717 f.values.clear(); | 732 f.values.clear(); |
718 f.values.push_back(n.freq); | 733 f.values.push_back(freq); |
719 f.values.push_back(velocity); | 734 f.values.push_back(velocity); |
720 // f.label = noteName(note, partShift, shiftCount); | 735 // f.label = noteName(note, partShift, shiftCount); |
721 noteFeatures.push_back(f); | 736 noteFeatures.push_back(f); |
722 } | 737 } |
723 | 738 |