# HG changeset patch # User Chris Cannam # Date 1399452195 -3600 # Node ID b2f0967cb8d1e24d503e33c5d5965b4d1e92efde # Parent c4eae816bdb382f114f9a89608245009c12a9764 Pull out shifted templates into separate arrays with proper alignment (trading off memory occupied against getting the alignments right) diff -r c4eae816bdb3 -r b2f0967cb8d1 data/include/templates.h --- a/data/include/templates.h Wed May 07 09:08:52 2014 +0100 +++ b/data/include/templates.h Wed May 07 09:43:15 2014 +0100 @@ -15,7 +15,7 @@ const char *name; int lowest; int highest; - double data[SILVET_TEMPLATE_NOTE_COUNT][SILVET_TEMPLATE_SIZE]; + float data[SILVET_TEMPLATE_NOTE_COUNT][SILVET_TEMPLATE_SIZE]; } silvet_template_t; static int silvet_templates_lowest_note = 15; diff -r c4eae816bdb3 -r b2f0967cb8d1 src/EM.cpp --- a/src/EM.cpp Wed May 07 09:08:52 2014 +0100 +++ b/src/EM.cpp Wed May 07 09:43:15 2014 +0100 @@ -33,6 +33,9 @@ static double epsilon = 1e-16; +bool EM::m_initialised = false; +double ****EM::m_templates = 0; + EM::EM(bool useShifts) : m_noteCount(SILVET_TEMPLATE_NOTE_COUNT), m_shiftCount(useShifts ? SILVET_TEMPLATE_MAX_SHIFT * 2 + 1 : 1), @@ -43,11 +46,24 @@ m_lowestPitch(silvet_templates_lowest_note), m_highestPitch(silvet_templates_highest_note) { + if (!m_initialised) { + cerr << "ERROR: You must call EM::initialise() before constructing any EM objects" << endl; + abort(); + } + m_pitches = allocate(m_noteCount); m_updatePitches = allocate(m_noteCount); for (int n = 0; n < m_noteCount; ++n) { m_pitches[n] = drand48(); } + + m_sources = allocate_channels(m_sourceCount, m_noteCount); + m_updateSources = allocate_channels(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); + } + } if (useShifts) { m_shifts = allocate_channels(m_shiftCount, m_noteCount); @@ -61,14 +77,6 @@ m_shifts = 0; m_updateShifts = 0; } - - m_sources = allocate_channels(m_sourceCount, m_noteCount); - m_updateSources = allocate_channels(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 = allocate(m_binCount); m_q = allocate(m_binCount); @@ -87,6 +95,27 @@ } void +EM::initialise() +{ + //!!! need mutex + + if (m_initialised) return; + m_templates = new double ***[SILVET_TEMPLATE_COUNT]; + for (int i = 0; i < SILVET_TEMPLATE_COUNT; ++i) { + m_templates[i] = new double **[SILVET_TEMPLATE_NOTE_COUNT]; + for (int n = 0; n < SILVET_TEMPLATE_NOTE_COUNT; ++n) { + m_templates[i][n] = new double *[SILVET_TEMPLATE_MAX_SHIFT * 2 + 1]; + for (int f = 0; f < SILVET_TEMPLATE_MAX_SHIFT * 2 + 1; ++f) { + m_templates[i][n][f] = allocate(SILVET_TEMPLATE_HEIGHT); + const float *t = silvet_templates[i].data[n] + f; + v_convert(m_templates[i][n][f], t, SILVET_TEMPLATE_HEIGHT); + } + } + } + m_initialised = true; +} + +void EM::rangeFor(int instrument, int &minPitch, int &maxPitch) { minPitch = silvet_templates[instrument].lowest; @@ -141,10 +170,9 @@ EM::templateFor(int instrument, int note, int shift) { if (m_shifts) { - return silvet_templates[instrument].data[note] + shift; + return m_templates[instrument][note][shift]; } else { - return silvet_templates[instrument].data[note] + - SILVET_TEMPLATE_MAX_SHIFT; + return m_templates[instrument][note][SILVET_TEMPLATE_MAX_SHIFT]; } } diff -r c4eae816bdb3 -r b2f0967cb8d1 src/EM.h --- a/src/EM.h Wed May 07 09:08:52 2014 +0100 +++ b/src/EM.h Wed May 07 09:43:15 2014 +0100 @@ -24,6 +24,8 @@ EM(bool useShifts); ~EM(); + static void initialise(); + 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; } @@ -51,6 +53,9 @@ double *m_estimate; double *m_q; + + static bool m_initialised; + static double ****m_templates; // [source][note][shift][bin] const int m_noteCount; const int m_shiftCount; // 1 + 2 * max template shift diff -r c4eae816bdb3 -r b2f0967cb8d1 src/Silvet.cpp --- a/src/Silvet.cpp Wed May 07 09:08:52 2014 +0100 +++ b/src/Silvet.cpp Wed May 07 09:43:15 2014 +0100 @@ -43,6 +43,7 @@ m_cq(0), m_hqMode(true) { + EM::initialise(); } Silvet::~Silvet()