changeset 55:2a21b4506d7f

Use MIDI pitch values, as in QM Vamp Plugins implementation
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 28 Nov 2013 17:03:57 +0000
parents 2e0d1300a065
children e2b7f7462618
files cpp-qm-dsp/Makefile cpp-qm-dsp/test.cpp vamp/CQVamp.cpp vamp/CQVamp.h
diffstat 4 files changed, 75 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/cpp-qm-dsp/Makefile	Thu Nov 28 14:32:42 2013 +0000
+++ b/cpp-qm-dsp/Makefile	Thu Nov 28 17:03:57 2013 +0000
@@ -3,8 +3,8 @@
 
 CFLAGS := -I../.. $(CFLAGS) $(DEFINES)
 
-CXXFLAGS := -I../.. -fPIC -Wall -g $(CXXFLAGS) $(DEFINES)
-#CXXFLAGS := -I../.. -fPIC -Wall -O3 -ffast-math -ftree-vectorize $(CXXFLAGS) $(DEFINES)
+#CXXFLAGS := -I../.. -fPIC -Wall -g $(CXXFLAGS) $(DEFINES)
+CXXFLAGS := -I../.. -fPIC -Wall -O3 -ffast-math -ftree-vectorize $(CXXFLAGS) $(DEFINES)
 
 LDFLAGS := $(LDFLAGS)
 
--- a/cpp-qm-dsp/test.cpp	Thu Nov 28 14:32:42 2013 +0000
+++ b/cpp-qm-dsp/test.cpp	Thu Nov 28 17:03:57 2013 +0000
@@ -30,11 +30,11 @@
 
     cerr << "got " << out.size() << " back (" << out[0].size() << " in each?)" << endl;
 
