changeset 241:70e6826adc64

* Add Power Spectrum example plugin
author cannam
date Mon, 10 Nov 2008 17:28:54 +0000
parents 7b90fe049d04
children 7f3a806ed1df
files Makefile Makefile.osx build/VampExamplePlugins.vcproj examples/PowerSpectrum.cpp examples/PowerSpectrum.h examples/plugins.cpp host/vamp-simple-host.cpp
diffstat 7 files changed, 266 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Nov 10 16:47:41 2008 +0000
+++ b/Makefile	Mon Nov 10 17:28:54 2008 +0000
@@ -168,6 +168,7 @@
 
 PLUGIN_HEADERS	= \
 		$(EXAMPLEDIR)/SpectralCentroid.h \
+		$(EXAMPLEDIR)/PowerSpectrum.h \
 		$(EXAMPLEDIR)/PercussionOnsetDetector.h \
 		$(EXAMPLEDIR)/FixedTempoEstimator.h \
 		$(EXAMPLEDIR)/AmplitudeFollower.h \
@@ -175,6 +176,7 @@
 
 PLUGIN_OBJECTS	= \
 		$(EXAMPLEDIR)/SpectralCentroid.o \
+		$(EXAMPLEDIR)/PowerSpectrum.o \
 		$(EXAMPLEDIR)/PercussionOnsetDetector.o \
 		$(EXAMPLEDIR)/FixedTempoEstimator.o \
 		$(EXAMPLEDIR)/AmplitudeFollower.o \
@@ -300,6 +302,9 @@
 examples/SpectralCentroid.o: examples/SpectralCentroid.h vamp-sdk/Plugin.h
 examples/SpectralCentroid.o: vamp-sdk/PluginBase.h vamp-sdk/plugguard.h
 examples/SpectralCentroid.o: vamp-sdk/RealTime.h
+examples/PowerSpectrum.o: examples/PowerSpectrum.h vamp-sdk/Plugin.h
+examples/PowerSpectrum.o: vamp-sdk/PluginBase.h vamp-sdk/plugguard.h
+examples/PowerSpectrum.o: vamp-sdk/RealTime.h
 examples/ZeroCrossing.o: examples/ZeroCrossing.h vamp-sdk/Plugin.h
 examples/ZeroCrossing.o: vamp-sdk/PluginBase.h vamp-sdk/plugguard.h
 examples/ZeroCrossing.o: vamp-sdk/RealTime.h
@@ -307,7 +312,7 @@
 examples/plugins.o: vamp-sdk/PluginBase.h vamp-sdk/plugguard.h
 examples/plugins.o: vamp-sdk/RealTime.h examples/ZeroCrossing.h
 examples/plugins.o: vamp-sdk/Plugin.h examples/SpectralCentroid.h
-examples/plugins.o: examples/PercussionOnsetDetector.h
+examples/plugins.o: examples/PercussionOnsetDetector.h examples/PowerSpectrum.h
 examples/plugins.o: examples/FixedTempoEstimator.h
 examples/plugins.o: examples/AmplitudeFollower.h
 host/vamp-simple-host.o: ./vamp-hostsdk/PluginHostAdapter.h vamp/vamp.h
--- a/Makefile.osx	Mon Nov 10 16:47:41 2008 +0000
+++ b/Makefile.osx	Mon Nov 10 17:28:54 2008 +0000
@@ -158,6 +158,7 @@
 
 PLUGIN_HEADERS	= \
 		$(EXAMPLEDIR)/SpectralCentroid.h \
+		$(EXAMPLEDIR)/PowerSpectrum.h \
 		$(EXAMPLEDIR)/PercussionOnsetDetector.h \
 		$(EXAMPLEDIR)/FixedTempoEstimator.h \
 		$(EXAMPLEDIR)/AmplitudeFollower.h \
@@ -165,6 +166,7 @@
 
 PLUGIN_OBJECTS	= \
 		$(EXAMPLEDIR)/SpectralCentroid.o \
+		$(EXAMPLEDIR)/PowerSpectrum.o \
 		$(EXAMPLEDIR)/PercussionOnsetDetector.o \
 		$(EXAMPLEDIR)/FixedTempoEstimator.o \
 		$(EXAMPLEDIR)/AmplitudeFollower.o \
@@ -247,6 +249,9 @@
 examples/SpectralCentroid.o: examples/SpectralCentroid.h vamp-sdk/Plugin.h
 examples/SpectralCentroid.o: vamp-sdk/PluginBase.h vamp-sdk/plugguard.h
 examples/SpectralCentroid.o: vamp-sdk/RealTime.h
