changeset 242:3e882621e2dd

Add "rapid" option (frame overlap factor)
author Chris Cannam <cannam@all-day-breakfast.com>
date Thu, 06 Jun 2019 14:21:39 +0100
parents d4ba927300f5
children 2e12b4a3c47d
files plugins/KeyDetect.cpp plugins/KeyDetect.h repoint-lock.json
diffstat 3 files changed, 45 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/KeyDetect.cpp	Wed Jun 05 16:11:35 2019 +0100
+++ b/plugins/KeyDetect.cpp	Thu Jun 06 14:21:39 2019 +0100
@@ -16,8 +16,6 @@
 
 using std::string;
 using std::vector;
-//using std::cerr;
-using std::endl;
 
 #include <cmath>
 
@@ -34,6 +32,7 @@
     m_blockSize(0),
     m_tuningFrequency(440),
     m_length(10),
+    m_rapid(true),
     m_getKeyMode(0),
     m_inputFrame(0),
     m_prevKey(-1)
@@ -81,7 +80,7 @@
 string
 KeyDetector::getCopyright() const
 {
-    return "Plugin by Katy Noland and Christian Landone.  Copyright (c) 2006-2009 QMUL - All Rights Reserved";
+    return "Plugin by Katy Noland and Christian Landone.  Copyright (c) 2006-2019 QMUL - All Rights Reserved";
 }
 
 KeyDetector::ParameterList
@@ -111,6 +110,17 @@
     desc.quantizeStep = 1;
     list.push_back(desc);
 
+    desc.identifier = "rapid";
+    desc.name = "Rapid";
+    desc.unit = "";
+    desc.description = "Sample intervals without overlap, for speed";
+    desc.minValue = 0;
+    desc.maxValue = 1;
+    desc.defaultValue = 1;
+    desc.isQuantized = true;
+    desc.quantizeStep = 1;
+    list.push_back(desc);
+
     return list;
 }
 
@@ -123,6 +133,9 @@
     if (param == "length") {
         return m_length;
     }
+    if (param == "rapid") {
+        return m_rapid ? 1.f : 0.f;
+    }
     std::cerr << "WARNING: KeyDetector::getParameter: unknown parameter \""
               << param << "\"" << std::endl;
     return 0.0;
@@ -135,10 +148,27 @@
         m_tuningFrequency = value;
     } else if (param == "length") {
         m_length = int(value + 0.1);
+    } else if (param == "rapid") {
+        m_rapid = (value > 0.5);
     } else {
         std::cerr << "WARNING: KeyDetector::setParameter: unknown parameter \""
                   << param << "\"" << std::endl;
     }
+
+    // force recalculate:
+    m_stepSize = 0;
+    m_blockSize = 0;
+}
+
+GetKeyMode::Config
+KeyDetector::getConfig() const
+{
+    GetKeyMode::Config config(m_inputSampleRate, m_tuningFrequency);
+    config.hpcpAverage = m_length;
+    config.medianAverage = m_length;
+    config.frameOverlapFactor = (m_rapid ? 1 : 8);
+    config.decimationFactor = 8;
+    return config;
 }
 
 bool
@@ -152,9 +182,7 @@
     if (channels < getMinChannelCount() ||
 	channels > getMaxChannelCount()) return false;
 
-    m_getKeyMode = new GetKeyMode(int(m_inputSampleRate + 0.1),
-                                  m_tuningFrequency,
-                                  m_length, m_length);
+    m_getKeyMode = new GetKeyMode(getConfig());
 
     m_stepSize = m_getKeyMode->getHopSize();
     m_blockSize = m_getKeyMode->getBlockSize();
@@ -181,9 +209,7 @@
 {
     if (m_getKeyMode) {
         delete m_getKeyMode;
-        m_getKeyMode = new GetKeyMode(int(m_inputSampleRate + 0.1),
-                                      m_tuningFrequency,
-                                      m_length, m_length);
+        m_getKeyMode = new GetKeyMode(getConfig());
     }
 
     if (m_inputFrame) {
@@ -289,13 +315,16 @@
     }
 
     int key = m_getKeyMode->process(m_inputFrame);
-    bool minor = m_getKeyMode->isModeMinor(key);
+
     int tonic = key;
     if (tonic > 12) tonic -= 12;
 
     int prevTonic = m_prevKey;
     if (prevTonic > 12) prevTonic -= 12;
 
+    bool minor = (key > 12);
+    bool prevMinor = (m_prevKey > 12);
+
     if (m_first || (tonic != prevTonic)) {
         Feature feature;
         feature.hasTimestamp = true;
@@ -305,7 +334,7 @@
         returnFeatures[0].push_back(feature); // tonic
     }
 
-    if (m_first || (minor != (m_getKeyMode->isModeMinor(m_prevKey)))) {
+    if (m_first || (minor != prevMinor)) {
         Feature feature;
         feature.hasTimestamp = true;
         feature.timestamp = now;
@@ -345,13 +374,11 @@
     return FeatureSet();
 }
 
-
 size_t
 KeyDetector::getPreferredStepSize() const
 {
     if (!m_stepSize) {
-        GetKeyMode gkm(int(m_inputSampleRate + 0.1),
-                       m_tuningFrequency, m_length, m_length);
+        GetKeyMode gkm(getConfig());
         m_stepSize = gkm.getHopSize();
         m_blockSize = gkm.getBlockSize();
     }
@@ -362,8 +389,7 @@
 KeyDetector::getPreferredBlockSize() const
 {
     if (!m_blockSize) {
-        GetKeyMode gkm(int(m_inputSampleRate + 0.1),
-                       m_tuningFrequency, m_length, m_length);
+        GetKeyMode gkm(getConfig());
         m_stepSize = gkm.getHopSize();
         m_blockSize = gkm.getBlockSize();
     }
--- a/plugins/KeyDetect.h	Wed Jun 05 16:11:35 2019 +0100
+++ b/plugins/KeyDetect.h	Thu Jun 06 14:21:39 2019 +0100
@@ -56,7 +56,9 @@
     mutable size_t m_blockSize;
     float m_tuningFrequency;
     int m_length;
+    bool m_rapid;
 
+    GetKeyMode::Config getConfig() const;
     std::string getKeyName(int index, bool minor, bool includeMajMin) const;
 
     GetKeyMode* m_getKeyMode;
--- a/repoint-lock.json	Wed Jun 05 16:11:35 2019 +0100
+++ b/repoint-lock.json	Thu Jun 06 14:21:39 2019 +0100
@@ -4,7 +4,7 @@
       "pin": "62987b6d6a3b"
     },
     "qm-dsp": {
-      "pin": "bdf8b2126892efdf3282165119c87d921dba29ad"
+      "pin": "934cda2e5d29c39ee2c6cfaa675e8a812fba7d4d"
     }
   }
 }