diff src/Silvet.cpp @ 38:5164bccf3064

Return pitch activation matrix
author Chris Cannam
date Fri, 04 Apr 2014 19:05:47 +0100
parents 947996aac974
children 2b254fc68e81
line wrap: on
line diff
--- a/src/Silvet.cpp	Fri Apr 04 18:18:18 2014 +0100
+++ b/src/Silvet.cpp	Fri Apr 04 19:05:47 2014 +0100
@@ -32,6 +32,7 @@
 static int processingSampleRate = 44100;
 static int processingBPO = 60;
 static int processingHeight = 545;
+static int processingNotes = 88;
 
 Silvet::Silvet(float inputSampleRate) :
     Plugin(inputSampleRate),
@@ -203,9 +204,44 @@
     m_cqOutputNo = list.size();
     list.push_back(d);
 
+    d.identifier = "pitchdistribution";
+    d.name = "Pitch distribution";
+    d.description = "The estimated pitch contribution matrix";
+    d.unit = "";
+    d.hasFixedBinCount = true;
+    d.binCount = processingNotes;
+    d.binNames.clear();
+    for (int i = 0; i < processingNotes; ++i) {
+        d.binNames.push_back(noteName(i));
+    }
+    d.hasKnownExtents = false;
+    d.isQuantized = false;
+    d.sampleType = OutputDescriptor::FixedSampleRate;
+    d.sampleRate = 25;
+    d.hasDuration = false;
+    m_pitchOutputNo = list.size();
+    list.push_back(d);
+
     return list;
 }
 
+std::string
+Silvet::noteName(int i) const
+{
+    static const char *names[] = {
+        "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"
+    };
+
+    const char *n = names[i % 12];
+
+    int oct = (i + 9) / 12; 
+    
+    char buf[20];
+    sprintf(buf, "%s%d", n, oct);
+
+    return buf;
+}
+
 bool
 Silvet::initialise(size_t channels, size_t stepSize, size_t blockSize)
 {
@@ -310,6 +346,13 @@
             em.iterate(filtered[i]);
         }
 
+        vector<double> pitches = em.getPitchDistribution();
+        Feature f;
+        for (int j = 0; j < (int)pitches.size(); ++j) {
+            f.values.push_back(float(pitches[i]));
+        }
+        fs[m_pitchOutputNo].push_back(f);
+
         //!!! now do something with the results from em!
         em.report();
     }