+examples/PowerSpectrum.o: examples/PowerSpectrum.h vamp-sdk/Plugin.h
+examples/PowerSpectrum.o: vamp-sdk/PluginBase.h vamp-sdk/plugguard.h
+examples/PowerSpectrum.o: vamp-sdk/RealTime.h
 examples/ZeroCrossing.o: examples/ZeroCrossing.h vamp-sdk/Plugin.h
 examples/ZeroCrossing.o: vamp-sdk/PluginBase.h vamp-sdk/plugguard.h
 examples/ZeroCrossing.o: vamp-sdk/RealTime.h
@@ -254,7 +259,7 @@
 examples/plugins.o: vamp-sdk/PluginBase.h vamp-sdk/plugguard.h
 examples/plugins.o: vamp-sdk/RealTime.h examples/ZeroCrossing.h
 examples/plugins.o: vamp-sdk/Plugin.h examples/SpectralCentroid.h
-examples/plugins.o: examples/PercussionOnsetDetector.h
+examples/plugins.o: examples/PercussionOnsetDetector.h examples/PowerSpectrum.h
 examples/plugins.o: examples/FixedTempoEstimator.h
 examples/plugins.o: examples/AmplitudeFollower.h
 host/vamp-simple-host.o: ./vamp-hostsdk/PluginHostAdapter.h vamp/vamp.h
--- a/build/VampExamplePlugins.vcproj	Mon Nov 10 16:47:41 2008 +0000
+++ b/build/VampExamplePlugins.vcproj	Mon Nov 10 17:28:54 2008 +0000
@@ -211,6 +211,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\examples\PowerSpectrum.h"
+				>
+			</File>
+			<File
 				RelativePath="..\examples\ZeroCrossing.h"
 				>
 			</File>
@@ -255,6 +259,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\examples\PowerSpectrum.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\examples\ZeroCrossing.cpp"
 				>
 			</File>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/PowerSpectrum.cpp	Mon Nov 10 17:28:54 2008 +0000
