# HG changeset patch # User Chris Cannam # Date 1238671102 0 # Node ID a040e35f352cfc8b65cbad4211cc5864a9566d75 # Parent b3a809bb964ee379b435fbc9ba7107d67612e3f7 * Add Discrete Wavelet Transform plugin from Thomas Wilmering diff -r b3a809bb964e -r a040e35f352c libmain.cpp --- a/libmain.cpp Mon Mar 30 12:41:57 2009 +0000 +++ b/libmain.cpp Thu Apr 02 11:18:22 2009 +0000 @@ -21,6 +21,7 @@ #include "plugins/SimilarityPlugin.h" #include "plugins/BarBeatTrack.h" #include "plugins/AdaptiveSpectrogram.h" +#include "plugins/DWT.h" static Vamp::PluginAdapter beatTrackerAdapter; static Vamp::PluginAdapter onsetDetectorAdapter; @@ -33,6 +34,7 @@ static Vamp::PluginAdapter similarityPluginAdapter; static Vamp::PluginAdapter barBeatTrackPluginAdapter; static Vamp::PluginAdapter adaptiveSpectrogramAdapter; +static Vamp::PluginAdapter dwtAdapter; const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int vampApiVersion, unsigned int index) @@ -50,7 +52,8 @@ case 7: return similarityPluginAdapter.getDescriptor(); case 8: return mfccPluginAdapter.getDescriptor(); case 9: return barBeatTrackPluginAdapter.getDescriptor(); -// case 10: return adaptiveSpectrogramAdapter.getDescriptor(); + case 10: return dwtAdapter.getDescriptor(); +// case 11: return adaptiveSpectrogramAdapter.getDescriptor(); default: return 0; } } diff -r b3a809bb964e -r a040e35f352c plugins/DWT.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/DWT.cpp Thu Apr 02 11:18:22 2009 +0000 @@ -0,0 +1,426 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + QM Vamp Plugin Set + + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2009 Thomas Wilmering. + All rights reserved. +*/ + +#include "DWT.h" + +#include + +using std::string; +using std::vector; +using std::cerr; +using std::endl; + +DWT::DWT(float inputSampleRate) : + Plugin(inputSampleRate), + m_stepSize(0), + m_blockSize(0) +{ + m_scales = 10; + m_flength = 0; + m_wavelet = Wavelet::Haar; + m_threshold = 0; + m_absolute = 0; +} + +DWT::~DWT() +{ +} + +string +DWT::getIdentifier() const +{ + return "dwt"; +} + +string +DWT::getName() const +{ + return "Discrete Wavelet Transform"; +} + +string +DWT::getDescription() const +{ + return "Visualisation by scalogram"; +} + +string +DWT::getMaker() const +{ + return "Queen Mary, University of London"; +} + +int +DWT::getPluginVersion() const +{ + return 1; +} + +string +DWT::getCopyright() const +{ + return "Plugin by Thomas Wilmering. Copyright (c) 2009 Thomas Wilmering and QMUL - All Rights Reserved"; +} + +size_t +DWT::getPreferredStepSize() const +{ + return 0; +} + +bool +DWT::initialise(size_t channels, size_t stepSize, size_t blockSize) +{ + if (channels < getMinChannelCount() || + channels > getMaxChannelCount()) return false; + + m_stepSize = stepSize; + m_blockSize = blockSize; + + Wavelet::createDecompositionFilters(m_wavelet, m_lpd, m_hpd); + + m_flength = m_lpd.size(); // or m_hpd.size() + + m_samplePass.resize(m_scales); // resize buffer for samples to pass to next block + + for (int i=0; i b) b = 1 << s; // correct blocksize if smaller than 2^(max scale) + +//-------------------------------------------------------------------------------------------------- + + float tempDet; + int outloc; + int halfblocksize = int(.5 * b); + int fbufloc; + int fbufloc2; + + vector< vector > wCoefficients(m_scales); // result + vector tempAprx(halfblocksize,0.0); // approximation + vector fbuf(b+m_flength-2,0.0); // input buffer + + for (int n=m_flength-2; n blocksize + m_samplePass[scale].push_back(fbuf[m_flength-2+n]); + m_samplePass[scale].erase (m_samplePass[scale].begin(),m_samplePass[scale].begin()+b); + } + + for (int n=0; n> 1; // the approximation in tmpfwd is stored as + halfblocksize = halfblocksize >> 1; // input for next level + + for (int n=m_flength-2; n(b+m_flength-2).swap(fbuf); + vector(halfblocksize).swap(tempAprx); // set new size with zeros + } + } + + +//----------------------------------------------------------------------------------------- + + halfblocksize = int(.5 * b_init); + + for (int m = 0; m > wCoefficients(m_scales); // result + vector tempAprx(halfblocksize,0.0); // approximation + vector fbuf(b+len-2,0.0); // input buffer + + //for (int n=len-2; n blocksize + m_samplePass[scale].push_back(fbuf[len-2+n]); + m_samplePass[scale].erase (m_samplePass[scale].begin(),m_samplePass[scale].begin()+b); + } + + for (int n=0; n> 1; // the approximation in tmpfwd is stored as + halfblocksize = halfblocksize >> 1; // input for next level + + for (int n=len-2; n(b+len-2).swap(fbuf); + vector(halfblocksize).swap(tempAprx); // set new size with zeros + } + + } + +//----------------------------------------------------------------------------------------- + + halfblocksize = int(.5 * b_init + 0.1); + + for (int m = 0; m + +#include + +using std::vector; + +class DWT : public Vamp::Plugin +{ +public: + DWT(float inputSampleRate); + virtual ~DWT(); + + bool initialise(size_t channels, size_t stepSize, size_t blockSize); + void reset(); + + InputDomain getInputDomain() const { return TimeDomain; } + + std::string getIdentifier() const; + std::string getName() const; + std::string getDescription() const; + std::string getMaker() const; + int getPluginVersion() const; + std::string getCopyright() const; + size_t getPreferredStepSize() const; + + OutputList getOutputDescriptors() const; + + ParameterList getParameterDescriptors() const; + float getParameter(std::string paramid) const; + void setParameter(std::string paramid, float newval); + + FeatureSet process(const float *const *inputBuffers, + Vamp::RealTime timestamp); + + FeatureSet getRemainingFeatures(); + +protected: + size_t m_stepSize; + size_t m_blockSize; + + int m_scales; + int m_flength; + Wavelet::Type m_wavelet; + float m_threshold; + float m_absolute; + + vector m_lpd; + vector m_hpd; + + vector< vector > m_samplePass; +}; + + +#endif diff -r b3a809bb964e -r a040e35f352c qm-vamp-plugins.pro --- a/qm-vamp-plugins.pro Mon Mar 30 12:41:57 2009 +0000 +++ b/qm-vamp-plugins.pro Thu Apr 02 11:18:22 2009 +0000 @@ -28,6 +28,7 @@ HEADERS += plugins/AdaptiveSpectrogram.h \ plugins/BarBeatTrack.h \ plugins/BeatTrack.h \ + plugins/DWT.h \ plugins/OnsetDetect.h \ plugins/ChromagramPlugin.h \ plugins/ConstantQSpectrogram.h \ @@ -40,6 +41,7 @@ plugins/AdaptiveSpectrogram.cpp \ plugins/BarBeatTrack.cpp \ plugins/BeatTrack.cpp \ + plugins/DWT.cpp \ plugins/OnsetDetect.cpp \ plugins/ChromagramPlugin.cpp \ plugins/ConstantQSpectrogram.cpp \