changeset 31:c6d230c31713

Stubbing out Vamp plugin
author Chris Cannam
date Thu, 03 Apr 2014 17:38:45 +0100
parents d697e78f81f1
children da54468cc452
files .hgsub .hgsubstate Makefile.inc Makefile.linux src/Silvet.cpp src/Silvet.h src/libmain.cpp vamp-plugin.map
diffstat 8 files changed, 408 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgsub	Thu Apr 03 17:38:45 2014 +0100
@@ -0,0 +1,1 @@
+constant-q-cpp = https://code.soundsoftware.ac.uk/hg/constant-q-cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgsubstate	Thu Apr 03 17:38:45 2014 +0100
@@ -0,0 +1,1 @@
+320aa9b3a2de3501a8e999319ad49862354416a1 constant-q-cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile.inc	Thu Apr 03 17:38:45 2014 +0100
@@ -0,0 +1,49 @@
+
+SRC_DIR  := src
+
+QMDSP_DIR ?= ../qm-dsp
+VAMPSDK_DIR  ?= ../vamp-plugin-sdk
+
+CQ_DIR	     ?= constant-q-cpp/cpp-qm-dsp
+
+PLUGIN_EXT	?= .so
+
+CXX	?= g++
+CC	?= gcc
+
+CFLAGS := $(CFLAGS) 
+CXXFLAGS := -I. -I$(VAMPSDK_DIR) -I$(QMDSP_DIR) $(CXXFLAGS)
+
+LDFLAGS := $(LDFLAGS) 
+PLUGIN_LDFLAGS := $(LDFLAGS) $(PLUGIN_LDFLAGS)
+
+PLUGIN	:= silvet$(PLUGIN_EXT)
+
+VAMP_HEADERS := $(SRC_DIR)/Silvet.h
+VAMP_SOURCES := $(SRC_DIR)/Silvet.cpp $(SRC_DIR)/libmain.cpp
+
+CQ_HEADERS   := $(CQ_DIR)/CQKernel.h $(CQ_DIR)/ConstantQ.h
+CQ_SOURCES   := $(CQ_DIR)/CQKernel.cpp $(CQ_DIR)/ConstantQ.cpp
+
+HEADERS	     := $(VAMP_HEADERS) $(CQ_HEADERS)
+SOURCES	     := $(VAMP_SOURCES) $(CQ_SOURCES)
+OBJECTS	     := $(SOURCES:.cpp=.o)
+
+LIBS	:= $(QMDSP_DIR)/libqm-dsp.a $(VAMPSDK_DIR)/libvamp-sdk.a -lpthread
+
+all: $(PLUGIN)
+
+$(PLUGIN):	$(OBJECTS)
+	$(CXX) -o $@ $^ $(LIBS) $(PLUGIN_LDFLAGS)
+
+clean:		
+	rm -f $(OBJECTS)
+
+distclean:	clean
+	rm -f $(PLUGIN)
+
+depend:
+	makedepend -Y -fMakefile.inc $(SOURCES) $(HEADERS)
+
+# DO NOT DELETE
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile.linux	Thu Apr 03 17:38:45 2014 +0100
@@ -0,0 +1,13 @@
+
+CFLAGS := -Wall -O3 -fPIC -I../vamp-plugin-sdk/
+#CFLAGS := -g -fPIC -I../vamp-plugin-sdk
+
+CXXFLAGS := $(CFLAGS)
+
+VAMPSDK_DIR := ../vamp-plugin-sdk
+PLUGIN_LDFLAGS := -shared -Wl,--version-script=vamp-plugin.map
+
+PLUGIN_EXT := .so
+
+include Makefile.inc
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Silvet.cpp	Thu Apr 03 17:38:45 2014 +0100
@@ -0,0 +1,236 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+  Silvet
+
+  A Vamp plugin for note transcription.
+  Centre for Digital Music, Queen Mary University of London.
+    
+  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 "Silvet.h"
+
+#include "data/include/templates.h"
+
+#include "dsp/rateconversion/Resampler.h"
+
+#include "constant-q-cpp/cpp-qm-dsp/ConstantQ.h"
+
+#include <vector>
+
+using std::vector;
+using std::cerr;
+using std::endl;
+
+static int processingSampleRate = 44100;
+static int processingBPO = 60;
+
+
+Silvet::Silvet(float inputSampleRate) :
+    Plugin(inputSampleRate),
+    m_resampler(0),
+    m_cq(0)
+{
+}
+
+Silvet::~Silvet()
+{
+    delete m_resampler;
+    delete m_cq;
+}
+
+string
+Silvet::getIdentifier() const
+{
+    return "silvet";
+}
+
+string
+Silvet::getName() const
+{
+    return "Silvet Note Transcription";
+}
+
+string
+Silvet::getDescription() const
+{
+    // Return something helpful here!
+    return "";
+}
+
+string
+Silvet::getMaker() const
+{
+    // Your name here
+    return "";
+}
+
+int
+Silvet::getPluginVersion() const
+{
+    return 1;
+}
+
+string
+Silvet::getCopyright() const
+{
+    // This function is not ideally named.  It does not necessarily
+    // need to say who made the plugin -- getMaker does that -- but it
+    // should indicate the terms under which it is distributed.  For
+    // example, "Copyright (year). All Rights Reserved", or "GPL"
+    return "";
+}
+
+Silvet::InputDomain
+Silvet::getInputDomain() const
+{
+    return TimeDomain;
+}
+
+size_t
+Silvet::getPreferredBlockSize() const
+{
+    return 0;
+}
+
+size_t 
+Silvet::getPreferredStepSize() const
+{
+    return 0;
+}
+
+size_t
+Silvet::getMinChannelCount() const
+{
+    return 1;
+}
+
+size_t
+Silvet::getMaxChannelCount() const
+{
+    return 1;
+}
+
+Silvet::ParameterList
+Silvet::getParameterDescriptors() const
+{
+    ParameterList list;
+    return list;
+}
+
+float
+Silvet::getParameter(string identifier) const
+{
+    return 0;
+}
+
+void
+Silvet::setParameter(string identifier, float value) 
+{
+}
+
+Silvet::ProgramList
+Silvet::getPrograms() const
+{
+    ProgramList list;
+    return list;
+}
+
+string
+Silvet::getCurrentProgram() const
+{
+    return ""; 
+}
+
+void
+Silvet::selectProgram(string name)
+{
+}
+
+Silvet::OutputList
+Silvet::getOutputDescriptors() const
+{
+    OutputList list;
+
+    OutputDescriptor d;
+    d.identifier = "transcription";
+    d.name = "Transcription";
+    d.description = ""; //!!!
+    d.unit = "Hz";
+    d.hasFixedBinCount = true;
+    d.binCount = 2;
+    d.binNames.push_back("Frequency");
+    d.binNames.push_back("Velocity");
+    d.hasKnownExtents = false;
+    d.isQuantized = false;
+    d.sampleType = OutputDescriptor::VariableSampleRate;
+    d.sampleRate = 0;
+    d.hasDuration = true;
+    list.push_back(d);
+
+    return list;
+}
+
+bool
+Silvet::initialise(size_t channels, size_t stepSize, size_t blockSize)
+{
+    if (channels < getMinChannelCount() ||
+	channels > getMaxChannelCount()) return false;
+
+    if (stepSize != blockSize) {
+	cerr << "Silvet::initialise: Step size must be the same as block size ("
+	     << stepSize << " != " << blockSize << ")" << endl;
+	return false;
+    }
+
+    m_blockSize = blockSize;
+
+    reset();
+
+    return true;
+}
+
+void
+Silvet::reset()
+{
+    delete m_resampler;
+    delete m_cq;
+
+    if (m_inputSampleRate != processingSampleRate) {
+	m_resampler = new Resampler(m_inputSampleRate, processingSampleRate);
+    } else {
+	m_resampler = 0;
+    }
+
+    m_cq = new ConstantQ
+	(processingSampleRate, 27.5, processingSampleRate / 3, processingBPO);
+
+}
+
+Silvet::FeatureSet
+Silvet::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
+{
+    vector<double> data;
+    for (int i = 0; i < m_blockSize; ++i) data.push_back(inputBuffers[0][i]);
+
+    if (m_resampler) {
+	data = m_resampler->process(data.data(), data.size());
+    }
+
+    vector<vector<double> > cqout = m_cq->process(data);
+
+    return FeatureSet();
+}
+
+Silvet::FeatureSet
+Silvet::getRemainingFeatures()
+{
+
+    return FeatureSet();
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Silvet.h	Thu Apr 03 17:38:45 2014 +0100
@@ -0,0 +1,70 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+  Silvet
+
+  A Vamp plugin for note transcription.
+  Centre for Digital Music, Queen Mary University of London.
+    
+  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 SILVET_H
+#define SILVET_H
+
+#include <vamp-sdk/Plugin.h>
+
+using std::string;
+
+class Resampler;
+class ConstantQ;
+
+class Silvet : public Vamp::Plugin
+{
+public:
+    Silvet(float inputSampleRate);
+    virtual ~Silvet();
+
+    string getIdentifier() const;
+    string getName() const;
+    string getDescription() const;
+    string getMaker() const;
+    int getPluginVersion() const;
+    string getCopyright() const;
+
+    InputDomain getInputDomain() const;
+    size_t getPreferredBlockSize() const;
+    size_t getPreferredStepSize() const;
+    size_t getMinChannelCount() const;
+    size_t getMaxChannelCount() const;
+
+    ParameterList getParameterDescriptors() const;
+    float getParameter(string identifier) const;
+    void setParameter(string identifier, float value);
+
+    ProgramList getPrograms() const;
+    string getCurrentProgram() const;
+    void selectProgram(string name);
+
+    OutputList getOutputDescriptors() const;
+
+    bool initialise(size_t channels, size_t stepSize, size_t blockSize);
+    void reset();
+
+    FeatureSet process(const float *const *inputBuffers,
+                       Vamp::RealTime timestamp);
+
+    FeatureSet getRemainingFeatures();
+
+protected:
+    Resampler *m_resampler;
+    ConstantQ *m_cq;
+
+    int m_blockSize;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/libmain.cpp	Thu Apr 03 17:38:45 2014 +0100
@@ -0,0 +1,34 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+  Silvet
+
+  A Vamp plugin for note transcription.
+  Centre for Digital Music, Queen Mary University of London.
+    
+  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 "Silvet.h"
+
+static Vamp::PluginAdapter<Silvet> silvetAdapter;
+
+const VampPluginDescriptor *
+vampGetPluginDescriptor(unsigned int version, unsigned int index)
+{
+    if (version < 1) return 0;
+
+    switch (index) {
+    case  0: return silvetAdapter.getDescriptor();
+    default: return 0;
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vamp-plugin.map	Thu Apr 03 17:38:45 2014 +0100
@@ -0,0 +1,4 @@
+{
+	global: vampGetPluginDescriptor;
+	local: *;
+};