changeset 91:2b0818a1c058 bqvec

First bit of bqvec adaptation
author Chris Cannam
date Tue, 06 May 2014 13:49:52 +0100
parents f1116eb464f9
children 81eaba98985b
files Makefile.inc Makefile.linux src/EM.cpp src/EM.h
diffstat 4 files changed, 37 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.inc	Tue May 06 13:05:43 2014 +0100
+++ b/Makefile.inc	Tue May 06 13:49:52 2014 +0100
@@ -3,6 +3,7 @@
 
 QMDSP_DIR ?= ../qm-dsp
 VAMPSDK_DIR  ?= ../vamp-plugin-sdk
+BQVEC_DIR ?= ../bqvec
 
 CQ_DIR	     ?= constant-q-cpp/cpp-qm-dsp
 
@@ -12,7 +13,7 @@
 CC	?= gcc
 
 CFLAGS := $(CFLAGS) 
-CXXFLAGS := -I. -I$(VAMPSDK_DIR) -I$(QMDSP_DIR) $(CXXFLAGS)
+CXXFLAGS := -I. -I$(VAMPSDK_DIR) -I$(QMDSP_DIR) -I$(BQVEC_DIR) $(CXXFLAGS)
 
 LDFLAGS := $(LDFLAGS) 
 PLUGIN_LDFLAGS := $(LDFLAGS) $(PLUGIN_LDFLAGS)
--- a/Makefile.linux	Tue May 06 13:05:43 2014 +0100
+++ b/Makefile.linux	Tue May 06 13:49:52 2014 +0100
@@ -1,5 +1,5 @@
 
-CFLAGS := -Wall -O3 -ffast-math -msse -mfpmath=sse -ftree-vectorize -fPIC -I../vamp-plugin-sdk/
+CFLAGS := -Wall -O3 -ffast-math -msse -mfpmath=sse -ftree-vectorize -ftree-vectorizer-verbose=2 -fPIC -I../vamp-plugin-sdk/
 #CFLAGS := -g -fPIC -I../vamp-plugin-sdk
 
 CXXFLAGS := $(CFLAGS)
--- a/src/EM.cpp	Tue May 06 13:05:43 2014 +0100
+++ b/src/EM.cpp	Tue May 06 13:49:52 2014 +0100
@@ -22,47 +22,48 @@
 
 #include <iostream>
 
-#include <vector>
+#include "VectorOps.h"
+#include "Allocators.h"
 
 using std::vector;
 using std::cerr;
 using std::endl;
 
+using namespace breakfastquay;
+
 static double epsilon = 1e-16;
 
 EM::EM() :
     m_noteCount(SILVET_TEMPLATE_NOTE_COUNT),
     m_shiftCount(SILVET_TEMPLATE_MAX_SHIFT * 2 + 1),
     m_binCount(SILVET_TEMPLATE_HEIGHT),
-    m_instrumentCount(SILVET_TEMPLATE_COUNT),
+    m_sourceCount(SILVET_TEMPLATE_COUNT),
     m_pitchSparsity(1.1),
     m_sourceSparsity(1.3),
     m_lowestPitch(silvet_templates_lowest_note),
     m_highestPitch(silvet_templates_highest_note)
 {
-    m_pitches = V(m_noteCount);
+    m_pitches = allocate<double>(m_noteCount);
     for (int n = 0; n < m_noteCount; ++n) {
         m_pitches[n] = drand48();
     }
 
-    m_shifts = Grid(m_shiftCount);
+    m_shifts = allocate_channels<double>(m_shiftCount, m_noteCount);
     for (int f = 0; f < m_shiftCount; ++f) {
-        m_shifts[f] = V(m_noteCount);
         for (int n = 0; n < m_noteCount; ++n) {
             m_shifts[f][n] = drand48();
         }
     }
     
-    m_sources = Grid(m_instrumentCount);
-        for (int i = 0; i < m_instrumentCount; ++i) {
-        m_sources[i] = V(m_noteCount);
+    m_sources = allocate_channels<double>(m_sourceCount, m_noteCount);
+    for (int i = 0; i < m_sourceCount; ++i) {
         for (int n = 0; n < m_noteCount; ++n) {
             m_sources[i][n] = (inRange(i, n) ? 1.0 : 0.0);
         }
     }
 
-    m_estimate = V(m_binCount);
-    m_q = V(m_binCount);
+    m_estimate = allocate<double>(m_binCount);
+    m_q = allocate<double>(m_binCount);
 }
 
 EM::~EM()
@@ -137,7 +138,7 @@
         m_estimate[i] = epsilon;
     }
 
