Mercurial > hg > silvet
comparison src/EM.cpp @ 35:461d94ed3816
More on EM
| author | Chris Cannam |
|---|---|
| date | Fri, 04 Apr 2014 14:38:40 +0100 |
| parents | 7d81407a2fd8 |
| children | 74b77a4d6552 |
comparison
equal
deleted
inserted
replaced
| 34:7d81407a2fd8 | 35:461d94ed3816 |
|---|---|
| 15 | 15 |
| 16 #include "EM.h" | 16 #include "EM.h" |
| 17 | 17 |
| 18 #include "data/include/templates.h" | 18 #include "data/include/templates.h" |
| 19 | 19 |
| 20 static double epsilon = 1e-16; | |
| 21 | |
| 22 EM::EM() : | |
| 23 m_notes(SILVET_TEMPLATE_NOTE_COUNT), | |
| 24 m_bins(SILVET_TEMPLATE_HEIGHT), | |
| 25 m_instruments(SILVET_TEMPLATE_COUNT) | |
| 26 { | |
| 27 m_lowest = 0; | |
| 28 m_highest = m_notes - 1; | |
| 29 | |
| 30 for (int i = 0; i < m_instruments; ++i) { | |
| 31 if (i == 0 || silvet_templates[i].lowest < m_lowest) { | |
| 32 m_lowest = silvet_templates[i].lowest; | |
| 33 } | |
| 34 if (i == 0 || silvet_templates[i].highest > m_highest) { | |
| 35 m_highest = silvet_templates[i].highest; | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 m_pitches = V(m_notes); | |
| 40 | |
| 41 for (int n = 0; n < m_notes; ++i) { | |
| 42 m_pitches[n] = drand48(); | |
| 43 } | |
| 44 | |
| 45 m_sources = Grid(m_instruments); | |
| 46 | |
| 47 for (int i = 0; i < m_instruments; ++i) { | |
| 48 m_sources[i] = V(m_notes); | |
| 49 for (int n = 0; n < m_notes; ++n) { | |
| 50 m_sources[i][n] = (inRange(i, n) ? 1.0 : 0.0); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 m_q = V(m_bins); | |
| 55 | |
| 56 for (int w = 0; w < m_bins; ++w) { | |
| 57 m_q[w] = epsilon; | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 EM::~EM() | |
| 62 { | |
| 63 } | |
| 64 | |
| 65 bool | |
| 66 EM::inRange(int instrument, int note) | |
| 67 { | |
| 68 return (note >= silvet_templates[instrument].lowest && | |
| 69 note <= silvet_templates[instrument].highest); | |
| 70 } | |
| 71 |
