Mercurial > hg > tuning-difference
comparison src/TuningDifference.cpp @ 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 | 86695c191896 |
comparison
equal
deleted
inserted
replaced
28:c21ce05afbe4 | 29:409ff482cb30 |
---|---|
32 static double frequencyForCentsAbove440(double cents) | 32 static double frequencyForCentsAbove440(double cents) |
33 { | 33 { |
34 return pitchToFrequency(69, cents, 440.); | 34 return pitchToFrequency(69, cents, 440.); |
35 } | 35 } |
36 | 36 |
37 static float defaultMaxDuration = 0; | |
38 | |
37 TuningDifference::TuningDifference(float inputSampleRate) : | 39 TuningDifference::TuningDifference(float inputSampleRate) : |
38 Plugin(inputSampleRate), | 40 Plugin(inputSampleRate), |
39 m_bpo(60), | 41 m_bpo(60), |
40 m_refChroma(new Chromagram(paramsForTuningFrequency(440.))), | 42 m_refChroma(new Chromagram(paramsForTuningFrequency(440.))), |
41 m_blockSize(0), | 43 m_blockSize(0), |
42 m_frameCount(0) | 44 m_frameCount(0), |
45 m_maxDuration(defaultMaxDuration) | |
43 { | 46 { |
44 } | 47 } |
45 | 48 |
46 TuningDifference::~TuningDifference() | 49 TuningDifference::~TuningDifference() |
47 { | 50 { |
123 | 126 |
124 TuningDifference::ParameterList | 127 TuningDifference::ParameterList |
125 TuningDifference::getParameterDescriptors() const | 128 TuningDifference::getParameterDescriptors() const |
126 { | 129 { |
127 ParameterList list; | 130 ParameterList list; |
131 | |
132 ParameterDescriptor desc; | |
133 | |
134 desc.identifier = "maxduration"; | |
135 desc.name = "Maximum duration to analyse"; | |
136 desc.description = "The maximum duration (in seconds) to consider from either input file. Zero means there is no limit."; | |
137 desc.minValue = 0; | |
138 desc.maxValue = 3600; | |
139 desc.defaultValue = defaultMaxDuration; | |
140 desc.isQuantized = false; | |
141 desc.unit = "s"; | |
142 list.push_back(desc); | |
143 | |
128 //!!! parameter: max search range | 144 //!!! parameter: max search range |
129 //!!! parameter: fine search precision | 145 //!!! parameter: fine search precision |
130 //!!! parameter: max total duration to listen to | 146 |
131 return list; | 147 return list; |
132 } | 148 } |
133 | 149 |
134 float | 150 float |
135 TuningDifference::getParameter(string) const | 151 TuningDifference::getParameter(string id) const |
136 { | 152 { |
153 if (id == "maxduration") { | |
154 return m_maxDuration; | |
155 } | |
137 return 0; | 156 return 0; |
138 } | 157 } |
139 | 158 |
140 void | 159 void |
141 TuningDifference::setParameter(string, float) | 160 TuningDifference::setParameter(string id, float value) |
142 { | 161 { |
162 if (id == "maxduration") { | |
163 m_maxDuration = value; | |
164 } | |
143 } | 165 } |
144 | 166 |
145 TuningDifference::ProgramList | 167 TuningDifference::ProgramList |
146 TuningDifference::getPrograms() const | 168 TuningDifference::getPrograms() const |
147 { | 169 { |
337 } | 359 } |
338 | 360 |
339 TuningDifference::FeatureSet | 361 TuningDifference::FeatureSet |
340 TuningDifference::process(const float *const *inputBuffers, Vamp::RealTime) | 362 TuningDifference::process(const float *const *inputBuffers, Vamp::RealTime) |
341 { | 363 { |
364 if (m_maxDuration > 0) { | |
365 int maxFrames = (m_maxDuration * m_inputSampleRate) / m_blockSize; | |
366 if (m_frameCount > maxFrames) return FeatureSet(); | |
367 } | |
368 | |
342 CQBase::RealBlock block; | 369 CQBase::RealBlock block; |
343 CQBase::RealSequence input; | 370 CQBase::RealSequence input; |
344 | 371 |
345 input = CQBase::RealSequence | 372 input = CQBase::RealSequence |
346 (inputBuffers[0], inputBuffers[0] + m_blockSize); | 373 (inputBuffers[0], inputBuffers[0] + m_blockSize); |