changeset 38:5164bccf3064

Return pitch activation matrix
author Chris Cannam
date Fri, 04 Apr 2014 19:05:47 +0100
parents 947996aac974
children 2b254fc68e81
files src/EM.cpp src/EM.h src/Silvet.cpp src/Silvet.h
diffstat 4 files changed, 59 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/EM.cpp	Fri Apr 04 18:18:18 2014 +0100
+++ b/src/EM.cpp	Fri Apr 04 19:05:47 2014 +0100
@@ -152,9 +152,10 @@
             newSources[i][n] = epsilon;
             if (inRange(i, n)) {
                 float *w = silvet_templates[i].data[n];
+                double pitch = m_pitches[n];
+                double source = m_sources[i][n];
                 for (int j = 0; j < m_bins; ++j) {
-                    newSources[i][n] +=
-                        w[j] * m_q[j] * m_pitches[n] * m_sources[i][n];
+                    newSources[i][n] += w[j] * m_q[j] * pitch * source;
                 }
             }
         }
--- a/src/EM.h	Fri Apr 04 18:18:18 2014 +0100
+++ b/src/EM.h	Fri Apr 04 19:05:47 2014 +0100
@@ -27,6 +27,16 @@
     void iterate(std::vector<double> column);
     void report();
 
+    const std::vector<double> &getEstimate() const { 
+	return m_estimate;
+    }
+    const std::vector<double> &getPitchDistribution() const {
+	return m_pitches;
+    }
+    const std::vector<std::vector<double> > &getSources() const {
+	return m_sources; 
+    }
+
 private:
     typedef std::vector<double> V;
     typedef std::vector<std::vector<double> > Grid;
--- 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();
     }
--- a/src/Silvet.h	Fri Apr 04 18:18:18 2014 +0100
+++ b/src/Silvet.h	Fri Apr 04 19:05:47 2014 +0100
@@ -77,12 +77,15 @@
     Grid preProcess(const Grid &);
     FeatureSet transcribe(const Grid &);
 
+    std::string noteName(int n) const;
+
     int m_blockSize;
     int m_columnCount;
     int m_reducedColumnCount;
 
     mutable int m_notesOutputNo;
     mutable int m_cqOutputNo;
+    mutable int m_pitchOutputNo;
 };
 
 #endif