changeset 167:31eda4b11f2b

* First bit of Vamp v2 work -- add an optional duration to features in a backward compatible way. Warning: this code is unstable and experimental and may change significantly in the coming weeks.
author cannam
date Thu, 17 Jul 2008 08:52:26 +0000
parents 120f88880347
children 006a775133b1
files Makefile host/vamp-simple-host.cpp vamp-sdk/Plugin.h vamp-sdk/PluginAdapter.cpp vamp-sdk/PluginBase.h vamp-sdk/PluginHostAdapter.cpp vamp/vamp.h
diffstat 7 files changed, 91 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Wed Jul 09 11:00:16 2008 +0000
+++ b/Makefile	Thu Jul 17 08:52:26 2008 +0000
@@ -36,12 +36,8 @@
 RANLIB		:= ranlib
 
 # Libraries required for the plugins.
-# (Note that it is desirable to statically link libstdc++ if possible,
-# because our plugin exposes only a C API so there are no boundary
-# compatibility problems.)
 #
-#PLUGIN_LIBS	= $(SDKDIR)/libvamp-sdk.a
-PLUGIN_LIBS	= $(SDKDIR)/libvamp-sdk.a $(shell g++ -print-file-name=libstdc++.a)
+PLUGIN_LIBS	= $(SDKDIR)/libvamp-sdk.a
 
 # File extension for a dynamically loadable object
 #
--- a/host/vamp-simple-host.cpp	Wed Jul 09 11:00:16 2008 +0000
+++ b/host/vamp-simple-host.cpp	Thu Jul 17 08:52:26 2008 +0000
@@ -434,7 +434,15 @@
                     (features[output][i].timestamp, sr);
             }
 
-            (out ? *out : cout) << displayFrame << ":";
+            (out ? *out : cout) << displayFrame;
+
+            if (features[output][i].hasDuration) {
+                displayFrame = RealTime::realTime2Frame
+                    (features[output][i].duration, sr);
+                (out ? *out : cout) << "," << displayFrame;
+            }
+
+            (out ? *out : cout)  << ":";
 
         } else {
 
@@ -444,7 +452,14 @@
                 rt = features[output][i].timestamp;
             }
 
-            (out ? *out : cout) << rt.toString() << ":";
+            (out ? *out : cout) << rt.toString();
+
+            if (features[output][i].hasDuration) {
+                rt = features[output][i].duration;
+                (out ? *out : cout) << "," << rt.toString();
+            }
+
+            (out ? *out : cout) << ":";
         }
 
         for (unsigned int j = 0; j < features[output][i].values.size(); ++j) {
--- a/vamp-sdk/Plugin.h	Wed Jul 09 11:00:16 2008 +0000
+++ b/vamp-sdk/Plugin.h	Thu Jul 17 08:52:26 2008 +0000
@@ -304,6 +304,10 @@
 	 * this to zero if that behaviour is not desired.
 	 */
 	float sampleRate;
+
+        OutputDescriptor() : // defaults for mandatory non-class-type members
+            hasFixedBinCount(false), hasKnownExtents(false), isQuantized(false),
+            sampleType(OneSamplePerStep) { }
     };
 
     typedef std::vector<OutputDescriptor> OutputList;
@@ -319,17 +323,34 @@
     {
 	/**
 	 * True if an output feature has its own timestamp.  This is
-	 * mandatory if the output has VariableSampleRate, and is
-	 * likely to be disregarded otherwise.
+	 * mandatory if the output has VariableSampleRate, optional if
+	 * the output has FixedSampleRate, and unused if the output
+	 * has OneSamplePerStep.
 	 */
 	bool hasTimestamp;
 
 	/**
 	 * Timestamp of the output feature.  This is mandatory if the
-	 * output has VariableSampleRate, and is likely to be
-	 * disregarded otherwise.  Undefined if hasTimestamp is false.
+	 * output has VariableSampleRate or if the output has
+	 * FixedSampleRate and hasTimestamp is true, and unused
+	 * otherwise.
 	 */
 	RealTime timestamp;
+
+        /**
+         * True if an output feature has a specified duration.  This
+         * is optional if the output has VariableSampleRate or
+         * FixedSampleRate, and and unused if the output has
+         * OneSamplePerStep.
+         */
+        bool hasDuration;
+
+        /**
+         * Duration of the output feature.  This is mandatory if the
+         * output has VariableSampleRate or FixedSampleRate and
+         * hasDuration is true, and unused otherwise.
+         */
+        RealTime duration;
 	
 	/**
 	 * Results for a single sample of this feature.  If the output
@@ -342,9 +363,13 @@
 	 * Label for the sample of this feature.
 	 */
 	std::string label;
+
+        Feature() : // defaults for mandatory non-class-type members
+            hasTimestamp(false), hasDuration(false) { }
     };
 
     typedef std::vector<Feature> FeatureList;