-    for (int i = 0; i < m_instrumentCount; ++i) {
+    for (int i = 0; i < m_sourceCount; ++i) {
         for (int n = 0; n < m_noteCount; ++n) {
             const double pitch = m_pitches[n];
             const double source = m_sources[i][n];
@@ -162,7 +163,7 @@
 {
     V newPitches(m_noteCount, epsilon);
     Grid newShifts(m_shiftCount, V(m_noteCount, epsilon));
-    Grid newSources(m_instrumentCount, V(m_noteCount, epsilon));
+    Grid newSources(m_sourceCount, V(m_noteCount, epsilon));
 
     for (int n = 0; n < m_noteCount; ++n) {
 
@@ -172,7 +173,7 @@
 
             const double shift = m_shifts[f][n];
 
-            for (int i = 0; i < m_instrumentCount; ++i) {
+            for (int i = 0; i < m_sourceCount; ++i) {
 
                 const double source = m_sources[i][n];
                 const double factor = pitch * source * shift;
@@ -203,7 +204,7 @@
             newPitches[n] = pow(newPitches[n], m_pitchSparsity);
         }
         if (m_sourceSparsity != 1.0) {
-            for (int i = 0; i < m_instrumentCount; ++i) {
+            for (int i = 0; i < m_sourceCount; ++i) {
                 newSources[i][n] = pow(newSources[i][n], m_sourceSparsity);
             }
         }
--- a/src/EM.h	Tue May 06 13:05:43 2014 +0100
+++ b/src/EM.h	Tue May 06 13:49:52 2014 +0100
@@ -24,33 +24,34 @@
     EM();
     ~EM();
 
-    void iterate(std::vector<double> column);
+    int getBinCount() const { return m_binCount; } // size of input column
+    int getNoteCount() const { return m_noteCount; } // size of pitch column
+    int getSourceCount() const { return m_sourceCount; }
 
-    const std::vector<double> &getEstimate() const { 
+    void iterate(double *column);
+
+    const double *getEstimate() const { // bin count
 	return m_estimate;
     }
-    const std::vector<double> &getPitchDistribution() const {
+    const double *getPitchDistribution() const { // note count
 	return m_pitches;
     }
-    const std::vector<std::vector<double> > &getSources() const {
+    const double **getSources() const { // source count * note count
 	return m_sources; 
     }
 
 private:
-    typedef std::vector<double> V;
-    typedef std::vector<std::vector<double> > Grid;
+    double *m_pitches;
+    double **m_shifts;
+    double **m_sources;
 
-    V m_pitches;
-    Grid m_shifts;
-    Grid m_sources;
-
-    V m_estimate;
-    V m_q;
+    double *m_estimate;
+    double *m_q;
     
     const int m_noteCount;
     const int m_shiftCount; // 1 + 2 * max template shift
     const int m_binCount;
-    const int m_instrumentCount;
+    const int m_sourceCount;
     
     const double m_pitchSparsity;
     const double m_sourceSparsity;
@@ -58,10 +59,11 @@
     const int m_lowestPitch;
     const int m_highestPitch;
 
-    void normaliseColumn(V &column);
-    void normaliseGrid(Grid &grid);
-    void expectation(const V &column);
-    void maximisation(const V &column);
+    void normaliseColumn(double *column, int size);
+    void normaliseGrid(double **grid, int width, int height);
+
+    void expectation(double *column); // size is m_binCount
+    void maximisation(double *column); // size is m_binCount
 
     const double *templateFor(int instrument, int note, int shift);
     void rangeFor(int instrument, int &minPitch, int &maxPitch);