changeset 35:461d94ed3816

More on EM
author Chris Cannam
date Fri, 04 Apr 2014 14:38:40 +0100
parents 7d81407a2fd8
children 74b77a4d6552
files data/include/templates.h src/EM.cpp src/EM.h yeti/scratch/generateTemplatesC.yeti
diffstat 4 files changed, 62 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/data/include/templates.h	Fri Apr 04 14:28:41 2014 +0100
+++ b/data/include/templates.h	Fri Apr 04 14:38:40 2014 +0100
@@ -7,6 +7,7 @@
 
 #define SILVET_TEMPLATE_NOTE_COUNT 88
 #define SILVET_TEMPLATE_HEIGHT     545
+#define SILVET_TEMPLATE_COUNT      13
 
 typedef struct {
     const char *name;
@@ -15,7 +16,7 @@
     float data[SILVET_TEMPLATE_NOTE_COUNT][SILVET_TEMPLATE_HEIGHT];
 } silvet_template_t;
 
-static silvet_template_t silvet_templates[13] = {
+static silvet_template_t silvet_templates[SILVET_TEMPLATE_COUNT] = {
 #include "bassoon.h"
 #include "cello.h"
 #include "clarinet.h"
--- a/src/EM.cpp	Fri Apr 04 14:28:41 2014 +0100
+++ b/src/EM.cpp	Fri Apr 04 14:38:40 2014 +0100
@@ -17,3 +17,55 @@
 
 #include "data/include/templates.h"
 
+static double epsilon = 1e-16;
+
+EM::EM() :
+    m_notes(SILVET_TEMPLATE_NOTE_COUNT),
+    m_bins(SILVET_TEMPLATE_HEIGHT),
+    m_instruments(SILVET_TEMPLATE_COUNT)
+{
+    m_lowest = 0;
+    m_highest = m_notes - 1;
+
+    for (int i = 0; i < m_instruments; ++i) {
+        if (i == 0 || silvet_templates[i].lowest < m_lowest) {
+            m_lowest = silvet_templates[i].lowest;
+        }
+        if (i == 0 || silvet_templates[i].highest > m_highest) {
+            m_highest = silvet_templates[i].highest;
+        }
+    }
+
+    m_pitches = V(m_notes);
+
+    for (int n = 0; n < m_notes; ++i) {
+        m_pitches[n] = drand48();
+    }
+    
+    m_sources = Grid(m_instruments);
+    
+    for (int i = 0; i < m_instruments; ++i) {
+        m_sources[i] = V(m_notes);
+        for (int n = 0; n < m_notes; ++n) {
+            m_sources[i][n] = (inRange(i, n) ? 1.0 : 0.0);
+        }
+    }
+
+    m_q = V(m_bins);
+    
+    for (int w = 0; w < m_bins; ++w) {
+        m_q[w] = epsilon;
+    }
+}
+
+EM::~EM()
+{
+}
+
+bool
+EM::inRange(int instrument, int note)
+{
+    return (note >= silvet_templates[instrument].lowest &&
+            note <= silvet_templates[instrument].highest);
+}
+
--- a/src/EM.h	Fri Apr 04 14:28:41 2014 +0100
+++ b/src/EM.h	Fri Apr 04 14:38:40 2014 +0100
@@ -34,8 +34,14 @@
     Grid m_sources;
     Grid m_q;
     
+    int m_notes;
+    int m_bins;
+    int m_instruments;
+
     int m_lowest;
     int m_highest;
+
+    bool inRange(int instrument, int note);
 };
 
 #endif
--- a/yeti/scratch/generateTemplatesC.yeti	Fri Apr 04 14:28:41 2014 +0100
+++ b/yeti/scratch/generateTemplatesC.yeti	Fri Apr 04 14:38:40 2014 +0100
@@ -69,6 +69,7 @@
         "",
         "#define SILVET_TEMPLATE_NOTE_COUNT \(noteCount)",
         "#define SILVET_TEMPLATE_HEIGHT     \(templateHeight)",
+        "#define SILVET_TEMPLATE_COUNT      \(length instruments)",
         "",
         "typedef struct {",
         "    const char *name;",
@@ -77,7 +78,7 @@
         "    float data[SILVET_TEMPLATE_NOTE_COUNT][SILVET_TEMPLATE_HEIGHT];",
         "} silvet_template_t;",
         "",
-        "static silvet_template_t silvet_templates[\(length instruments)] = {",
+        "static silvet_template_t silvet_templates[SILVET_TEMPLATE_COUNT] = {",
     ] ostr.writeln;
     for instruments do instrument:
         ostr.writeln "#include \"\(instrument).h\"";