Mercurial > hg > silvet
comparison src/EM.cpp @ 110:e282930cfca7
Add draft/intensive mode setting (determines whether to use shifts)
author | Chris Cannam |
---|---|
date | Tue, 06 May 2014 18:55:11 +0100 |
parents | 3e7e3c610fae |
children | 2169e7a448c5 |
comparison
equal
deleted
inserted
replaced
109:e236bf47ed51 | 110:e282930cfca7 |
---|---|
28 using std::cerr; | 28 using std::cerr; |
29 using std::endl; | 29 using std::endl; |
30 | 30 |
31 static double epsilon = 1e-16; | 31 static double epsilon = 1e-16; |
32 | 32 |
33 EM::EM() : | 33 EM::EM(bool useShifts) : |
34 m_useShifts(useShifts), | |
34 m_noteCount(SILVET_TEMPLATE_NOTE_COUNT), | 35 m_noteCount(SILVET_TEMPLATE_NOTE_COUNT), |
35 m_shiftCount(SILVET_TEMPLATE_MAX_SHIFT * 2 + 1), | 36 m_shiftCount(useShifts ? SILVET_TEMPLATE_MAX_SHIFT * 2 + 1 : 1), |
36 m_binCount(SILVET_TEMPLATE_HEIGHT), | 37 m_binCount(SILVET_TEMPLATE_HEIGHT), |
37 m_instrumentCount(SILVET_TEMPLATE_COUNT), | 38 m_instrumentCount(SILVET_TEMPLATE_COUNT), |
38 m_pitchSparsity(1.1), | 39 m_pitchSparsity(1.1), |
39 m_sourceSparsity(1.3) | 40 m_sourceSparsity(1.3) |
40 { | 41 { |
48 | 49 |
49 m_shifts = Grid(m_shiftCount); | 50 m_shifts = Grid(m_shiftCount); |
50 for (int f = 0; f < m_shiftCount; ++f) { | 51 for (int f = 0; f < m_shiftCount; ++f) { |
51 m_shifts[f] = V(m_noteCount); | 52 m_shifts[f] = V(m_noteCount); |
52 for (int n = 0; n < m_noteCount; ++n) { | 53 for (int n = 0; n < m_noteCount; ++n) { |
53 m_shifts[f][n] = drand48(); | 54 if (m_useShifts) { |
55 m_shifts[f][n] = drand48(); | |
56 } else { | |
57 m_shifts[f][n] = 1.0; | |
58 } | |
54 } | 59 } |
55 } | 60 } |
56 | 61 |
57 m_sources = Grid(m_instrumentCount); | 62 m_sources = Grid(m_instrumentCount); |
58 for (int i = 0; i < m_instrumentCount; ++i) { | 63 for (int i = 0; i < m_instrumentCount; ++i) { |
124 } | 129 } |
125 | 130 |
126 const float * | 131 const float * |
127 EM::templateFor(int instrument, int note, int shift) | 132 EM::templateFor(int instrument, int note, int shift) |
128 { | 133 { |
129 return silvet_templates[instrument].data[note] + shift; | 134 if (m_useShifts) { |
135 return silvet_templates[instrument].data[note] + shift; | |
136 } else { | |
137 return silvet_templates[instrument].data[note] + | |
138 SILVET_TEMPLATE_MAX_SHIFT; | |
139 } | |
130 } | 140 } |
131 | 141 |
132 void | 142 void |
133 EM::expectation(const V &column) | 143 EM::expectation(const V &column) |
134 { | 144 { |
183 } | 193 } |
184 normaliseColumn(newPitches); | 194 normaliseColumn(newPitches); |
185 | 195 |
186 Grid newShifts = m_shifts; | 196 Grid newShifts = m_shifts; |
187 | 197 |
188 for (int f = 0; f < m_shiftCount; ++f) { | 198 if (m_useShifts) { |
189 for (int n = 0; n < m_noteCount; ++n) { | 199 for (int f = 0; f < m_shiftCount; ++f) { |
190 newShifts[f][n] = epsilon; | 200 for (int n = 0; n < m_noteCount; ++n) { |
191 for (int i = 0; i < m_instrumentCount; ++i) { | 201 newShifts[f][n] = epsilon; |
192 const float *w = templateFor(i, n, f); | 202 for (int i = 0; i < m_instrumentCount; ++i) { |
193 double pitch = m_pitches[n]; | 203 const float *w = templateFor(i, n, f); |
194 double source = m_sources[i][n]; | 204 double pitch = m_pitches[n]; |
195 double shift = m_shifts[f][n]; | 205 double source = m_sources[i][n]; |
196 for (int j = 0; j < m_binCount; ++j) { | 206 double shift = m_shifts[f][n]; |
197 newShifts[f][n] += w[j] * m_q[j] * pitch * source * shift; | 207 for (int j = 0; j < m_binCount; ++j) { |
198 } | 208 newShifts[f][n] += w[j] * m_q[j] * pitch * source * shift; |
199 } | 209 } |
200 } | 210 } |
201 } | 211 } |
202 normaliseGrid(newShifts); | 212 } |
213 normaliseGrid(newShifts); | |
214 } | |
203 | 215 |
204 Grid newSources = m_sources; | 216 Grid newSources = m_sources; |
205 | 217 |
206 for (int i = 0; i < m_instrumentCount; ++i) { | 218 for (int i = 0; i < m_instrumentCount; ++i) { |
207 for (int n = 0; n < m_noteCount; ++n) { | 219 for (int n = 0; n < m_noteCount; ++n) { |