* First pass at a simple set of Vamp plugins using the Aubio library.
authorChris Cannam <cannam@all-day-breakfast.com>
Thu, 11 May 2006 14:51:10 +0000 (14:51 +0000)
committerChris Cannam <cannam@all-day-breakfast.com>
Thu, 11 May 2006 14:51:10 +0000 (14:51 +0000)
Makefile [new file with mode: 0644]
libmain.cpp [new file with mode: 0644]
plugins/Notes.cpp [new file with mode: 0644]
plugins/Notes.h [new file with mode: 0644]
plugins/Onset.cpp [new file with mode: 0644]
plugins/Onset.h [new file with mode: 0644]
plugins/Pitch.cpp [new file with mode: 0644]
plugins/Pitch.h [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..576d93c
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,53 @@
+
+# Location of Vamp SDK
+#
+VAMPDIR                = ../vamp-plugin-sdk
+VAMPLIBDIR     = $(VAMPDIR)/vamp-sdk
+
+# Location of our plugins
+#
+PLUGINDIR      = plugins
+
+# Compile flags
+#
+CXXFLAGS       := $(CXXFLAGS) -g -Wall -I$(VAMPDIR) -I.
+
+# Libraries required for the plugins.  Note that we can (and actively
+# want to) statically link libstdc++, because our plugin exposes only
+# a C API so there are no boundary compatibility problems.
+#
+PLUGIN_LIBS    = -L$(VAMPLIBDIR) -lvamp-sdk -laubio
+#PLUGIN_LIBS   = -L$(VAMPLIBDIR) -lvamp-sdk /usr/lib/libaubio.a /usr/lib/libfftw3f.a
+#PLUGIN_LIBS   = -L$(VAMPLIBDIR) -lvamp-sdk $(shell g++ -print-file-name=libstdc++.a)
+
+# Flags required to tell the compiler to make a dynamically loadable object
+#
+PLUGIN_LDFLAGS = -shared -Wl,-Bsymbolic -static-libgcc
+
+# File extension for a dynamically loadable object
+#
+PLUGIN_EXT     = .so
+
+## For OS/X with g++:
+#PLUGIN_LDFLAGS        = -dynamiclib
+#PLUGIN_EXT    = .dylib
+
+
+### End of user-serviceable parts
+
+PLUGIN_OBJECTS = libmain.o $(patsubst %.cpp,%.o,$(wildcard $(PLUGINDIR)/*.cpp))
+PLUGIN_HEADERS = $(patsubst %.cpp,%.h,$(wildcard $(PLUGINDIR)/*.cpp))
+PLUGIN_TARGET  = vamp-aubio$(PLUGIN_EXT)
+
+all:           $(PLUGIN_TARGET)
+
+$(PLUGIN_TARGET):      $(PLUGIN_OBJECTS) $(PLUGIN_HEADERS)
+               $(CXX) $(LDFLAGS) $(PLUGIN_LDFLAGS) -o $@ $(PLUGIN_OBJECTS) $(PLUGIN_LIBS)
+
+clean:         
+               rm -f $(PLUGIN_OBJECTS)
+
+distclean:     clean
+               rm -f $(PLUGIN_TARGET) *~ */*~
+
+
diff --git a/libmain.cpp b/libmain.cpp
new file mode 100644 (file)
index 0000000..a349b9d
--- /dev/null
@@ -0,0 +1,37 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Vamp feature extraction plugins using Paul Brossier's Aubio library.
+
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+
+*/
+
+#include <vamp/vamp.h>
+#include <vamp-sdk/PluginAdapter.h>
+
+#include "plugins/Onset.h"
+#include "plugins/Pitch.h"
+#include "plugins/Notes.h"
+
+static Vamp::PluginAdapter<Onset> onsetAdapter;
+static Vamp::PluginAdapter<Pitch> pitchAdapter;
+static Vamp::PluginAdapter<Notes> notesAdapter;
+
+const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int index)
+{
+    switch (index) {
+    case  0: return onsetAdapter.getDescriptor();
+    case  1: return pitchAdapter.getDescriptor();
+    case  2: return notesAdapter.getDescriptor();
+    default: return 0;
+    }
+}
+
diff --git a/plugins/Notes.cpp b/plugins/Notes.cpp
new file mode 100644 (file)
index 0000000..0a64dce
--- /dev/null
@@ -0,0 +1,340 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Vamp feature extraction plugins using Paul Brossier's Aubio library.
+
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+
+*/
+
+#include "Notes.h"
+
+using std::string;
+using std::vector;
+using std::cerr;
+using std::endl;
+
+Notes::Notes(float inputSampleRate) :
+    Plugin(inputSampleRate),
+    m_ibuf(0),
+    m_fftgrain(0),
+    m_onset(0),
+    m_pv(0),
+    m_peakpick(0),
+    m_onsetdet(0),
+    m_onsettype(aubio_onset_mkl),
+    m_pitchdet(0),
+    m_pitchtype(aubio_pitch_fcomb),
+    m_pitchmode(aubio_pitchm_freq),
+    m_threshold(0.3),
+    m_silence(-90),
+    m_median(6)
+{
+}
+
+Notes::~Notes()
+{
+    if (m_onsetdet) aubio_onsetdetection_free(m_onsetdet);
+    if (m_pitchdet) del_aubio_pitchdetection(m_pitchdet);
+    if (m_ibuf) del_fvec(m_ibuf);
+    if (m_onset) del_fvec(m_onset);
+    if (m_fftgrain) del_cvec(m_fftgrain);
+    if (m_pv) del_aubio_pvoc(m_pv);
+    if (m_peakpick) del_aubio_peakpicker(m_peakpick);
+}
+
+string
+Notes::getName() const
+{
+    return "aubionotes";
+}
+
+string
+Notes::getDescription() const
+{
+    return "Aubio Note Tracker";
+}
+
+string
+Notes::getMaker() const
+{
+    return "Paul Brossier (plugin by Chris Cannam)";
+}
+
+int
+Notes::getPluginVersion() const
+{
+    return 1;
+}
+
+string
+Notes::getCopyright() const
+{
+    return "GPL";
+}
+
+bool
+Notes::initialise(size_t channels, size_t stepSize, size_t blockSize)
+{
+    m_channelCount = channels;
+    m_stepSize = stepSize;
+    m_blockSize = blockSize;
+
+    size_t processingBlockSize;
+    if (m_onsettype == aubio_onset_energy ||
+        m_onsettype == aubio_onset_hfc) {
+        processingBlockSize = stepSize * 2;
+    } else {
+        processingBlockSize = stepSize * 4;
+    }
+
+    m_ibuf = new_fvec(stepSize, channels);
+    m_onset = new_fvec(1, channels);
+    m_fftgrain = new_cvec(processingBlockSize, channels);
+    m_pv = new_aubio_pvoc(processingBlockSize, stepSize, channels);
+    m_peakpick = new_aubio_peakpicker(m_threshold);
+
+    m_onsetdet = new_aubio_onsetdetection(m_onsettype, processingBlockSize, channels);
+
+    m_pitchdet = new_aubio_pitchdetection(processingBlockSize * 4,
+                                          stepSize,
+                                          channels,
+                                          lrintf(m_inputSampleRate),
+                                          m_pitchtype,
+                                          m_pitchmode);
+
+    m_count = 0;
+    m_currentOnset = Vamp::RealTime::zeroTime;
+    m_haveCurrent = false;
+
+    return true;
+}
+
+void
+Notes::reset()
+{
+}
+
+size_t
+Notes::getPreferredStepSize() const
+{
+    if (m_onsettype == aubio_onset_energy ||
+        m_onsettype == aubio_onset_hfc) {
+        return 512;
+    } else {
+        return 128;
+    }
+}
+
+size_t
+Notes::getPreferredBlockSize() const
+{
+    return getPreferredStepSize();
+}
+
+Notes::ParameterList
+Notes::getParameterDescriptors() const
+{
+    ParameterList list;
+    
+    ParameterDescriptor desc;
+    desc.name = "onsettype";
+    desc.description = "Onset Detection Function Type";
+    desc.minValue = 0;
+    desc.maxValue = 6;
+    desc.defaultValue = (int)aubio_onset_mkl;
+    desc.isQuantized = true;
+    desc.quantizeStep = 1;
+    desc.valueNames.push_back("Energy Based");
+    desc.valueNames.push_back("Spectral Difference");
+    desc.valueNames.push_back("High-Frequency Content");
+    desc.valueNames.push_back("Complex Domain");
+    desc.valueNames.push_back("Phase Deviation");
+    desc.valueNames.push_back("Kullback-Liebler");
+    desc.valueNames.push_back("Modified Kullback-Liebler");
+    list.push_back(desc);
+
+    desc = ParameterDescriptor();
+    desc.name = "pitchtype";
+    desc.description = "Pitch Detection Function Type";
+    desc.minValue = 0;
+    desc.maxValue = 4;
+    desc.defaultValue = (int)aubio_pitch_fcomb;
+    desc.isQuantized = true;
+    desc.quantizeStep = 1;
+    desc.valueNames.push_back("YIN Frequency Estimator");
+    desc.valueNames.push_back("Spectral Comb");
+    desc.valueNames.push_back("Schmitt");
+    desc.valueNames.push_back("Fast Harmonic Comb");
+    desc.valueNames.push_back("YIN with FFT");
+    list.push_back(desc);
+
+    desc = ParameterDescriptor();
+    desc.name = "peakpickthreshold";
+    desc.description = "Peak Picker Threshold";
+    desc.minValue = 0;
+    desc.maxValue = 1;
+    desc.defaultValue = 0.3;
+    desc.isQuantized = false;
+    list.push_back(desc);
+
+    desc = ParameterDescriptor();
+    desc.name = "silencethreshold";
+    desc.description = "Silence Threshold";
+    desc.minValue = -120;
+    desc.maxValue = 0;
+    desc.defaultValue = -90;
+    desc.unit = "dB";
+    desc.isQuantized = false;
+    list.push_back(desc);
+
+    return list;
+}
+
+float
+Notes::getParameter(std::string param) const
+{
+    if (param == "onsettype") {
+        return m_onsettype;
+    } else if (param == "pitchtype") {
+        return m_pitchtype;
+    } else if (param == "peakpickthreshold") {
+        return m_threshold;
+    } else if (param == "silencethreshold") {
+        return m_silence;
+    } else {
+        return 0.0;
+    }
+}
+
+void
+Notes::setParameter(std::string param, float value)
+{
+    if (param == "onsettype") {
+        switch (lrintf(value)) {
+        case 0: m_onsettype = aubio_onset_energy; break;
+        case 1: m_onsettype = aubio_onset_specdiff; break;
+        case 2: m_onsettype = aubio_onset_hfc; break;
+        case 3: m_onsettype = aubio_onset_complex; break;
+        case 4: m_onsettype = aubio_onset_phase; break;
+        case 5: m_onsettype = aubio_onset_kl; break;
+        case 6: m_onsettype = aubio_onset_mkl; break;
+        }
+    } else if (param == "pitchtype") {
+        switch (lrintf(value)) {
+        case 0: m_pitchtype = aubio_pitch_yin; break;
+        case 1: m_pitchtype = aubio_pitch_mcomb; break;
+        case 2: m_pitchtype = aubio_pitch_schmitt; break;
+        case 3: m_pitchtype = aubio_pitch_fcomb; break;
+        case 4: m_pitchtype = aubio_pitch_yinfft; break;
+        }
+    } else if (param == "peakpickthreshold") {
+        m_threshold = value;
+    } else if (param == "silencethreshold") {
+        m_silence = value;
+    }
+}
+
+Notes::OutputList
+Notes::getOutputDescriptors() const
+{
+    OutputList list;
+
+    OutputDescriptor d;
+    d.name = "notes";
+    d.unit = "Hz";
+    d.description = "Notes";
+    d.hasFixedBinCount = true;
+    d.binCount = 2;
+    d.binNames.push_back("Frequency");
+    d.binNames.push_back("Duration");
+    d.binNames.push_back("Velocity");
+    d.hasKnownExtents = false;
+    d.isQuantized = false;
+    d.sampleType = OutputDescriptor::VariableSampleRate;
+    d.sampleRate = 0;
+    list.push_back(d);
+
+    return list;
+}
+
+Notes::FeatureSet
+Notes::process(float **inputBuffers, Vamp::RealTime timestamp)
+{
+    for (size_t i = 0; i < m_stepSize; ++i) {
+        for (size_t j = 0; j < m_channelCount; ++j) {
+            fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
+        }
+    }
+
+    aubio_pvoc_do(m_pv, m_ibuf, m_fftgrain);
+    aubio_onsetdetection(m_onsetdet, m_fftgrain, m_onset);
+
+    bool isonset = aubio_peakpick_pimrt(m_onset, m_peakpick);
+
+    float frequency = aubio_pitchdetection(m_pitchdet, m_ibuf);
+
+    m_notebuf.push_back(frequency);
+    if (m_notebuf.size() > m_median) m_notebuf.pop_front();
+
+    float level = aubio_level_detection(m_ibuf, m_silence);
+
+    FeatureSet returnFeatures;
+
+    if (isonset) {
+        if (level == 1.) {
+            isonset = false;
+            m_count = 0;
+            if (m_haveCurrent) pushNote(returnFeatures, timestamp);
+        } else {
+            m_count = 1;
+        }
+    } else {
+        if (m_count > 0) ++m_count;
+        if (m_count == m_median) {
+            if (m_haveCurrent) pushNote(returnFeatures, timestamp);
+            m_currentOnset = timestamp;
+            m_currentLevel = level;
+            m_haveCurrent = true;
+        }
+    }
+
+    m_lastTimeStamp = timestamp;
+    return returnFeatures;
+}
+
+Notes::FeatureSet
+Notes::getRemainingFeatures()
+{
+    FeatureSet returnFeatures;
+    if (m_haveCurrent) pushNote(returnFeatures, m_lastTimeStamp);
+    return returnFeatures;
+}
+
+void
+Notes::pushNote(FeatureSet &fs, const Vamp::RealTime &offTime)
+{
+    std::deque<float> toSort = m_notebuf;
+    std::sort(toSort.begin(), toSort.end());
+    float median = toSort[toSort.size()/2];
+    if (median < 45.0) return;
+
+    Feature feature;
+    feature.hasTimestamp = true;
+    feature.timestamp = m_currentOnset;
+    feature.values.push_back(median);
+//    feature.values.push_back(FLOOR(aubio_freqtomidi(median) + 0.5));
+    feature.values.push_back
+        (Vamp::RealTime::realTime2Frame(offTime, lrintf(m_inputSampleRate)) -
+         Vamp::RealTime::realTime2Frame(m_currentOnset, lrintf(m_inputSampleRate)));
+    feature.values.push_back(m_currentLevel);
+    fs[0].push_back(feature);
+}
+    
diff --git a/plugins/Notes.h b/plugins/Notes.h
new file mode 100644 (file)
index 0000000..3f86bce
--- /dev/null
@@ -0,0 +1,83 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Vamp feature extraction plugins using Paul Brossier's Aubio library.
+
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+
+*/
+
+#ifndef _NOTES_PLUGIN_H_
+#define _NOTES_PLUGIN_H_
+
+#include <vamp-sdk/Plugin.h>
+#include <aubio/aubio.h>
+
+#include <deque>
+
+class Notes : public Vamp::Plugin
+{
+public:
+    Notes(float inputSampleRate);
+    virtual ~Notes();
+
+    bool initialise(size_t channels, size_t stepSize, size_t blockSize);
+    void reset();
+
+    InputDomain getInputDomain() const { return TimeDomain; }
+
+    std::string getName() const;
+    std::string getDescription() const;
+    std::string getMaker() const;
+    int getPluginVersion() const;
+    std::string getCopyright() const;
+
+    ParameterList getParameterDescriptors() const;
+    float getParameter(std::string) const;
+    void setParameter(std::string, float);
+
+    size_t getPreferredStepSize() const;
+    size_t getPreferredBlockSize() const;
+
+    OutputList getOutputDescriptors() const;
+
+    FeatureSet process(float **inputBuffers, Vamp::RealTime timestamp);
+
+    FeatureSet getRemainingFeatures();
+
+protected:
+    fvec_t *m_ibuf;
+    cvec_t *m_fftgrain;
+    fvec_t *m_onset;
+    aubio_pvoc_t *m_pv;
+    aubio_pickpeak_t *m_peakpick;
+    aubio_onsetdetection_t *m_onsetdet;
+    aubio_onsetdetection_type m_onsettype;
+    aubio_pitchdetection_t *m_pitchdet;
+    aubio_pitchdetection_type m_pitchtype;
+    aubio_pitchdetection_mode m_pitchmode;
+    float m_threshold;
+    float m_silence;
+    size_t m_median;
+    size_t m_stepSize;
+    size_t m_blockSize;
+    size_t m_channelCount;
+    std::deque<float> m_notebuf;
+    size_t m_count;
+    Vamp::RealTime m_currentOnset;
+    Vamp::RealTime m_lastTimeStamp;
+    float m_currentLevel;
+    bool m_haveCurrent;
+
+    void pushNote(FeatureSet &, const Vamp::RealTime &);
+};
+
+
+#endif
diff --git a/plugins/Onset.cpp b/plugins/Onset.cpp
new file mode 100644 (file)
index 0000000..089f5e1
--- /dev/null
@@ -0,0 +1,255 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Vamp feature extraction plugins using Paul Brossier's Aubio library.
+
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+
+*/
+
+#include "Onset.h"
+
+using std::string;
+using std::vector;
+using std::cerr;
+using std::endl;
+
+Onset::Onset(float inputSampleRate) :
+    Plugin(inputSampleRate),
+    m_ibuf(0),
+    m_fftgrain(0),
+    m_onset(0),
+    m_pv(0),
+    m_peakpick(0),
+    m_onsetdet(0),
+    m_onsettype(aubio_onset_mkl),
+    m_threshold(0.3),
+    m_silence(-90)
+{
+}
+
+Onset::~Onset()
+{
+    if (m_onsetdet) aubio_onsetdetection_free(m_onsetdet);
+    if (m_ibuf) del_fvec(m_ibuf);
+    if (m_onset) del_fvec(m_onset);
+    if (m_fftgrain) del_cvec(m_fftgrain);
+    if (m_pv) del_aubio_pvoc(m_pv);
+    if (m_peakpick) del_aubio_peakpicker(m_peakpick);
+}
+
+string
+Onset::getName() const
+{
+    return "aubioonset";
+}
+
+string
+Onset::getDescription() const
+{
+    return "Aubio Onset Detector";
+}
+
+string
+Onset::getMaker() const
+{
+    return "Paul Brossier (plugin by Chris Cannam)";
+}
+
+int
+Onset::getPluginVersion() const
+{
+    return 1;
+}
+
+string
+Onset::getCopyright() const
+{
+    return "GPL";
+}
+
+bool
+Onset::initialise(size_t channels, size_t stepSize, size_t blockSize)
+{
+    m_channelCount = channels;
+    m_stepSize = stepSize;
+    m_blockSize = blockSize;
+
+    size_t processingBlockSize;
+    if (m_onsettype == aubio_onset_energy ||
+        m_onsettype == aubio_onset_hfc) {
+        processingBlockSize = stepSize * 2;
+    } else {
+        processingBlockSize = stepSize * 4;
+    }
+
+    m_ibuf = new_fvec(stepSize, channels);
+    m_onset = new_fvec(1, channels);
+    m_fftgrain = new_cvec(processingBlockSize, channels);
+    m_pv = new_aubio_pvoc(processingBlockSize, stepSize, channels);
+    m_peakpick = new_aubio_peakpicker(m_threshold);
+
+    m_onsetdet = new_aubio_onsetdetection(m_onsettype, processingBlockSize, channels);
+
+    return true;
+}
+
+void
+Onset::reset()
+{
+}
+
+size_t
+Onset::getPreferredStepSize() const
+{
+    if (m_onsettype == aubio_onset_energy ||
+        m_onsettype == aubio_onset_hfc) {
+        return 512;
+    } else {
+        return 128;
+    }
+}
+
+size_t
+Onset::getPreferredBlockSize() const
+{
+    return getPreferredStepSize();
+}
+
+Onset::ParameterList
+Onset::getParameterDescriptors() const
+{
+    ParameterList list;
+    
+    ParameterDescriptor desc;
+    desc.name = "onsettype";
+    desc.description = "Onset Detection Function Type";
+    desc.minValue = 0;
+    desc.maxValue = 6;
+    desc.defaultValue = (int)aubio_onset_mkl;
+    desc.isQuantized = true;
+    desc.quantizeStep = 1;
+    desc.valueNames.push_back("Energy Based");
+    desc.valueNames.push_back("Spectral Difference");
+    desc.valueNames.push_back("High-Frequency Content");
+    desc.valueNames.push_back("Complex Domain");
+    desc.valueNames.push_back("Phase Deviation");
+    desc.valueNames.push_back("Kullback-Liebler");
+    desc.valueNames.push_back("Modified Kullback-Liebler");
+    list.push_back(desc);
+
+    desc = ParameterDescriptor();
+    desc.name = "peakpickthreshold";
+    desc.description = "Peak Picker Threshold";
+    desc.minValue = 0;
+    desc.maxValue = 1;
+    desc.defaultValue = 0.3;
+    desc.isQuantized = false;
+    list.push_back(desc);
+
+    desc = ParameterDescriptor();
+    desc.name = "silencethreshold";
+    desc.description = "Silence Threshold";
+    desc.minValue = -120;
+    desc.maxValue = 0;
+    desc.defaultValue = -90;
+    desc.unit = "dB";
+    desc.isQuantized = false;
+    list.push_back(desc);
+
+    return list;
+}
+
+float
+Onset::getParameter(std::string param) const
+{
+    if (param == "onsettype") {
+        return m_onsettype;
+    } else if (param == "peakpickthreshold") {
+        return m_threshold;
+    } else if (param == "silencethreshold") {
+        return m_silence;
+    } else {
+        return 0.0;
+    }
+}
+
+void
+Onset::setParameter(std::string param, float value)
+{
+    if (param == "onsettype") {
+        switch (lrintf(value)) {
+        case 0: m_onsettype = aubio_onset_energy; break;
+        case 1: m_onsettype = aubio_onset_specdiff; break;
+        case 2: m_onsettype = aubio_onset_hfc; break;
+        case 3: m_onsettype = aubio_onset_complex; break;
+        case 4: m_onsettype = aubio_onset_phase; break;
+        case 5: m_onsettype = aubio_onset_kl; break;
+        case 6: m_onsettype = aubio_onset_mkl; break;
+        }
+    } else if (param == "peakpickthreshold") {
+        m_threshold = value;
+    } else if (param == "silencethreshold") {
+        m_silence = value;
+    }
+}
+
+Onset::OutputList
+Onset::getOutputDescriptors() const
+{
+    OutputList list;
+
+    OutputDescriptor d;
+    d.name = "onsets";
+    d.unit = "";
+    d.description = "Onsets";
+    d.hasFixedBinCount = true;
+    d.binCount = 0;
+    d.sampleType = OutputDescriptor::OneSamplePerStep;
+    list.push_back(d);
+
+    return list;
+}
+
+Onset::FeatureSet
+Onset::process(float **inputBuffers, Vamp::RealTime /* timestamp */)
+{
+    for (size_t i = 0; i < m_stepSize; ++i) {
+        for (size_t j = 0; j < m_channelCount; ++j) {
+            fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
+        }
+    }
+
+    aubio_pvoc_do(m_pv, m_ibuf, m_fftgrain);
+    aubio_onsetdetection(m_onsetdet, m_fftgrain, m_onset);
+
+    bool isonset = aubio_peakpick_pimrt(m_onset, m_peakpick);
+
+    if (isonset) {
+        if (aubio_silence_detection(m_ibuf, m_silence)) {
+            isonset = false;
+        }
+    }
+
+    FeatureSet returnFeatures;
+
+    if (isonset) {
+        returnFeatures[0].push_back(Feature());
+    }
+
+    return returnFeatures;
+}
+
+Onset::FeatureSet
+Onset::getRemainingFeatures()
+{
+    return FeatureSet();
+}
+
diff --git a/plugins/Onset.h b/plugins/Onset.h
new file mode 100644 (file)
index 0000000..895cce6
--- /dev/null
@@ -0,0 +1,69 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Vamp feature extraction plugins using Paul Brossier's Aubio library.
+
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+
+*/
+
+#ifndef _ONSET_PLUGIN_H_
+#define _ONSET_PLUGIN_H_
+
+#include <vamp-sdk/Plugin.h>
+#include <aubio/aubio.h>
+
+class Onset : public Vamp::Plugin
+{
+public:
+    Onset(float inputSampleRate);
+    virtual ~Onset();
+
+    bool initialise(size_t channels, size_t stepSize, size_t blockSize);
+    void reset();
+
+    InputDomain getInputDomain() const { return TimeDomain; }
+
+    std::string getName() const;
+    std::string getDescription() const;
+    std::string getMaker() const;
+    int getPluginVersion() const;
+    std::string getCopyright() const;
+
+    ParameterList getParameterDescriptors() const;
+    float getParameter(std::string) const;
+    void setParameter(std::string, float);
+
+    size_t getPreferredStepSize() const;
+    size_t getPreferredBlockSize() const;
+
+    OutputList getOutputDescriptors() const;
+
+    FeatureSet process(float **inputBuffers, Vamp::RealTime timestamp);
+
+    FeatureSet getRemainingFeatures();
+
+protected:
+    fvec_t *m_ibuf;
+    cvec_t *m_fftgrain;
+    fvec_t *m_onset;
+    aubio_pvoc_t *m_pv;
+    aubio_pickpeak_t *m_peakpick;
+    aubio_onsetdetection_t *m_onsetdet;
+    aubio_onsetdetection_type m_onsettype;
+    float m_threshold;
+    float m_silence;
+    size_t m_stepSize;
+    size_t m_blockSize;
+    size_t m_channelCount;
+};
+
+
+#endif
diff --git a/plugins/Pitch.cpp b/plugins/Pitch.cpp
new file mode 100644 (file)
index 0000000..2c43f45
--- /dev/null
@@ -0,0 +1,196 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Vamp feature extraction plugins using Paul Brossier's Aubio library.
+
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+
+*/
+
+#include "Pitch.h"
+
+using std::string;
+using std::vector;
+using std::cerr;
+using std::endl;
+
+Pitch::Pitch(float inputSampleRate) :
+    Plugin(inputSampleRate),
+    m_ibuf(0),
+    m_pitchdet(0),
+    m_pitchtype(aubio_pitch_fcomb),
+    m_pitchmode(aubio_pitchm_freq)
+{
+}
+
+Pitch::~Pitch()
+{
+    if (m_pitchdet) del_aubio_pitchdetection(m_pitchdet);
+    if (m_ibuf) del_fvec(m_ibuf);
+}
+
+string
+Pitch::getName() const
+{
+    return "aubiopitch";
+}
+
+string
+Pitch::getDescription() const
+{
+    return "Aubio Pitch Detector";
+}
+
+string
+Pitch::getMaker() const
+{
+    return "Paul Brossier (plugin by Chris Cannam)";
+}
+
+int
+Pitch::getPluginVersion() const
+{
+    return 1;
+}
+
+string
+Pitch::getCopyright() const
+{
+    return "GPL";
+}
+
+bool
+Pitch::initialise(size_t channels, size_t stepSize, size_t blockSize)
+{
+    m_channelCount = channels;
+    m_stepSize = stepSize;
+    m_blockSize = blockSize;
+
+    m_ibuf = new_fvec(stepSize, channels);
+
+    m_pitchdet = new_aubio_pitchdetection(blockSize * 4,
+                                          stepSize,
+                                          channels,
+                                          lrintf(m_inputSampleRate),
+                                          m_pitchtype,
+                                          m_pitchmode);
+
+    return true;
+}
+
+void
+Pitch::reset()
+{
+}
+
+size_t
+Pitch::getPreferredStepSize() const
+{
+    return 512;
+}
+
+size_t
+Pitch::getPreferredBlockSize() const
+{
+    return 1024;
+}
+
+Pitch::ParameterList
+Pitch::getParameterDescriptors() const
+{
+    ParameterList list;
+    
+    ParameterDescriptor desc;
+    desc.name = "pitchtype";
+    desc.description = "Pitch Detection Function Type";
+    desc.minValue = 0;
+    desc.maxValue = 4;
+    desc.defaultValue = (int)aubio_pitch_fcomb;
+    desc.isQuantized = true;
+    desc.quantizeStep = 1;
+    desc.valueNames.push_back("YIN Frequency Estimator");
+    desc.valueNames.push_back("Spectral Comb");
+    desc.valueNames.push_back("Schmitt");
+    desc.valueNames.push_back("Fast Harmonic Comb");
+    desc.valueNames.push_back("YIN with FFT");
+    list.push_back(desc);
+
+    return list;
+}
+
+float
+Pitch::getParameter(std::string param) const
+{
+    if (param == "pitchtype") {
+        return m_pitchtype;
+    } else {
+        return 0.0;
+    }
+}
+
+void
+Pitch::setParameter(std::string param, float value)
+{
+    if (param == "pitchtype") {
+        switch (lrintf(value)) {
+        case 0: m_pitchtype = aubio_pitch_yin; break;
+        case 1: m_pitchtype = aubio_pitch_mcomb; break;
+        case 2: m_pitchtype = aubio_pitch_schmitt; break;
+        case 3: m_pitchtype = aubio_pitch_fcomb; break;
+        case 4: m_pitchtype = aubio_pitch_yinfft; break;
+        }
+    }
+}
+
+Pitch::OutputList
+Pitch::getOutputDescriptors() const
+{
+    OutputList list;
+
+    OutputDescriptor d;
+    d.name = "frequency";
+    d.unit = "Hz";
+    d.description = "Frequency";
+    d.hasFixedBinCount = true;
+    d.binCount = 1;
+    d.hasKnownExtents = false;
+    d.isQuantized = false;
+    d.sampleType = OutputDescriptor::OneSamplePerStep;
+    list.push_back(d);
+
+    return list;
+}
+
+Pitch::FeatureSet
+Pitch::process(float **inputBuffers, Vamp::RealTime /* timestamp */)
+{
+    for (size_t i = 0; i < m_stepSize; ++i) {
+        for (size_t j = 0; j < m_channelCount; ++j) {
+            fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i);
+        }
+    }
+
+    float pitch = aubio_pitchdetection(m_pitchdet, m_ibuf);
+
+    Feature feature;
+    feature.hasTimestamp = false;
+    feature.values.push_back(pitch);
+
+    FeatureSet returnFeatures;
+    returnFeatures[0].push_back(feature);
+    return returnFeatures;
+}
+
+Pitch::FeatureSet
+Pitch::getRemainingFeatures()
+{
+    return FeatureSet();
+}
+
diff --git a/plugins/Pitch.h b/plugins/Pitch.h
new file mode 100644 (file)
index 0000000..1752737
--- /dev/null
@@ -0,0 +1,64 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Vamp feature extraction plugins using Paul Brossier's Aubio library.
+
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+
+*/
+
+#ifndef _PITCH_PLUGIN_H_
+#define _PITCH_PLUGIN_H_
+
+#include <vamp-sdk/Plugin.h>
+#include <aubio/aubio.h>
+
+class Pitch : public Vamp::Plugin
+{
+public:
+    Pitch(float inputSampleRate);
+    virtual ~Pitch();
+
+    bool initialise(size_t channels, size_t stepSize, size_t blockSize);
+    void reset();
+
+    InputDomain getInputDomain() const { return TimeDomain; }
+
+    std::string getName() const;
+    std::string getDescription() const;
+    std::string getMaker() const;
+    int getPluginVersion() const;
+    std::string getCopyright() const;
+
+    ParameterList getParameterDescriptors() const;
+    float getParameter(std::string) const;
+    void setParameter(std::string, float);
+
+    size_t getPreferredStepSize() const;
+    size_t getPreferredBlockSize() const;
+
+    OutputList getOutputDescriptors() const;
+
+    FeatureSet process(float **inputBuffers, Vamp::RealTime timestamp);
+
+    FeatureSet getRemainingFeatures();
+
+protected:
+    fvec_t *m_ibuf;
+    aubio_pitchdetection_t *m_pitchdet;
+    aubio_pitchdetection_type m_pitchtype;
+    aubio_pitchdetection_mode m_pitchmode;
+    size_t m_stepSize;
+    size_t m_blockSize;
+    size_t m_channelCount;
+};
+
+
+#endif