Mercurial > hg > vamp-test-plugin
changeset 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 |
files | VampTestPlugin.cpp VampTestPlugin.h |
diffstat | 2 files changed, 30 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/VampTestPlugin.cpp Tue Nov 25 12:00:52 2014 +0000 +++ b/VampTestPlugin.cpp Tue Dec 02 18:02:36 2014 +0000 @@ -3,6 +3,7 @@ #include "VampTestPlugin.h" #include <sstream> +#include <cmath> using std::stringstream; @@ -12,6 +13,7 @@ Plugin(inputSampleRate), m_produceOutput(true), m_n(0), + m_channels(1), m_stepSize(0), m_blockSize(0) { @@ -87,7 +89,7 @@ size_t VampTestPlugin::getMaxChannelCount() const { - return 1; + return 10; } VampTestPlugin::ParameterList @@ -266,6 +268,19 @@ m_outputNumbers[d.identifier] = n++; list.push_back(d); + d.identifier = "rmss"; + d.name = "RMS of Input Channels"; + d.description = "RMS levels of each input channel"; + d.unit = ""; + d.hasFixedBinCount = true; + d.binCount = m_channels; + d.hasKnownExtents = false; + d.isQuantized = false; + d.sampleType = OutputDescriptor::OneSamplePerStep; + d.hasDuration = false; + m_outputNumbers[d.identifier] = n++; + list.push_back(d); + return list; } @@ -275,6 +290,7 @@ if (channels < getMinChannelCount() || channels > getMaxChannelCount()) return false; + m_channels = channels; m_stepSize = stepSize; m_blockSize = blockSize; @@ -471,6 +487,18 @@ { if (!m_produceOutput) return FeatureSet(); FeatureSet fs = featuresFrom(timestamp, false); + + Feature f; + for (int c = 0; c < m_channels; ++c) { + float sum = 0.f; + for (int i = 0; i < m_blockSize; ++i) { + sum += inputBuffers[c][i] * inputBuffers[c][i]; + } + float rms = sqrtf(sum / m_blockSize); + f.values.push_back(rms); + } + fs[m_outputNumbers["rmss"]].push_back(f); + return fs; }