comparison src/EM.cpp @ 83:a0dedcbfa628 timing

Hoist variables, add consts
author Chris Cannam
date Tue, 06 May 2014 11:53:02 +0100
parents 3e7e3c610fae
children 64b08cc12da0
comparison
equal deleted inserted replaced
81:3f260f426039 83:a0dedcbfa628
34 m_noteCount(SILVET_TEMPLATE_NOTE_COUNT), 34 m_noteCount(SILVET_TEMPLATE_NOTE_COUNT),
35 m_shiftCount(SILVET_TEMPLATE_MAX_SHIFT * 2 + 1), 35 m_shiftCount(SILVET_TEMPLATE_MAX_SHIFT * 2 + 1),
36 m_binCount(SILVET_TEMPLATE_HEIGHT), 36 m_binCount(SILVET_TEMPLATE_HEIGHT),
37 m_instrumentCount(SILVET_TEMPLATE_COUNT), 37 m_instrumentCount(SILVET_TEMPLATE_COUNT),
38 m_pitchSparsity(1.1), 38 m_pitchSparsity(1.1),
39 m_sourceSparsity(1.3) 39 m_sourceSparsity(1.3),
40 { 40 m_lowestPitch(silvet_templates_lowest_note),
41 m_lowestPitch = silvet_templates_lowest_note; 41 m_highestPitch(silvet_templates_highest_note)
42 m_highestPitch = silvet_templates_highest_note; 42 {
43
44 m_pitches = V(m_noteCount); 43 m_pitches = V(m_noteCount);
45 for (int n = 0; n < m_noteCount; ++n) { 44 for (int n = 0; n < m_noteCount; ++n) {
46 m_pitches[n] = drand48(); 45 m_pitches[n] = drand48();
47 } 46 }
48 47
138 m_estimate[i] = epsilon; 137 m_estimate[i] = epsilon;
139 } 138 }
140 139
141 for (int i = 0; i < m_instrumentCount; ++i) { 140 for (int i = 0; i < m_instrumentCount; ++i) {
142 for (int n = 0; n < m_noteCount; ++n) { 141 for (int n = 0; n < m_noteCount; ++n) {
142 const double pitch = m_pitches[n];
143 const double source = m_sources[i][n];
143 for (int f = 0; f < m_shiftCount; ++f) { 144 for (int f = 0; f < m_shiftCount; ++f) {
144 const float *w = templateFor(i, n, f); 145 const float *w = templateFor(i, n, f);
145 double pitch = m_pitches[n]; 146 const double shift = m_shifts[f][n];
146 double source = m_sources[i][n]; 147 const double factor = pitch * source * shift;
147 double shift = m_shifts[f][n];
148 for (int j = 0; j < m_binCount; ++j) { 148 for (int j = 0; j < m_binCount; ++j) {
149 m_estimate[j] += w[j] * pitch * source * shift; 149 m_estimate[j] += w[j] * factor;
150 } 150 }
151 } 151 }
152 } 152 }
153 } 153 }
154 154
163 V newPitches = m_pitches; 163 V newPitches = m_pitches;
164 164
165 for (int n = 0; n < m_noteCount; ++n) { 165 for (int n = 0; n < m_noteCount; ++n) {
166 newPitches[n] = epsilon; 166 newPitches[n] = epsilon;
167 if (n >= m_lowestPitch && n <= m_highestPitch) { 167 if (n >= m_lowestPitch && n <= m_highestPitch) {
168 const double pitch = m_pitches[n];
168 for (int i = 0; i < m_instrumentCount; ++i) { 169 for (int i = 0; i < m_instrumentCount; ++i) {
170 const double source = m_sources[i][n];
169 for (int f = 0; f < m_shiftCount; ++f) { 171 for (int f = 0; f < m_shiftCount; ++f) {
170 const float *w = templateFor(i, n, f); 172 const float *w = templateFor(i, n, f);
171 double pitch = m_pitches[n]; 173 const double shift = m_shifts[f][n];
172 double source = m_sources[i][n]; 174 const double factor = pitch * source * shift;
173 double shift = m_shifts[f][n];
174 for (int j = 0; j < m_binCount; ++j) { 175 for (int j = 0; j < m_binCount; ++j) {
175 newPitches[n] += w[j] * m_q[j] * pitch * source * shift; 176 newPitches[n] += w[j] * m_q[j] * factor;
176 } 177 }
177 } 178 }
178 } 179 }
179 } 180 }
180 if (m_pitchSparsity != 1.0) { 181 if (m_pitchSparsity != 1.0) {
185 186
186 Grid newShifts = m_shifts; 187 Grid newShifts = m_shifts;
187 188
188 for (int f = 0; f < m_shiftCount; ++f) { 189 for (int f = 0; f < m_shiftCount; ++f) {
189 for (int n = 0; n < m_noteCount; ++n) { 190 for (int n = 0; n < m_noteCount; ++n) {
191 const double pitch = m_pitches[n];
192 const double shift = m_shifts[f][n];
190 newShifts[f][n] = epsilon; 193 newShifts[f][n] = epsilon;
191 for (int i = 0; i < m_instrumentCount; ++i) { 194 for (int i = 0; i < m_instrumentCount; ++i) {
192 const float *w = templateFor(i, n, f); 195 const float *w = templateFor(i, n, f);
193 double pitch = m_pitches[n]; 196 const double source = m_sources[i][n];
194 double source = m_sources[i][n]; 197 const double factor = pitch * source * shift;
195 double shift = m_shifts[f][n];
196 for (int j = 0; j < m_binCount; ++j) { 198 for (int j = 0; j < m_binCount; ++j) {
197 newShifts[f][n] += w[j] * m_q[j] * pitch * source * shift; 199 newShifts[f][n] += w[j] * m_q[j] * factor;
198 } 200 }
199 } 201 }
200 } 202 }
201 } 203 }
202 normaliseGrid(newShifts); 204 normaliseGrid(newShifts);
203 205
204 Grid newSources = m_sources; 206 Grid newSources = m_sources;
205 207
206 for (int i = 0; i < m_instrumentCount; ++i) { 208 for (int i = 0; i < m_instrumentCount; ++i) {
207 for (int n = 0; n < m_noteCount; ++n) { 209 for (int n = 0; n < m_noteCount; ++n) {
210 const double pitch = m_pitches[n];
211 const double source = m_sources[i][n];
208 newSources[i][n] = epsilon; 212 newSources[i][n] = epsilon;
209 if (inRange(i, n)) { 213 if (inRange(i, n)) {
210 for (int f = 0; f < m_shiftCount; ++f) { 214 for (int f = 0; f < m_shiftCount; ++f) {
211 const float *w = templateFor(i, n, f); 215 const float *w = templateFor(i, n, f);
212 double pitch = m_pitches[n]; 216 const double shift = m_shifts[f][n];
213 double source = m_sources[i][n]; 217 const double factor = pitch * source * shift;
214 double shift = m_shifts[f][n];
215 for (int j = 0; j < m_binCount; ++j) { 218 for (int j = 0; j < m_binCount; ++j) {
216 newSources[i][n] += w[j] * m_q[j] * pitch * source * shift; 219 newSources[i][n] += w[j] * m_q[j] * factor;
217 } 220 }
218 } 221 }
219 } 222 }
220 if (m_sourceSparsity != 1.0) { 223 if (m_sourceSparsity != 1.0) {
221 newSources[i][n] = pow(newSources[i][n], m_sourceSparsity); 224 newSources[i][n] = pow(newSources[i][n], m_sourceSparsity);