# HG changeset patch # User Chris Cannam # Date 1396618720 -3600 # Node ID 461d94ed3816bddbbe45164e1f80ddb0f8151ef9 # Parent 7d81407a2fd8586adaf366efc3a33f66f3bb5cfc More on EM diff -r 7d81407a2fd8 -r 461d94ed3816 data/include/templates.h --- 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" diff -r 7d81407a2fd8 -r 461d94ed3816 src/EM.cpp --- 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); +} + diff -r 7d81407a2fd8 -r 461d94ed3816 src/EM.h --- 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 diff -r 7d81407a2fd8 -r 461d94ed3816 yeti/scratch/generateTemplatesC.yeti --- 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\"";