Mercurial > hg > tuning-difference
changeset 29:409ff482cb30
Add max-duration parameter. The results are often going to be quite wrong if you use this, simply because the two performances may be at different speeds and so the same duration of each may represent a different (sub-)performance. But it's sometimes necessary just to avoid blowing the thing up.
author | Chris Cannam |
---|---|
date | Fri, 27 Mar 2015 17:20:40 +0000 |
parents | c21ce05afbe4 |
children | 917a0e72c692 |
files | src/TuningDifference.cpp src/TuningDifference.h |
diffstat | 2 files changed, 32 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/TuningDifference.cpp Fri Mar 13 15:03:54 2015 +0000 +++ b/src/TuningDifference.cpp Fri Mar 27 17:20:40 2015 +0000 @@ -34,12 +34,15 @@ return pitchToFrequency(69, cents, 440.); } +static float defaultMaxDuration = 0; + TuningDifference::TuningDifference(float inputSampleRate) : Plugin(inputSampleRate), m_bpo(60), m_refChroma(new Chromagram(paramsForTuningFrequency(440.))), m_blockSize(0), - m_frameCount(0) + m_frameCount(0), + m_maxDuration(defaultMaxDuration) { } @@ -125,21 +128,40 @@ TuningDifference::getParameterDescriptors() const { ParameterList list; + + ParameterDescriptor desc; + + desc.identifier = "maxduration"; + desc.name = "Maximum duration to analyse"; + desc.description = "The maximum duration (in seconds) to consider from either input file. Zero means there is no limit."; + desc.minValue = 0; + desc.maxValue = 3600; + desc.defaultValue = defaultMaxDuration; + desc.isQuantized = false; + desc.unit = "s"; + list.push_back(desc); + //!!! parameter: max search range //!!! parameter: fine search precision - //!!! parameter: max total duration to listen to + return list; } float -TuningDifference::getParameter(string) const +TuningDifference::getParameter(string id) const { + if (id == "maxduration") { + return m_maxDuration; + } return 0; } void -TuningDifference::setParameter(string, float) +TuningDifference::setParameter(string id, float value) { + if (id == "maxduration") { + m_maxDuration = value; + } } TuningDifference::ProgramList @@ -339,6 +361,11 @@ TuningDifference::FeatureSet TuningDifference::process(const float *const *inputBuffers, Vamp::RealTime) { + if (m_maxDuration > 0) { + int maxFrames = (m_maxDuration * m_inputSampleRate) / m_blockSize; + if (m_frameCount > maxFrames) return FeatureSet(); + } + CQBase::RealBlock block; CQBase::RealSequence input;
--- a/src/TuningDifference.h Fri Mar 13 15:03:54 2015 +0000 +++ b/src/TuningDifference.h Fri Mar 27 17:20:40 2015 +0000 @@ -70,6 +70,7 @@ Signal m_other; int m_blockSize; int m_frameCount; + float m_maxDuration; Chromagram::Parameters paramsForTuningFrequency(double hz) const; TFeature computeFeatureFromTotals(const TFeature &totals) const;