+
     typedef std::map<int, FeatureList> FeatureSet; // key is output no
 
     /**
--- a/vamp-sdk/PluginAdapter.cpp	Wed Jul 09 11:00:16 2008 +0000
+++ b/vamp-sdk/PluginAdapter.cpp	Thu Jul 17 08:52:26 2008 +0000
@@ -55,7 +55,7 @@
     PluginAdapterBase *m_base;
 
     static VampPluginHandle vampInstantiate(const VampPluginDescriptor *desc,
-                                          float inputSampleRate);
+                                            float inputSampleRate);
 
     static void vampCleanup(VampPluginHandle handle);
 
@@ -592,6 +592,7 @@
                 }
             }
             if (list[i].features) free(list[i].features);
+            if (list[i].featuresV2) free(list[i].featuresV2);
         }
         m_fs.erase(plugin);
         m_fsizes.erase(plugin);
@@ -707,7 +708,7 @@
 
 VampFeatureList *
 PluginAdapterBase::Impl::convertFeatures(Plugin *plugin,
-                                   const Plugin::FeatureSet &features)
+                                         const Plugin::FeatureSet &features)
 {
     int lastN = -1;
 
@@ -752,6 +753,12 @@
             feature->nsec = fl[j].timestamp.nsec;
             feature->valueCount = fl[j].values.size();
 
+            VampFeatureV2 *v2 = &fs[n].featuresV2[j];
+            
+            v2->hasDuration = fl[j].hasDuration;
+            v2->durationSec = fl[j].duration.sec;
+            v2->durationNsec = fl[j].duration.nsec;
+
             if (feature->label) free(feature->label);
 
             if (fl[j].label.empty()) {
@@ -800,6 +807,7 @@
     while (i < n) {
         m_fs[plugin][i].featureCount = 0;
         m_fs[plugin][i].features = 0;
+        m_fs[plugin][i].featuresV2 = 0;
         m_fsizes[plugin].push_back(0);
         m_fvsizes[plugin].push_back(std::vector<size_t>());
         i++;
@@ -820,10 +828,15 @@
     m_fs[plugin][n].features = (VampFeature *)realloc
         (m_fs[plugin][n].features, sz * sizeof(VampFeature));
 
+    m_fs[plugin][n].featuresV2 = (VampFeatureV2 *)realloc
+        (m_fs[plugin][n].featuresV2, sz * sizeof(VampFeatureV2));
+
     while (m_fsizes[plugin][n] < sz) {
+        m_fs[plugin][n].features[m_fsizes[plugin][n]].hasTimestamp = 0;
         m_fs[plugin][n].features[m_fsizes[plugin][n]].valueCount = 0;
         m_fs[plugin][n].features[m_fsizes[plugin][n]].values = 0;
         m_fs[plugin][n].features[m_fsizes[plugin][n]].label = 0;
+        m_fs[plugin][n].featuresV2[m_fsizes[plugin][n]].hasDuration = 0;
         m_fvsizes[plugin][n].push_back(0);
         m_fsizes[plugin][n]++;
     }
--- a/vamp-sdk/PluginBase.h	Wed Jul 09 11:00:16 2008 +0000
+++ b/vamp-sdk/PluginBase.h	Thu Jul 17 08:52:26 2008 +0000
@@ -64,7 +64,7 @@
     /**
      * Get the Vamp API compatibility level of the plugin.
      */
-    virtual unsigned int getVampApiVersion() const { return 1; }
+    virtual unsigned int getVampApiVersion() const { return 2; }
 
     /**
      * Get the computer-usable name of the plugin.  This should be
@@ -190,6 +190,9 @@
          * encoded in the names.
          */
         std::vector<std::string> valueNames;
+
+        ParameterDescriptor() : // the defaults are invalid: you must set them
+            minValue(0), maxValue(0), defaultValue(0), isQuantized(false) { }
     };
 
     typedef std::vector<ParameterDescriptor> ParameterList;
--- a/vamp-sdk/PluginHostAdapter.cpp	Wed Jul 09 11:00:16 2008 +0000
+++ b/vamp-sdk/PluginHostAdapter.cpp	Thu Jul 17 08:52:26 2008 +0000
@@ -404,6 +404,14 @@
                 feature.timestamp = RealTime(list.features[j].sec,
                                              list.features[j].nsec);
 
+                if (m_descriptor->vampApiVersion >= 2) {
+                    feature.hasDuration = list.featuresV2[j].hasDuration;
+                    feature.duration = RealTime(list.featuresV2[j].durationSec,
+                                                list.featuresV2[j].durationNsec);
+                } else {
+                    feature.hasDuration = false;
+                }
+
                 for (unsigned int k = 0; k < list.features[j].valueCount; ++k) {
                     feature.values.push_back(list.features[j].values[k]);
                 }
--- a/vamp/vamp.h	Wed Jul 09 11:00:16 2008 +0000
+++ b/vamp/vamp.h	Thu Jul 17 08:52:26 2008 +0000
@@ -50,7 +50,7 @@
  * See also the vampApiVersion field in the plugin descriptor, and the
  * hostApiVersion argument to the vampGetPluginDescriptor function.
  */
-#define VAMP_API_VERSION 1
+#define VAMP_API_VERSION 2
 
 /**
  * C language API for Vamp plugins.
@@ -184,6 +184,19 @@
 
 } VampFeature;
 
+typedef struct _VampFeatureV2
+{
+    /** 1 if the feature has a duration. */
+    int hasDuration;
+
+    /** Seconds component of duratiion. */
+    int durationSec;
+
+    /** Nanoseconds component of duration. */
+    int durationNsec;
+
+} VampFeatureV2;
+
 typedef struct _VampFeatureList
 {
     /** Number of features in this feature list. */
@@ -192,6 +205,9 @@
     /** Features in this feature list.  May be NULL if featureCount is zero. */
     VampFeature *features;
 
+    /** Vamp 2.0 extended information for features in this feature list. */
+    VampFeatureV2 *featuresV2;
+
 } VampFeatureList;
 
 typedef enum