# HG changeset patch # User Chris Cannam # Date 1427476840 0 # Node ID 409ff482cb3028e689a400a688a539f7dc96e342 # Parent c21ce05afbe4bb441a564bd9dd9140e1829e8b2a 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. diff -r c21ce05afbe4 -r 409ff482cb30 src/TuningDifference.cpp --- 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; diff -r c21ce05afbe4 -r 409ff482cb30 src/TuningDifference.h --- 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;