Mercurial > hg > silvet
changeset 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 | ef266e31534f |
children | 88e6066e80b5 |
files | .hgsubstate src/EM.cpp |
diffstat | 2 files changed, 40 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgsubstate Thu May 08 09:34:22 2014 +0100 +++ b/.hgsubstate Thu May 08 09:47:18 2014 +0100 @@ -1,2 +1,2 @@ a2621605a8c2119bb063c59e83f4fe792a58e4ac bqvec -7d97986563a0b3104a5c3f88190350ae55528738 constant-q-cpp +4cb16296f14156f59bc6c716fb67767f53d67028 constant-q-cpp
--- a/src/EM.cpp Thu May 08 09:34:22 2014 +0100 +++ b/src/EM.cpp Thu May 08 09:47:18 2014 +0100 @@ -155,14 +155,26 @@ v_set(m_estimate, epsilon, m_binCount); - for (int i = 0; i < m_sourceCount; ++i) { - for (int n = 0; n < m_noteCount; ++n) { - const double pitch = m_pitches[n]; - const double source = m_sources[i][n]; - for (int f = 0; f < m_shiftCount; ++f) { + for (int f = 0; f < m_shiftCount; ++f) { + + const double *shiftIn = m_shifts ? m_shifts[f] : 0; + + for (int i = 0; i < m_sourceCount; ++i) { + + const double *sourceIn = m_sources[i]; + + int lowest, highest; + rangeFor(i, lowest, highest); + + for (int n = lowest; n <= highest; ++n) { + + const double source = sourceIn[n]; + const double shift = shiftIn ? shiftIn[n] : 1.0; + const double pitch = m_pitches[n]; + + const double factor = pitch * source * shift; const double *w = templateFor(i, n, f); - const double shift = m_shifts ? m_shifts[f][n] : 1.0; - const double factor = pitch * source * shift; + v_add_with_gain(m_estimate, w, factor, m_binCount); } } @@ -190,17 +202,25 @@ double *contributions = allocate<double>(m_binCount); - for (int n = 0; n < m_noteCount; ++n) { + for (int f = 0; f < m_shiftCount; ++f) { - const double pitch = m_pitches[n]; + const double *shiftIn = m_shifts ? m_shifts[f] : 0; + double *shiftOut = m_shifts ? m_updateShifts[f] : 0; - for (int f = 0; f < m_shiftCount; ++f) { + for (int i = 0; i < m_sourceCount; ++i) { - const double shift = m_shifts ? m_shifts[f][n] : 1.0; + const double *sourceIn = m_sources[i]; + double *sourceOut = m_updateSources[i]; - for (int i = 0; i < m_sourceCount; ++i) { + int lowest, highest; + rangeFor(i, lowest, highest); - const double source = m_sources[i][n]; + for (int n = lowest; n <= highest; ++n) { + + const double shift = shiftIn ? shiftIn[n] : 1.0; + const double source = sourceIn[n]; + const double pitch = m_pitches[n]; + const double factor = pitch * source * shift; const double *w = templateFor(i, n, f); @@ -209,17 +229,11 @@ double total = factor * v_sum(contributions, m_binCount); - if (n >= m_lowestPitch && n <= m_highestPitch) { + m_updatePitches[n] += total; + sourceOut[n] += total; - m_updatePitches[n] += total; - - if (inRange(i, n)) { - m_updateSources[i][n] += total; - } - } - - if (m_shifts) { - m_updateShifts[f][n] += total; + if (shiftOut) { + shiftOut[n] += total; } } } @@ -233,8 +247,8 @@ } if (m_sourceSparsity != 1.0) { - for (int n = 0; n < m_noteCount; ++n) { - for (int i = 0; i < m_sourceCount; ++i) { + for (int i = 0; i < m_sourceCount; ++i) { + for (int n = 0; n < m_noteCount; ++n) { m_updateSources[i][n] = pow(m_updateSources[i][n], m_sourceSparsity); }