@@ -0,0 +1,162 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Vamp
+
+    An API for audio analysis and feature extraction plugins.
+
+    Centre for Digital Music, Queen Mary, University of London.
+    Copyright 2008 QMUL.
+  
+    Permission is hereby granted, free of charge, to any person
+    obtaining a copy of this software and associated documentation
+    files (the "Software"), to deal in the Software without
+    restriction, including without limitation the rights to use, copy,
+    modify, merge, publish, distribute, sublicense, and/or sell copies
+    of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be
+    included in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
+    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+    Except as contained in this notice, the names of the Centre for
+    Digital Music; Queen Mary, University of London; and Chris Cannam
+    shall not be used in advertising or otherwise to promote the sale,
+    use or other dealings in this Software without prior written
+    authorization.
+*/
+
+#include "PowerSpectrum.h"
+
+using std::string;
+using std::cerr;
+using std::endl;
+
+#include <math.h>
+
+PowerSpectrum::PowerSpectrum(float inputSampleRate) :
+    Plugin(inputSampleRate),
+    m_blockSize(0)
+{
+}
+
+PowerSpectrum::~PowerSpectrum()
+{
+}
+
+string
+PowerSpectrum::getIdentifier() const
+{
+    return "powerspectrum";
+}
+
+string
+PowerSpectrum::getName() const
+{
+    return "Simple Power Spectrum";
+}
+
+string
+PowerSpectrum::getDescription() const
+{
+    return "Return the power spectrum of a signal";
+}
+
+string
+PowerSpectrum::getMaker() const
+{
+    return "Vamp SDK Example Plugins";
+}
+
+int
+PowerSpectrum::getPluginVersion() const
+{
+    return 1;
+}
+
+string
+PowerSpectrum::getCopyright() const
+{
+    return "Freely redistributable (BSD license)";
+}
+
+bool
+PowerSpectrum::initialise(size_t channels, size_t stepSize, size_t blockSize)
+{
+    if (channels < getMinChannelCount() ||
+	channels > getMaxChannelCount()) return false;
+
+    m_blockSize = blockSize;
+
+    return true;
+}
+
+void
+PowerSpectrum::reset()
+{
+}
+
+PowerSpectrum::OutputList
+PowerSpectrum::getOutputDescriptors() const
+{
+    OutputList list;
+
+    OutputDescriptor d;
+    d.identifier = "powerspectrum";
+    d.name = "Power Spectrum";
+    d.description = "Power values of the frequency spectrum bins calculated from the input signal";
+    d.unit = "";
+    d.hasFixedBinCount = true;
+    d.binCount = m_blockSize / 2 + 1;
+    d.hasKnownExtents = false;
+    d.isQuantized = false;
+    d.sampleType = OutputDescriptor::OneSamplePerStep;
+    list.push_back(d);
+
+    return list;
+}
+
+PowerSpectrum::FeatureSet
+PowerSpectrum::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
+{
+    FeatureSet fs;
+
+    if (m_blockSize == 0) {
+	cerr << "ERROR: PowerSpectrum::process: Not initialised" << endl;
+	return fs;
+    }
+
+    size_t n = m_blockSize / 2 + 1;
+    const float *fbuf = inputBuffers[0];
+
+    Feature feature;
+    feature.hasTimestamp = false;
+    feature.values.reserve(n); // optional
+
+    for (size_t i = 0; i < n; ++i) {
+
+	double real = fbuf[i * 2];
+	double imag = fbuf[i * 2 + 1];
+
+        feature.values.push_back(real * real + imag * imag);
+    }
+
+    fs[0].push_back(feature);
+
+    return fs;
+}
+
+PowerSpectrum::FeatureSet
+PowerSpectrum::getRemainingFeatures()
+{
+    return FeatureSet();
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/PowerSpectrum.h	Mon Nov 10 17:28:54 2008 +0000
@@ -0,0 +1,80 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Vamp
+
+    An API for audio analysis and feature extraction plugins.
+
+    Centre for Digital Music, Queen Mary, University of London.
+    Copyright 2006 Chris Cannam.
+  
+    Permission is hereby granted, free of charge, to any person
+    obtaining a copy of this software and associated documentation
+    files (the "Software"), to deal in the Software without
+    restriction, including without limitation the rights to use, copy,
+    modify, merge, publish, distribute, sublicense, and/or sell copies
+    of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be
+    included in all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
+    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+    Except as contained in this notice, the names of the Centre for
+    Digital Music; Queen Mary, University of London; and Chris Cannam
+    shall not be used in advertising or otherwise to promote the sale,
+    use or other dealings in this Software without prior written
+    authorization.
+*/
+
+#ifndef _POWER_SPECTRUM_PLUGIN_H_
+#define _POWER_SPECTRUM_PLUGIN_H_
+
+#include "vamp-sdk/Plugin.h"
+
+/**
+ * Example plugin that returns a power spectrum calculated (trivially)
+ * from the frequency domain representation of each block of audio.
+ * This is one of the simplest possible Vamp plugins, included as an
+ * example of how to return the appropriate value structure for this
+ * sort of visualisation.
+ */
+
+class PowerSpectrum : public Vamp::Plugin
+{
+public:
+    PowerSpectrum(float inputSampleRate);
+    virtual ~PowerSpectrum();
+
+    bool initialise(size_t channels, size_t stepSize, size_t blockSize);
+    void reset();
+
+    InputDomain getInputDomain() const { return FrequencyDomain; }
+
+    std::string getIdentifier() const;
+    std::string getName() const;
+    std::string getDescription() const;
+    std::string getMaker() const;
+    int getPluginVersion() const;
+    std::string getCopyright() const;
+
+    OutputList getOutputDescriptors() const;
+
+    FeatureSet process(const float *const *inputBuffers,
+                       Vamp::RealTime timestamp);
+
+    FeatureSet getRemainingFeatures();
+
+protected:
+    size_t m_blockSize;
+};
+
+
+#endif
--- a/examples/plugins.cpp	Mon Nov 10 16:47:41 2008 +0000
+++ b/examples/plugins.cpp	Mon Nov 10 17:28:54 2008 +0000
@@ -42,12 +42,14 @@
 #include "PercussionOnsetDetector.h"
 #include "FixedTempoEstimator.h"
 #include "AmplitudeFollower.h"
+#include "PowerSpectrum.h"
 
 static Vamp::PluginAdapter<ZeroCrossing> zeroCrossingAdapter;
 static Vamp::PluginAdapter<SpectralCentroid> spectralCentroidAdapter;
 static Vamp::PluginAdapter<PercussionOnsetDetector> percussionOnsetAdapter;
 static Vamp::PluginAdapter<FixedTempoEstimator> fixedTempoAdapter;
 static Vamp::PluginAdapter<AmplitudeFollower> amplitudeAdapter;
+static Vamp::PluginAdapter<PowerSpectrum> powerSpectrum;
 
 const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int version,
                                                     unsigned int index)
@@ -60,6 +62,7 @@
     case  2: return percussionOnsetAdapter.getDescriptor();
     case  3: return amplitudeAdapter.getDescriptor();
     case  4: return fixedTempoAdapter.getDescriptor();
+    case  5: return powerSpectrum.getDescriptor();
     default: return 0;
     }
 }
--- a/host/vamp-simple-host.cpp	Mon Nov 10 16:47:41 2008 +0000
+++ b/host/vamp-simple-host.cpp	Mon Nov 10 17:28:54 2008 +0000
@@ -38,7 +38,7 @@
 /*
  * This "simple" Vamp plugin host is no longer as simple as it was; it
  * now has a lot of options and includes a lot of code to handle the
- * various useful list options it supports.
+ * various useful listing modes it supports.
  *
  * However, the runPlugin function still contains a reasonable
  * implementation of a fairly generic Vamp plugin host capable of