Mercurial > hg > silvet
comparison src/EM.cpp @ 130:f25b8e7de0ed
Include in sum only the notes actually in range for an instrument (the other templates should be all zeros anyway)
author | Chris Cannam |
---|---|
date | Thu, 08 May 2014 09:47:18 +0100 |
parents | 7377032e0bf1 |
children | d2bc51cc7f57 |
comparison
equal
deleted
inserted
replaced
129:ef266e31534f | 130:f25b8e7de0ed |
---|---|
153 { | 153 { |
154 // cerr << "."; | 154 // cerr << "."; |
155 | 155 |
156 v_set(m_estimate, epsilon, m_binCount); | 156 v_set(m_estimate, epsilon, m_binCount); |
157 | 157 |
158 for (int i = 0; i < m_sourceCount; ++i) { | 158 for (int f = 0; f < m_shiftCount; ++f) { |
159 for (int n = 0; n < m_noteCount; ++n) { | 159 |
160 const double pitch = m_pitches[n]; | 160 const double *shiftIn = m_shifts ? m_shifts[f] : 0; |
161 const double source = m_sources[i][n]; | 161 |
162 for (int f = 0; f < m_shiftCount; ++f) { | 162 for (int i = 0; i < m_sourceCount; ++i) { |
163 | |
164 const double *sourceIn = m_sources[i]; | |
165 | |
166 int lowest, highest; | |
167 rangeFor(i, lowest, highest); | |
168 | |
169 for (int n = lowest; n <= highest; ++n) { | |
170 | |
171 const double source = sourceIn[n]; | |
172 const double shift = shiftIn ? shiftIn[n] : 1.0; | |
173 const double pitch = m_pitches[n]; | |
174 | |
175 const double factor = pitch * source * shift; | |
163 const double *w = templateFor(i, n, f); | 176 const double *w = templateFor(i, n, f); |
164 const double shift = m_shifts ? m_shifts[f][n] : 1.0; | 177 |
165 const double factor = pitch * source * shift; | |
166 v_add_with_gain(m_estimate, w, factor, m_binCount); | 178 v_add_with_gain(m_estimate, w, factor, m_binCount); |
167 } | 179 } |
168 } | 180 } |
169 } | 181 } |
170 | 182 |
188 } | 200 } |
189 } | 201 } |
190 | 202 |
191 double *contributions = allocate<double>(m_binCount); | 203 double *contributions = allocate<double>(m_binCount); |
192 | 204 |
193 for (int n = 0; n < m_noteCount; ++n) { | 205 for (int f = 0; f < m_shiftCount; ++f) { |
194 | 206 |
195 const double pitch = m_pitches[n]; | 207 const double *shiftIn = m_shifts ? m_shifts[f] : 0; |
196 | 208 double *shiftOut = m_shifts ? m_updateShifts[f] : 0; |
197 for (int f = 0; f < m_shiftCount; ++f) { | 209 |
198 | 210 for (int i = 0; i < m_sourceCount; ++i) { |
199 const double shift = m_shifts ? m_shifts[f][n] : 1.0; | 211 |
200 | 212 const double *sourceIn = m_sources[i]; |
201 for (int i = 0; i < m_sourceCount; ++i) { | 213 double *sourceOut = m_updateSources[i]; |
202 | 214 |
203 const double source = m_sources[i][n]; | 215 int lowest, highest; |
216 rangeFor(i, lowest, highest); | |
217 | |
218 for (int n = lowest; n <= highest; ++n) { | |
219 | |
220 const double shift = shiftIn ? shiftIn[n] : 1.0; | |
221 const double source = sourceIn[n]; | |
222 const double pitch = m_pitches[n]; | |
223 | |
204 const double factor = pitch * source * shift; | 224 const double factor = pitch * source * shift; |
205 const double *w = templateFor(i, n, f); | 225 const double *w = templateFor(i, n, f); |
206 | 226 |
207 v_copy(contributions, w, m_binCount); | 227 v_copy(contributions, w, m_binCount); |
208 v_multiply(contributions, m_q, m_binCount); | 228 v_multiply(contributions, m_q, m_binCount); |
209 | 229 |
210 double total = factor * v_sum(contributions, m_binCount); | 230 double total = factor * v_sum(contributions, m_binCount); |
211 | 231 |
212 if (n >= m_lowestPitch && n <= m_highestPitch) { | 232 m_updatePitches[n] += total; |
213 | 233 sourceOut[n] += total; |
214 m_updatePitches[n] += total; | 234 |
215 | 235 if (shiftOut) { |
216 if (inRange(i, n)) { | 236 shiftOut[n] += total; |
217 m_updateSources[i][n] += total; | |
218 } | |
219 } | |
220 | |
221 if (m_shifts) { | |
222 m_updateShifts[f][n] += total; | |
223 } | 237 } |
224 } | 238 } |
225 } | 239 } |
226 } | 240 } |
227 | 241 |
231 pow(m_updatePitches[n], m_pitchSparsity); | 245 pow(m_updatePitches[n], m_pitchSparsity); |
232 } | 246 } |
233 } | 247 } |
234 | 248 |
235 if (m_sourceSparsity != 1.0) { | 249 if (m_sourceSparsity != 1.0) { |
236 for (int n = 0; n < m_noteCount; ++n) { | 250 for (int i = 0; i < m_sourceCount; ++i) { |
237 for (int i = 0; i < m_sourceCount; ++i) { | 251 for (int n = 0; n < m_noteCount; ++n) { |
238 m_updateSources[i][n] = | 252 m_updateSources[i][n] = |
239 pow(m_updateSources[i][n], m_sourceSparsity); | 253 pow(m_updateSources[i][n], m_sourceSparsity); |
240 } | 254 } |
241 } | 255 } |
242 } | 256 } |