changeset 2:8056c637875b ofa-vamp-plugin

* Divide into three plugins
author cannam
date Mon, 01 Oct 2007 09:09:26 +0000
parents 150ad38c1871
children 59654da9b928
files Makefile OfaVampPlugin.cpp OfaVampPlugin.h ofa-vamp-plugin.cat
diffstat 4 files changed, 152 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Sep 24 13:36:27 2007 +0000
+++ b/Makefile	Mon Oct 01 09:09:26 2007 +0000
@@ -1,5 +1,7 @@
 
-CXXFLAGS	:= -I../vamp-plugin-sdk -O3 -Wall -march=pentium4 -msse -msse2 -fomit-frame-pointer -ffast-math
+CXXFLAGS	:= -I../vamp-plugin-sdk -O2 -Wall
+
+#CXXFLAGS	:= -I../vamp-plugin-sdk -O3 -Wall -march=pentium4 -msse -msse2 -fomit-frame-pointer -ffast-math
 
 ofa-vamp-plugin.so:	OfaVampPlugin.o protocol.o
 	g++ -shared $^ -o $@ -L../vamp-plugin-sdk/vamp-sdk -Wl,-Bstatic -lvamp-sdk -Wl,-Bdynamic -lofa -lcurl -lexpat
--- a/OfaVampPlugin.cpp	Mon Sep 24 13:36:27 2007 +0000
+++ b/OfaVampPlugin.cpp	Mon Oct 01 09:09:26 2007 +0000
@@ -1,5 +1,18 @@
 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
 
