Mercurial > hg > tipic
changeset 9:f440b0e2192b
Call the (not yet existing) implementation functions
author | Chris Cannam |
---|---|
date | Fri, 14 Aug 2015 14:40:48 +0100 |
parents | f51f26334f78 |
children | fa87ce20fe8c |
files | Makefile.linux src/PitchFilterbank.cpp src/PitchFilterbank.h src/TipicVampPlugin.cpp src/TipicVampPlugin.h |
diffstat | 5 files changed, 107 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile.linux Fri Aug 14 12:45:27 2015 +0100 +++ b/Makefile.linux Fri Aug 14 14:40:48 2015 +0100 @@ -1,5 +1,5 @@ -CFLAGS := -Wall -O3 -ffast-math -msse -msse2 -mfpmath=sse -ftree-vectorize -fPIC -I../vamp-plugin-sdk/ +CFLAGS := -Wall -Werror -O3 -ffast-math -msse -msse2 -mfpmath=sse -ftree-vectorize -fPIC -I../vamp-plugin-sdk/ #CFLAGS := -g -fPIC -I../vamp-plugin-sdk
--- a/src/PitchFilterbank.cpp Fri Aug 14 12:45:27 2015 +0100 +++ b/src/PitchFilterbank.cpp Fri Aug 14 14:40:48 2015 +0100 @@ -35,8 +35,11 @@ } } - ~D(); + ~D() { + } + int getSampleRate() const { return m_sampleRate; } + /// A series of real-valued samples ordered in time. typedef vector<double> RealSequence; @@ -90,3 +93,33 @@ } }; +PitchFilterbank::PitchFilterbank(int sampleRate) : + m_d(new D(sampleRate)) +{ +} + +PitchFilterbank::~PitchFilterbank() +{ + delete m_d; +} + +void +PitchFilterbank::reset() +{ + int rate = m_d->getSampleRate(); + delete m_d; + m_d = new D(rate); +} + +PitchFilterbank::RealBlock +PitchFilterbank::process(const RealSequence &in) +{ + return m_d->process(in); +} + +PitchFilterbank::RealBlock +PitchFilterbank::getRemainingOutput() +{ + return m_d->getRemainingOutput(); +} +
--- a/src/PitchFilterbank.h Fri Aug 14 12:45:27 2015 +0100 +++ b/src/PitchFilterbank.h Fri Aug 14 14:40:48 2015 +0100 @@ -20,6 +20,8 @@ /// A matrix of real-valued samples, indexed by time then bin number. typedef std::vector<RealColumn> RealBlock; + void reset(); + RealBlock process(const RealSequence &); RealBlock getRemainingOutput();
--- a/src/TipicVampPlugin.cpp Fri Aug 14 12:45:27 2015 +0100 +++ b/src/TipicVampPlugin.cpp Fri Aug 14 14:40:48 2015 +0100 @@ -1,8 +1,21 @@ #include "TipicVampPlugin.h" +#include <bqvec/Range.h> +#include <bqvec/VectorOps.h> + +#include <iostream> + +using namespace std; + +using namespace breakfastquay; + Tipic::Tipic(float inputSampleRate) : - Plugin(inputSampleRate) + Plugin(inputSampleRate), + m_stepSize(0), + m_blockSize(0), + m_filterbank(inputSampleRate), + m_pitchOutputNo(-1) { } @@ -139,6 +152,7 @@ d.sampleType = OutputDescriptor::FixedSampleRate; d.sampleRate = 4410.0 / m_inputSampleRate; d.hasDuration = false; + m_pitchOutputNo = list.size(); list.push_back(d); return list; @@ -147,27 +161,70 @@ bool Tipic::initialise(size_t channels, size_t stepSize, size_t blockSize) { + if (m_pitchOutputNo < 0) { + // getOutputDescriptors has never been called, it sets up the + // outputNo members + (void)getOutputDescriptors(); + } + if (channels < getMinChannelCount() || - channels > getMaxChannelCount()) return false; + channels > getMaxChannelCount()) { + cerr << "ERROR: initialise: wrong number of channels supplied (only 1 supported)" << endl; + return false; + } + m_stepSize = stepSize; + m_blockSize = blockSize; + + if (m_stepSize != m_blockSize) { + cerr << "ERROR: initialise: step size and block size must be equal" << endl; + return false; + } + + reset(); + return true; } void Tipic::reset() { - // Clear buffers, reset stored values, etc + m_filterbank.reset(); } Tipic::FeatureSet Tipic::process(const float *const *inputBuffers, Vamp::RealTime timestamp) { - return FeatureSet(); + PitchFilterbank::RealSequence in; + in.resize(m_blockSize); + v_convert(in.data(), inputBuffers[0], m_blockSize); + + PitchFilterbank::RealBlock pitchFiltered = m_filterbank.process(in); + + FeatureSet fs; + addPitchFeatures(fs, pitchFiltered); + return fs; } Tipic::FeatureSet Tipic::getRemainingFeatures() { - return FeatureSet(); + PitchFilterbank::RealBlock pitchFiltered = m_filterbank.getRemainingOutput(); + + FeatureSet fs; + addPitchFeatures(fs, pitchFiltered); + return fs; } +void +Tipic::addPitchFeatures(FeatureSet &fs, const PitchFilterbank::RealBlock &block) +{ + for (int i = 0; in_range_for(block, i); ++i) { + Feature f; + int h = block[i].size(); + f.values.resize(h); + v_convert(f.values.data(), block[i].data(), h); + fs[m_pitchOutputNo].push_back(f); + } +} +
--- a/src/TipicVampPlugin.h Fri Aug 14 12:45:27 2015 +0100 +++ b/src/TipicVampPlugin.h Fri Aug 14 14:40:48 2015 +0100 @@ -3,6 +3,8 @@ #include <vamp-sdk/Plugin.h> +#include "PitchFilterbank.h" + using std::string; class Tipic : public Vamp::Plugin @@ -43,9 +45,13 @@ FeatureSet getRemainingFeatures(); protected: - + int m_stepSize; + int m_blockSize; + PitchFilterbank m_filterbank; + mutable int m_pitchOutputNo; + + void addPitchFeatures(FeatureSet &, const PitchFilterbank::RealBlock &); }; - #endif