Mercurial > hg > silvet
comparison src/EM.cpp @ 112:2169e7a448c5 bqvec-openmp
Merge from default branch
author | Chris Cannam |
---|---|
date | Wed, 07 May 2014 09:01:32 +0100 |
parents | 9b299b087dd4 e282930cfca7 |
children | c4eae816bdb3 |
comparison
equal
deleted
inserted
replaced
111:9b299b087dd4 | 112:2169e7a448c5 |
---|---|
31 | 31 |
32 using namespace breakfastquay; | 32 using namespace breakfastquay; |
33 | 33 |
34 static double epsilon = 1e-16; | 34 static double epsilon = 1e-16; |
35 | 35 |
36 EM::EM() : | 36 EM::EM(bool useShifts) : |
37 m_useShifts(useShifts), | |
37 m_noteCount(SILVET_TEMPLATE_NOTE_COUNT), | 38 m_noteCount(SILVET_TEMPLATE_NOTE_COUNT), |
38 m_shiftCount(SILVET_TEMPLATE_MAX_SHIFT * 2 + 1), | 39 m_shiftCount(useShifts ? SILVET_TEMPLATE_MAX_SHIFT * 2 + 1 : 1), |
39 m_binCount(SILVET_TEMPLATE_HEIGHT), | 40 m_binCount(SILVET_TEMPLATE_HEIGHT), |
40 m_sourceCount(SILVET_TEMPLATE_COUNT), | 41 m_sourceCount(SILVET_TEMPLATE_COUNT), |
41 m_pitchSparsity(1.1), | 42 m_pitchSparsity(1.1), |
42 m_sourceSparsity(1.3), | 43 m_sourceSparsity(1.3), |
43 m_lowestPitch(silvet_templates_lowest_note), | 44 m_lowestPitch(silvet_templates_lowest_note), |
51 | 52 |
52 m_shifts = allocate_channels<double>(m_shiftCount, m_noteCount); | 53 m_shifts = allocate_channels<double>(m_shiftCount, m_noteCount); |
53 m_updateShifts = allocate_channels<double>(m_shiftCount, m_noteCount); | 54 m_updateShifts = allocate_channels<double>(m_shiftCount, m_noteCount); |
54 for (int f = 0; f < m_shiftCount; ++f) { | 55 for (int f = 0; f < m_shiftCount; ++f) { |
55 for (int n = 0; n < m_noteCount; ++n) { | 56 for (int n = 0; n < m_noteCount; ++n) { |
56 m_shifts[f][n] = drand48(); | 57 if (m_useShifts) { |
58 m_shifts[f][n] = drand48(); | |
59 } else { | |
60 m_shifts[f][n] = 1.0; | |
61 } | |
57 } | 62 } |
58 } | 63 } |
59 | 64 |
60 m_sources = allocate_channels<double>(m_sourceCount, m_noteCount); | 65 m_sources = allocate_channels<double>(m_sourceCount, m_noteCount); |
61 m_updateSources = allocate_channels<double>(m_sourceCount, m_noteCount); | 66 m_updateSources = allocate_channels<double>(m_sourceCount, m_noteCount); |
133 } | 138 } |
134 | 139 |
135 const double * | 140 const double * |
136 EM::templateFor(int instrument, int note, int shift) | 141 EM::templateFor(int instrument, int note, int shift) |
137 { | 142 { |
138 return silvet_templates[instrument].data[note] + shift; | 143 if (m_useShifts) { |
144 return silvet_templates[instrument].data[note] + shift; | |
145 } else { | |
146 return silvet_templates[instrument].data[note] + | |
147 SILVET_TEMPLATE_MAX_SHIFT; | |
148 } | |
139 } | 149 } |
140 | 150 |
141 void | 151 void |
142 EM::expectation(const double *column) | 152 EM::expectation(const double *column) |
143 { | 153 { |
225 } | 235 } |
226 } | 236 } |
227 } | 237 } |
228 | 238 |
229 normaliseColumn(m_updatePitches, m_noteCount); | 239 normaliseColumn(m_updatePitches, m_noteCount); |
230 normaliseGrid(m_updateShifts, m_shiftCount, m_noteCount); | 240 std::swap(m_pitches, m_updatePitches); |
241 | |
242 if (m_useShifts) { | |
243 normaliseGrid(m_updateShifts, m_shiftCount, m_noteCount); | |
244 std::swap(m_shifts, m_updateShifts); | |
245 } | |
246 | |
231 normaliseGrid(m_updateSources, m_sourceCount, m_noteCount); | 247 normaliseGrid(m_updateSources, m_sourceCount, m_noteCount); |
232 | |
233 std::swap(m_pitches, m_updatePitches); | |
234 std::swap(m_shifts, m_updateShifts); | |
235 std::swap(m_sources, m_updateSources); | 248 std::swap(m_sources, m_updateSources); |
236 } | 249 } |
237 | 250 |
238 | 251 |