+/*
+    Vamp feature extraction plugins using MusicIP OFA library.
+
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2007 QMUL.
+    
+    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 "OfaVampPlugin.h"
 
 #include <vamp/vamp.h>
@@ -17,8 +30,9 @@
 
 using std::string;
 
-OfaVampPlugin::OfaVampPlugin(float inputSampleRate) :
+OfaVampPlugin::OfaVampPlugin(float inputSampleRate, Type type) :
     Plugin(inputSampleRate),
+    m_type(type),
     m_buffer(0),
     m_bufsiz(0),
     m_bufidx(0),
@@ -35,27 +49,9 @@
 }
 
 string
-OfaVampPlugin::getIdentifier() const
-{
-    return "ofa";
-}
-
-string
-OfaVampPlugin::getName() const
-{
-    return "MusicIP OFA Audio Fingerprinter";
-}
-
-string
-OfaVampPlugin::getDescription() const
-{
-    return "Calculates an audio fingerprint using the MusicIP fingerprinting library";
-}
-
-string
 OfaVampPlugin::getMaker() const
 {
-    return "Chris Cannam";
+    return "Chris Cannam, using MusicIP OFA library";
 }
 
 int
@@ -67,7 +63,7 @@
 string
 OfaVampPlugin::getCopyright() const
 {
-    return ""; //!!!
+    return "GPL";
 }
 
 OfaVampPlugin::ParameterList
@@ -134,29 +130,46 @@
     OutputList list;
 
     OutputDescriptor desc;
-    desc.identifier = "fingerprint";
-    desc.name = "Fingerprint";
-    desc.description = "Single result containing the audio fingerprint as its label";
-    desc.unit = "";
-    desc.hasFixedBinCount = true;
-    desc.binCount = 0;
-    desc.hasKnownExtents = false;
-    desc.isQuantized = false;
-    desc.sampleType = OutputDescriptor::VariableSampleRate;
-    desc.sampleRate = m_inputSampleRate;
-    list.push_back(desc);
 
-    desc.identifier = "puid";
-    desc.name = "PUID";
-    desc.description = "Single result containing the MusicIP online PUID for this audio track, if available";
-    desc.unit = "";
-    desc.hasFixedBinCount = true;
-    desc.binCount = 0;
-    desc.hasKnownExtents = false;
-    desc.isQuantized = false;
-    desc.sampleType = OutputDescriptor::VariableSampleRate;
-    desc.sampleRate = m_inputSampleRate;
-    list.push_back(desc);
+    m_fingerprintResultIndex = -1;
+    m_puidResultIndex = -1;
+    int index = 0;
+
+    if (m_type == TypeFingerprint || m_type == TypeBoth) {
+
+        desc.identifier = "fingerprint";
+        desc.name = "Fingerprint";
+        desc.description = "Single result containing the audio fingerprint as its label";
+        desc.unit = "";
+        desc.hasFixedBinCount = true;
+        desc.binCount = 0;
+        desc.hasKnownExtents = false;
+        desc.isQuantized = false;
+        desc.sampleType = OutputDescriptor::VariableSampleRate;
+        desc.sampleRate = m_inputSampleRate;
+        list.push_back(desc);
+
+        m_fingerprintResultIndex = index;
+        ++index;
+    }
+
+    if (m_type == TypePUID || m_type == TypeBoth) {
+
+        desc.identifier = "puid";
+        desc.name = "PUID";
+        desc.description = "Single result containing the MusicIP online PUID for this audio track, if available";
+        desc.unit = "";
+        desc.hasFixedBinCount = true;
+        desc.binCount = 0;
+        desc.hasKnownExtents = false;
+        desc.isQuantized = false;
+        desc.sampleType = OutputDescriptor::VariableSampleRate;
+        desc.sampleRate = m_inputSampleRate;
+        list.push_back(desc);
+
+        m_puidResultIndex = index;
+        ++index;
+    }
 
     return list;
 }
@@ -220,12 +233,15 @@
 
         m_print = print;
 
-        Feature feature;
-        feature.hasTimestamp = true;
-        feature.timestamp = Vamp::RealTime::zeroTime;
-        feature.label = m_print;
-        fset[0].push_back(feature);
-        return fset;
+        if (m_fingerprintResultIndex >= 0) {
+
+            Feature feature;
+            feature.hasTimestamp = true;
+            feature.timestamp = Vamp::RealTime::zeroTime;
+            feature.label = m_print;
+            fset[m_fingerprintResultIndex].push_back(feature);
+            return fset;
+        }
     }
 
     return FeatureSet();
@@ -236,7 +252,7 @@
 {
     FeatureSet fset;
 
-    if (m_print == "") return fset;
+    if (m_print == "" || m_puidResultIndex < 0) return fset;
 
     Feature feature;
     feature.hasTimestamp = true;
@@ -272,13 +288,14 @@
         std::cerr << "Fingerprint was: " << m_print << std::endl;
     } else {
         feature.label = info->getPUID();
-        fset[1].push_back(feature);
+        fset[m_puidResultIndex].push_back(feature);
     }
 
     return fset;
 }
 
-static Vamp::PluginAdapter<OfaVampPlugin> ofaAdapter;
+static Vamp::PluginAdapter<OfaFingerprintPlugin> ofaFingerprintAdapter;
+static Vamp::PluginAdapter<OfaPUIDPlugin> ofaPUIDAdapter;
 
 const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int version,
                                                     unsigned int index)
@@ -286,7 +303,8 @@
     if (version < 1) return 0;
 
     switch (index) {
-    case  0: return ofaAdapter.getDescriptor();
+    case  0: return ofaFingerprintAdapter.getDescriptor();
+    case  1: return ofaPUIDAdapter.getDescriptor();
     default: return 0;
     }
 }
--- a/OfaVampPlugin.h	Mon Sep 24 13:36:27 2007 +0000
+++ b/OfaVampPlugin.h	Mon Oct 01 09:09:26 2007 +0000
@@ -1,16 +1,28 @@
 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
 
+/*
+    Vamp feature extraction plugins using MusicIP OFA library.
+
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2007 QMUL.
+    
+    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 _OFA_VAMP_PLUGIN_H_
 #define _OFA_VAMP_PLUGIN_H_
 
 #include <vamp-sdk/Plugin.h>
 
-#include <pthread.h>
-
 class OfaVampPlugin : public Vamp::Plugin
 {
 public:
-    OfaVampPlugin(float inputSampleRate);
+    enum Type { TypeFingerprint, TypePUID, TypeBoth };
+    OfaVampPlugin(float inputSampleRate, Type type);
     virtual ~OfaVampPlugin();
 
     bool initialise(size_t channels, size_t stepSize, size_t blockSize);
@@ -24,9 +36,6 @@
     size_t getMinChannelCount() const { return 1; }
     size_t getMaxChannelCount() const { return 2; }
 
-    std::string getIdentifier() const;
-    std::string getName() const;
-    std::string getDescription() const;
     std::string getMaker() const;
     int getPluginVersion() const;
     std::string getCopyright() const;
@@ -43,6 +52,9 @@
     FeatureSet getRemainingFeatures();
 
 protected:
+    Type m_type;
+    mutable int m_fingerprintResultIndex;
+    mutable int m_puidResultIndex;
     int16_t *m_buffer;
     size_t m_bufsiz;
     size_t m_bufidx;
@@ -53,5 +65,62 @@
     bool m_enough;
 };
 
+class OfaFingerprintPlugin : public OfaVampPlugin
+{
+public:
+    OfaFingerprintPlugin(float inputSampleRate) :
+        OfaVampPlugin(inputSampleRate, TypeFingerprint) { }
+
+    std::string getName() const { 
+        return "MusicIP Audio Fingerprinter";
+    }
+
+    std::string getDescription() const { 
+        return "Calculates an audio fingerprint using the MusicIP OFA fingerprinting library";
+    }
+
+    std::string getIdentifier() const {
+        return "ofa_fingerprint";
+    }
+};
+
+class OfaPUIDPlugin : public OfaVampPlugin
+{
+public:
+    OfaPUIDPlugin(float inputSampleRate) :
+        OfaVampPlugin(inputSampleRate, TypePUID) { }
+
+    std::string getName() const { 
+        return "MusicIP PUID Lookup";
+    }
+
+    std::string getDescription() const { 
+        return "Calculates an audio fingerprint using the MusicIP OFA fingerprinting library and uses it to look up a MusicDNS PUID";
+    }
+
+    std::string getIdentifier() const {
+        return "ofa_puid";
+    }
+};
+
+class OfaBothPlugin : public OfaVampPlugin
+{
+public:
+    OfaBothPlugin(float inputSampleRate) :
+        OfaVampPlugin(inputSampleRate, TypeBoth) { }
+
+    std::string getName() const { 
+        return "MusicIP Fingerprinter and PUID";
+    }
+
+    std::string getDescription() const { 
+        return "Calculates an audio fingerprint and PUID using the MusicIP OFA library";
+    }
+
+    std::string getIdentifier() const {
+        return "ofa_both";
+    }
+};
+
 
 #endif
--- a/ofa-vamp-plugin.cat	Mon Sep 24 13:36:27 2007 +0000
+++ b/ofa-vamp-plugin.cat	Mon Oct 01 09:09:26 2007 +0000
@@ -1,1 +1,3 @@
-vamp:ofa-vamp-plugin:ofa::Fingerprinting
+vamp:ofa-vamp-plugin:ofa_fingerprint::Fingerprinting
+vamp:ofa-vamp-plugin:ofa_puid::Fingerprinting
+vamp:ofa-vamp-plugin:ofa_both::Fingerprinting