Mercurial > hg > silvet
changeset 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 | e236bf47ed51 |
children | 2169e7a448c5 df05f855f63b |
files | src/EM.cpp src/EM.h src/Silvet.cpp src/Silvet.h |
diffstat | 4 files changed, 56 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/EM.cpp Tue May 06 18:28:34 2014 +0100 +++ b/src/EM.cpp Tue May 06 18:55:11 2014 +0100 @@ -30,9 +30,10 @@ static double epsilon = 1e-16; -EM::EM() : +EM::EM(bool useShifts) : + m_useShifts(useShifts), m_noteCount(SILVET_TEMPLATE_NOTE_COUNT), - m_shiftCount(SILVET_TEMPLATE_MAX_SHIFT * 2 + 1), + m_shiftCount(useShifts ? SILVET_TEMPLATE_MAX_SHIFT * 2 + 1 : 1), m_binCount(SILVET_TEMPLATE_HEIGHT), m_instrumentCount(SILVET_TEMPLATE_COUNT), m_pitchSparsity(1.1), @@ -50,7 +51,11 @@ for (int f = 0; f < m_shiftCount; ++f) { m_shifts[f] = V(m_noteCount); for (int n = 0; n < m_noteCount; ++n) { - m_shifts[f][n] = drand48(); + if (m_useShifts) { + m_shifts[f][n] = drand48(); + } else { + m_shifts[f][n] = 1.0; + } } } @@ -126,7 +131,12 @@ const float * EM::templateFor(int instrument, int note, int shift) { - return silvet_templates[instrument].data[note] + shift; + if (m_useShifts) { + return silvet_templates[instrument].data[note] + shift; + } else { + return silvet_templates[instrument].data[note] + + SILVET_TEMPLATE_MAX_SHIFT; + } } void @@ -185,21 +195,23 @@ Grid newShifts = m_shifts; - for (int f = 0; f < m_shiftCount; ++f) { - for (int n = 0; n < m_noteCount; ++n) { - newShifts[f][n] = epsilon; - for (int i = 0; i < m_instrumentCount; ++i) { - const float *w = templateFor(i, n, f); - double pitch = m_pitches[n]; - double source = m_sources[i][n]; - double shift = m_shifts[f][n]; - for (int j = 0; j < m_binCount; ++j) { - newShifts[f][n] += w[j] * m_q[j] * pitch * source * shift; + if (m_useShifts) { + for (int f = 0; f < m_shiftCount; ++f) { + for (int n = 0; n < m_noteCount; ++n) { + newShifts[f][n] = epsilon; + for (int i = 0; i < m_instrumentCount; ++i) { + const float *w = templateFor(i, n, f); + double pitch = m_pitches[n]; + double source = m_sources[i][n]; + double shift = m_shifts[f][n]; + for (int j = 0; j < m_binCount; ++j) { + newShifts[f][n] += w[j] * m_q[j] * pitch * source * shift; + } } } } + normaliseGrid(newShifts); } - normaliseGrid(newShifts); Grid newSources = m_sources;
--- a/src/EM.h Tue May 06 18:28:34 2014 +0100 +++ b/src/EM.h Tue May 06 18:55:11 2014 +0100 @@ -21,7 +21,7 @@ class EM { public: - EM(); + EM(bool useShifts); ~EM(); void iterate(std::vector<double> column); @@ -40,6 +40,8 @@ typedef std::vector<double> V; typedef std::vector<std::vector<double> > Grid; + bool m_useShifts; + V m_pitches; Grid m_shifts; Grid m_sources;
--- a/src/Silvet.cpp Tue May 06 18:28:34 2014 +0100 +++ b/src/Silvet.cpp Tue May 06 18:55:11 2014 +0100 @@ -40,7 +40,8 @@ Silvet::Silvet(float inputSampleRate) : Plugin(inputSampleRate), m_resampler(0), - m_cq(0) + m_cq(0), + m_hqMode(false) { } @@ -129,18 +130,39 @@ Silvet::getParameterDescriptors() const { ParameterList list; + + ParameterDescriptor desc; + desc.identifier = "mode"; + desc.name = "Processing mode"; + desc.unit = ""; + desc.description = "Determines the tradeoff of processing speed against transcription quality"; + desc.minValue = 0; + desc.maxValue = 1; + desc.defaultValue = 0; + desc.isQuantized = true; + desc.quantizeStep = 1; + desc.valueNames.push_back("Draft (faster)"); + desc.valueNames.push_back("Intensive (higher quality)"); + list.push_back(desc); + return list; } float Silvet::getParameter(string identifier) const { + if (identifier == "mode") { + return m_hqMode ? 1.f : 0.f; + } return 0; } void Silvet::setParameter(string identifier, float value) { + if (identifier == "mode") { + m_hqMode = (value > 0.5); + } } Silvet::ProgramList @@ -396,7 +418,7 @@ if (sum < 1e-5) continue; - EM em; + EM em(m_hqMode); for (int j = 0; j < iterations; ++j) { em.iterate(filtered[i]); }