Mercurial > hg > vamp-test-plugin
comparison VampTestPlugin.cpp @ 18:014cce47e998
Add an output that returns some actual feature of the input channels (also counting the channels, effectively)
author | Chris Cannam |
---|---|
date | Tue, 02 Dec 2014 18:02:36 +0000 |
parents | ac7f544c7b20 |
children | 534b001d8e8f |
comparison
equal
deleted
inserted
replaced
17:ac7f544c7b20 | 18:014cce47e998 |
---|---|
1 | 1 |
2 | 2 |
3 #include "VampTestPlugin.h" | 3 #include "VampTestPlugin.h" |
4 | 4 |
5 #include <sstream> | 5 #include <sstream> |
6 #include <cmath> | |
6 | 7 |
7 using std::stringstream; | 8 using std::stringstream; |
8 | 9 |
9 using Vamp::RealTime; | 10 using Vamp::RealTime; |
10 | 11 |
11 VampTestPlugin::VampTestPlugin(float inputSampleRate) : | 12 VampTestPlugin::VampTestPlugin(float inputSampleRate) : |
12 Plugin(inputSampleRate), | 13 Plugin(inputSampleRate), |
13 m_produceOutput(true), | 14 m_produceOutput(true), |
14 m_n(0), | 15 m_n(0), |
16 m_channels(1), | |
15 m_stepSize(0), | 17 m_stepSize(0), |
16 m_blockSize(0) | 18 m_blockSize(0) |
17 { | 19 { |
18 for (int i = 0; i < 10; ++i) { | 20 for (int i = 0; i < 10; ++i) { |
19 m_instants.push_back(RealTime::fromSeconds(1.5 * i)); | 21 m_instants.push_back(RealTime::fromSeconds(1.5 * i)); |
85 } | 87 } |
86 | 88 |
87 size_t | 89 size_t |
88 VampTestPlugin::getMaxChannelCount() const | 90 VampTestPlugin::getMaxChannelCount() const |
89 { | 91 { |
90 return 1; | 92 return 10; |
91 } | 93 } |
92 | 94 |
93 VampTestPlugin::ParameterList | 95 VampTestPlugin::ParameterList |
94 VampTestPlugin::getParameterDescriptors() const | 96 VampTestPlugin::getParameterDescriptors() const |
95 { | 97 { |
264 d.sampleRate = 0; | 266 d.sampleRate = 0; |
265 d.hasDuration = true; | 267 d.hasDuration = true; |
266 m_outputNumbers[d.identifier] = n++; | 268 m_outputNumbers[d.identifier] = n++; |
267 list.push_back(d); | 269 list.push_back(d); |
268 | 270 |
271 d.identifier = "rmss"; | |
272 d.name = "RMS of Input Channels"; | |
273 d.description = "RMS levels of each input channel"; | |
274 d.unit = ""; | |
275 d.hasFixedBinCount = true; | |
276 d.binCount = m_channels; | |
277 d.hasKnownExtents = false; | |
278 d.isQuantized = false; | |
279 d.sampleType = OutputDescriptor::OneSamplePerStep; | |
280 d.hasDuration = false; | |
281 m_outputNumbers[d.identifier] = n++; | |
282 list.push_back(d); | |
283 | |
269 return list; | 284 return list; |
270 } | 285 } |
271 | 286 |
272 bool | 287 bool |
273 VampTestPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize) | 288 VampTestPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize) |
274 { | 289 { |
275 if (channels < getMinChannelCount() || | 290 if (channels < getMinChannelCount() || |
276 channels > getMaxChannelCount()) return false; | 291 channels > getMaxChannelCount()) return false; |
277 | 292 |
293 m_channels = channels; | |
278 m_stepSize = stepSize; | 294 m_stepSize = stepSize; |
279 m_blockSize = blockSize; | 295 m_blockSize = blockSize; |
280 | 296 |
281 return true; | 297 return true; |
282 } | 298 } |
469 VampTestPlugin::FeatureSet | 485 VampTestPlugin::FeatureSet |
470 VampTestPlugin::process(const float *const *inputBuffers, RealTime timestamp) | 486 VampTestPlugin::process(const float *const *inputBuffers, RealTime timestamp) |
471 { | 487 { |
472 if (!m_produceOutput) return FeatureSet(); | 488 if (!m_produceOutput) return FeatureSet(); |
473 FeatureSet fs = featuresFrom(timestamp, false); | 489 FeatureSet fs = featuresFrom(timestamp, false); |
490 | |
491 Feature f; | |
492 for (int c = 0; c < m_channels; ++c) { | |
493 float sum = 0.f; | |
494 for (int i = 0; i < m_blockSize; ++i) { | |
495 sum += inputBuffers[c][i] * inputBuffers[c][i]; | |
496 } | |
497 float rms = sqrtf(sum / m_blockSize); | |
498 f.values.push_back(rms); | |
499 } | |
500 fs[m_outputNumbers["rmss"]].push_back(f); | |
501 | |
474 return fs; | 502 return fs; |
475 } | 503 } |
476 | 504 |
477 VampTestPlugin::FeatureSet | 505 VampTestPlugin::FeatureSet |
478 VampTestPlugin::getRemainingFeatures() | 506 VampTestPlugin::getRemainingFeatures() |