Mercurial > hg > qm-vamp-plugins
comparison plugins/KeyDetect.cpp @ 244:ed249a345715
Add tonic strength output, like key strength but without separating major/minor
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Mon, 12 Aug 2019 15:00:45 +0100 |
parents | 3e882621e2dd |
children | a3612b821a0b |
comparison
equal
deleted
inserted
replaced
243:2e12b4a3c47d | 244:ed249a345715 |
---|---|
72 } | 72 } |
73 | 73 |
74 int | 74 int |
75 KeyDetector::getPluginVersion() const | 75 KeyDetector::getPluginVersion() const |
76 { | 76 { |
77 return 5; | 77 return 6; |
78 } | 78 } |
79 | 79 |
80 string | 80 string |
81 KeyDetector::getCopyright() const | 81 KeyDetector::getCopyright() const |
82 { | 82 { |
129 { | 129 { |
130 if (param == "tuning") { | 130 if (param == "tuning") { |
131 return m_tuningFrequency; | 131 return m_tuningFrequency; |
132 } | 132 } |
133 if (param == "length") { | 133 if (param == "length") { |
134 return m_length; | 134 return float(m_length); |
135 } | 135 } |
136 if (param == "rapid") { | 136 if (param == "rapid") { |
137 return m_rapid ? 1.f : 0.f; | 137 return m_rapid ? 1.f : 0.f; |
138 } | 138 } |
139 std::cerr << "WARNING: KeyDetector::getParameter: unknown parameter \"" | 139 std::cerr << "WARNING: KeyDetector::getParameter: unknown parameter \"" |
228 { | 228 { |
229 OutputList list; | 229 OutputList list; |
230 | 230 |
231 float osr = 0.0f; | 231 float osr = 0.0f; |
232 if (m_stepSize == 0) (void)getPreferredStepSize(); | 232 if (m_stepSize == 0) (void)getPreferredStepSize(); |
233 osr = m_inputSampleRate / m_stepSize; | 233 osr = m_inputSampleRate / float(m_stepSize); |
234 | 234 |
235 OutputDescriptor d; | 235 OutputDescriptor d; |
236 d.identifier = "tonic"; | 236 d.identifier = "tonic"; |
237 d.name = "Tonic Pitch"; | 237 d.name = "Tonic Pitch"; |
238 d.unit = ""; | 238 d.unit = ""; |
295 true); | 295 true); |
296 d.binNames.push_back(label); | 296 d.binNames.push_back(label); |
297 } | 297 } |
298 list.push_back(d); | 298 list.push_back(d); |
299 | 299 |
300 d.identifier = "tonicstrength"; | |
301 d.name = "Tonic Strength Plot"; | |
302 d.unit = ""; | |
303 d.description = "Correlation of the chroma vector with stored key profile for each tonic pitch across both major and minor mode"; | |
304 d.hasFixedBinCount = true; | |
305 d.binCount = 12; | |
306 d.hasKnownExtents = false; | |
307 d.isQuantized = false; | |
308 d.sampleType = OutputDescriptor::OneSamplePerStep; | |
309 for (int i = 0; i < 12; ++i) { | |
310 int idx = conversion[i]; | |
311 std::string label = getKeyName(idx > 12 ? idx-12 : idx, | |
312 i >= 12, | |
313 false); | |
314 d.binNames.push_back(label); | |
315 } | |
316 list.push_back(d); | |
317 | |
300 return list; | 318 return list; |
301 } | 319 } |
302 | 320 |
303 KeyDetector::FeatureSet | 321 KeyDetector::FeatureSet |
304 KeyDetector::process(const float *const *inputBuffers, | 322 KeyDetector::process(const float *const *inputBuffers, |
354 | 372 |
355 m_prevKey = key; | 373 m_prevKey = key; |
356 m_first = false; | 374 m_first = false; |
357 | 375 |
358 Feature ksf; | 376 Feature ksf; |
377 ksf.hasTimestamp = false; | |
359 ksf.values.reserve(25); | 378 ksf.values.reserve(25); |
379 | |
380 Feature tsf; | |
381 tsf.hasTimestamp = false; | |
382 tsf.values.reserve(12); | |
383 | |
360 double *keystrengths = m_getKeyMode->getKeyStrengths(); | 384 double *keystrengths = m_getKeyMode->getKeyStrengths(); |
385 | |
361 for (int i = 0; i < 24; ++i) { | 386 for (int i = 0; i < 24; ++i) { |
387 | |
362 if (i == 12) ksf.values.push_back(-1); | 388 if (i == 12) ksf.values.push_back(-1); |
363 ksf.values.push_back(keystrengths[conversion[i]-1]); | 389 ksf.values.push_back(float(keystrengths[conversion[i]-1])); |
364 } | 390 |
365 ksf.hasTimestamp = false; | 391 if (i < 12) { |
392 tsf.values.push_back(float(keystrengths[conversion[i]-1])); | |
393 } else { | |
394 tsf.values[i-12] += float(keystrengths[conversion[i]-1]); | |
395 } | |
396 } | |
397 | |
366 returnFeatures[3].push_back(ksf); | 398 returnFeatures[3].push_back(ksf); |
399 returnFeatures[4].push_back(tsf); | |
367 | 400 |
368 return returnFeatures; | 401 return returnFeatures; |
369 } | 402 } |
370 | 403 |
371 KeyDetector::FeatureSet | 404 KeyDetector::FeatureSet |