-    for (int b = 0; b < out.size() / 8; ++b) {
+    for (int b = 0; b < (int)out.size() / 8; ++b) {
 	printf("\nColumns %d to %d:\n\n", b * 8, b * 8 + 7);
 	for (int j = int(out[0].size()) - 1; j >= 0; --j) {
 	    for (int i = 0; i < 8; ++i) {
-		if (i + b * 8 < out.size()) {
+		if (i + b * 8 < (int)out.size()) {
 		    double v = out[i + b * 8][j];
 		    if (v < 0.0001) printf("  0      ");
 		    else printf("  %.4f ", out[i + b * 8][j]);
--- a/vamp/CQVamp.cpp	Thu Nov 28 14:32:42 2013 +0000
+++ b/vamp/CQVamp.cpp	Thu Nov 28 17:03:57 2013 +0000
@@ -4,6 +4,8 @@
 
 #include "../cpp-qm-dsp/ConstantQ.h"
 
+#include "qm-dsp/base/Pitch.h"
+
 using std::string;
 using std::vector;
 using std::cerr;
@@ -11,10 +13,13 @@
 
 CQVamp::CQVamp(float inputSampleRate) :
     Vamp::Plugin(inputSampleRate),
+    m_minMIDIPitch(36),
+    m_maxMIDIPitch(84),
+    m_tuningFrequency(440),
+    m_bpo(24),
     m_cq(0),
     m_maxFrequency(inputSampleRate/2),
     m_minFrequency(46),
-    m_bpo(24),
     m_haveStartTime(false),
     m_columnCount(0)
 {
@@ -65,7 +70,7 @@
 CQVamp::getParameterDescriptors() const
 {
     ParameterList list;
-
+/*
     ParameterDescriptor desc;
     desc.identifier = "minfreq";
     desc.name = "Minimum Frequency";
@@ -86,6 +91,39 @@
     desc.defaultValue = m_inputSampleRate/2;
     desc.isQuantized = false;
     list.push_back(desc);
+ */
+    ParameterDescriptor desc;
+    desc.identifier = "minpitch";
+    desc.name = "Minimum Pitch";
+    desc.unit = "MIDI units";
+    desc.description = "MIDI pitch corresponding to the lowest frequency to be included in the constant-Q transform";
+    desc.minValue = 0;
+    desc.maxValue = 127;
+    desc.defaultValue = 36;
+    desc.isQuantized = true;
+    desc.quantizeStep = 1;
+    list.push_back(desc);
+
+    desc.identifier = "maxpitch";
+    desc.name = "Maximum Pitch";
+    desc.unit = "MIDI units";
+    desc.description = "MIDI pitch corresponding to the highest frequency to be included in the constant-Q transform";
+    desc.minValue = 0;
+    desc.maxValue = 127;
+    desc.defaultValue = 84;
+    desc.isQuantized = true;
+    desc.quantizeStep = 1;
+    list.push_back(desc);
+
+    desc.identifier = "tuning";
+    desc.name = "Tuning Frequency";
+    desc.unit = "Hz";
+    desc.description = "Frequency of concert A";
+    desc.minValue = 360;
+    desc.maxValue = 500;
+    desc.defaultValue = 440;
+    desc.isQuantized = false;
+    list.push_back(desc);
     
     desc.identifier = "bpo";
     desc.name = "Bins per Octave";
@@ -104,12 +142,23 @@
 float
 CQVamp::getParameter(std::string param) const
 {
+    if (param == "minpitch") {
+        return m_minMIDIPitch;
+    }
+    if (param == "maxpitch") {
+        return m_maxMIDIPitch;
+    }
+    if (param == "tuning") {
+        return m_tuningFrequency;
+    }
+/*
     if (param == "minfreq") {
         return m_minFrequency;
     }
     if (param == "maxfreq") {
         return m_maxFrequency;
     }
+*/
     if (param == "bpo") {
         return m_bpo;
     }
@@ -121,11 +170,18 @@
 void
 CQVamp::setParameter(std::string param, float value)
 {
-    if (param == "minfreq") {
+    if (param == "minpitch") {
+        m_minMIDIPitch = lrintf(value);
+    } else if (param == "maxpitch") {
+        m_maxMIDIPitch = lrintf(value);
+    } else if (param == "tuning") {
+        m_tuningFrequency = value;
+/*    if (param == "minfreq") {
         m_minFrequency = value;
     } else if (param == "maxfreq") {
         m_maxFrequency = value;
-    } else if (param == "bpo") {
+*/
+    } else  if (param == "bpo") {
         m_bpo = lrintf(value);
     } else {
         std::cerr << "WARNING: CQVamp::setParameter: unknown parameter \""
@@ -147,6 +203,11 @@
     m_stepSize = stepSize;
     m_blockSize = blockSize;
 
+    m_minFrequency = Pitch::getFrequencyForPitch
+        (m_minMIDIPitch, 0, m_tuningFrequency);
+    m_maxFrequency = Pitch::getFrequencyForPitch
+        (m_maxMIDIPitch, 0, m_tuningFrequency);
+
     m_cq = new ConstantQ
 	(m_inputSampleRate, m_minFrequency, m_maxFrequency, m_bpo);
 
@@ -257,7 +318,7 @@
 	feature.values = column;
 	feature.label = "";
 
-        cerr << "timestamp = " << feature.timestamp << " (latency = " << m_cq->getLatency() << ", sample rate " << m_inputSampleRate << ")" << endl;
+//        cerr << "timestamp = " << feature.timestamp << " (latency = " << m_cq->getLatency() << ", sample rate " << m_inputSampleRate << ")" << endl;
 
         if (feature.timestamp >= m_startTime) {
             returnFeatures[0].push_back(feature);
--- a/vamp/CQVamp.h	Thu Nov 28 14:32:42 2013 +0000
+++ b/vamp/CQVamp.h	Thu Nov 28 17:03:57 2013 +0000
@@ -40,10 +40,14 @@
     FeatureSet getRemainingFeatures();
 
 protected:
+    int m_minMIDIPitch;
+    int m_maxMIDIPitch;
+    float m_tuningFrequency;
+    int m_bpo;
+
     ConstantQ *m_cq;
     float m_maxFrequency;
     float m_minFrequency;
-    int m_bpo;
     int m_stepSize;
     int m_blockSize;