changeset 70:d26c85099215

* Support latest changes to Vamp API (value names for parameters, FFT alignment, value -> bin terminology change)
author Chris Cannam
date Wed, 05 Apr 2006 16:52:30 +0000
parents 57a78e7e4ad3
children e32c6a6cb40f
files base/System.h transform/FeatureExtractionPluginTransform.cpp transform/FeatureExtractionPluginTransform.h
diffstat 3 files changed, 86 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/base/System.h	Mon Apr 03 17:18:27 2006 +0000
+++ b/base/System.h	Wed Apr 05 16:52:30 2006 +0000
@@ -50,9 +50,18 @@
 #define DLCLOSE(a)   dlclose((a))
 #define DLERROR()    dlerror()
 
+#ifdef __APPLE__
+
+#define PLUGIN_GLOB  "*.dylib"
+
+#else 
+
 #define PLUGIN_GLOB  "*.so"
 
-#endif
+#endif /* __APPLE__ */
 
-#endif
+#endif /* ! _WIN32 */
 
+#endif /* ! _SYSTEM_H_ */
+
+
--- a/transform/FeatureExtractionPluginTransform.cpp	Mon Apr 03 17:18:27 2006 +0000
+++ b/transform/FeatureExtractionPluginTransform.cpp	Wed Apr 05 16:52:30 2006 +0000
@@ -101,14 +101,14 @@
     std::cerr << "FeatureExtractionPluginTransform: output sample type "
 	      << m_descriptor->sampleType << std::endl;
 
-    int valueCount = 1;
+    int binCount = 1;
     float minValue = 0.0, maxValue = 0.0;
     
-    if (m_descriptor->hasFixedValueCount) {
-	valueCount = m_descriptor->valueCount;
+    if (m_descriptor->hasFixedBinCount) {
+	binCount = m_descriptor->binCount;
     }
 
-    if (valueCount > 0 && m_descriptor->hasKnownExtents) {
+    if (binCount > 0 && m_descriptor->hasKnownExtents) {
 	minValue = m_descriptor->minValue;
 	maxValue = m_descriptor->maxValue;
     }
@@ -133,12 +133,12 @@
 	break;
     }
 
-    if (valueCount == 0) {
+    if (binCount == 0) {
 
 	m_output = new SparseOneDimensionalModel(modelRate, modelResolution,
 						 false);
 
-    } else if (valueCount == 1 ||
+    } else if (binCount == 1 ||
 
 	       // We don't have a sparse 3D model
 	       m_descriptor->sampleType ==
@@ -153,12 +153,12 @@
     } else {
 	
 	m_output = new DenseThreeDimensionalModel(modelRate, modelResolution,
-						  valueCount, false);
+						  binCount, false);
 
-	if (!m_descriptor->valueNames.empty()) {
+	if (!m_descriptor->binNames.empty()) {
 	    std::vector<QString> names;
-	    for (size_t i = 0; i < m_descriptor->valueNames.size(); ++i) {
-		names.push_back(m_descriptor->valueNames[i].c_str());
+	    for (size_t i = 0; i < m_descriptor->binNames.size(); ++i) {
+		names.push_back(m_descriptor->binNames[i].c_str());
 	    }
 	    (dynamic_cast<DenseThreeDimensionalModel *>(m_output))
 		->setBinNames(names);
@@ -233,54 +233,52 @@
         }
     }
 
-    size_t startFrame = m_input->getStartFrame();
-    size_t   endFrame = m_input->getEndFrame();
-    size_t blockFrame = startFrame;
+    long startFrame = m_input->getStartFrame();
+    long   endFrame = m_input->getEndFrame();
+    long blockFrame = startFrame;
 
-    size_t prevCompletion = 0;
+    long prevCompletion = 0;
 
-    while (blockFrame < endFrame) {
+    while (1) {
+
+        if (fftPlan) {
+            if (blockFrame - m_blockSize/2 > endFrame) break;
+        } else {
+            if (blockFrame >= endFrame) break;
+        }
 
 //	std::cerr << "FeatureExtractionPluginTransform::run: blockFrame "
 //		  << blockFrame << std::endl;
 
-	size_t completion =
+	long completion =
 	    (((blockFrame - startFrame) / m_stepSize) * 99) /
 	    (   (endFrame - startFrame) / m_stepSize);
 
 	// channelCount is either m_input->channelCount or 1
 
-	size_t got = 0;
-
-	if (channelCount == 1) {
-	    got = input->getValues
-		(m_channel, blockFrame, blockFrame + m_blockSize, buffers[0]);
-	    while (got < m_blockSize) {
-		buffers[0][got++] = 0.0;
-	    }
-	} else {
-	    for (size_t ch = 0; ch < channelCount; ++ch) {
-		got = input->getValues
-		    (ch, blockFrame, blockFrame + m_blockSize, buffers[ch]);
-		while (got < m_blockSize) {
-		    buffers[ch][got++] = 0.0;
-		}
-	    }
-	}
-
+        for (int ch = 0; ch < channelCount; ++ch) {
+            if (fftPlan) {
+                getFrames(ch, channelCount, 
+                          blockFrame - m_blockSize/2, m_blockSize, buffers[ch]);
+            } else {
+                getFrames(ch, channelCount, 
+                           blockFrame, m_blockSize, buffers[ch]);
+            }                
+        }
+        
         if (fftPlan) {
-            for (size_t ch = 0; ch < channelCount; ++ch) {
-                for (size_t i = 0; i < m_blockSize; ++i) {
+            for (int ch = 0; ch < channelCount; ++ch) {
+                for (int i = 0; i < m_blockSize; ++i) {
                     fftInput[i] = buffers[ch][i];
                 }
                 windower.cut(fftInput);
-                for (size_t i = 0; i < m_blockSize/2; ++i) {
+                for (int i = 0; i < m_blockSize/2; ++i) {
                     double temp = fftInput[i];
                     fftInput[i] = fftInput[i + m_blockSize/2];
                     fftInput[i + m_blockSize/2] = temp;
                 }
                 fftw_execute(fftPlan);
-                for (size_t i = 0; i < m_blockSize/2; ++i) {
+                for (int i = 0; i < m_blockSize/2; ++i) {
                     buffers[ch][i*2] = fftOutput[i][0];
                     buffers[ch][i*2 + 1] = fftOutput[i][1];
                 }
@@ -321,6 +319,32 @@
     setCompletion(100);
 }
 
+void
+FeatureExtractionPluginTransform::getFrames(int channel, int channelCount,
+                                            long startFrame, long size,
+                                            float *buffer)
+{
+    long offset = 0;
+
+    if (startFrame < 0) {
+        for (int i = 0; i < size && startFrame + i < 0; ++i) {
+            buffer[i] = 0.0f;
+        }
+        offset = -startFrame;
+        size -= offset;
+        if (size <= 0) return;
+        startFrame = 0;
+    }
+
+    size_t got = getInput()->getValues
+        ((channelCount == 1 ? m_channel : channel),
+         startFrame, startFrame + size, buffer + offset);
+
+    while (got < size) {
+        buffer[offset + got] = 0.0;
+        ++got;
+    }
+}
 
 void
 FeatureExtractionPluginTransform::addFeature(size_t blockFrame,
@@ -331,9 +355,9 @@
 //    std::cerr << "FeatureExtractionPluginTransform::addFeature("
 //	      << blockFrame << ")" << std::endl;
 
-    int valueCount = 1;
-    if (m_descriptor->hasFixedValueCount) {
-	valueCount = m_descriptor->valueCount;
+    int binCount = 1;
+    if (m_descriptor->hasFixedBinCount) {
+	binCount = m_descriptor->binCount;
     }
 
     size_t frame = blockFrame;
@@ -363,13 +387,13 @@
 	}
     }
 	
-    if (valueCount == 0) {
+    if (binCount == 0) {
 
 	SparseOneDimensionalModel *model = getOutput<SparseOneDimensionalModel>();
 	if (!model) return;
 	model->addPoint(SparseOneDimensionalModel::Point(frame, feature.label.c_str()));
 	
-    } else if (valueCount == 1 ||
+    } else if (binCount == 1 ||
 	       m_descriptor->sampleType == 
 	       Vamp::Plugin::OutputDescriptor::VariableSampleRate) {
 
@@ -394,18 +418,18 @@
 void
 FeatureExtractionPluginTransform::setCompletion(int completion)
 {
-    int valueCount = 1;
-    if (m_descriptor->hasFixedValueCount) {
-	valueCount = m_descriptor->valueCount;
+    int binCount = 1;
+    if (m_descriptor->hasFixedBinCount) {
+	binCount = m_descriptor->binCount;
     }
 
-    if (valueCount == 0) {
+    if (binCount == 0) {
 
 	SparseOneDimensionalModel *model = getOutput<SparseOneDimensionalModel>();
 	if (!model) return;
 	model->setCompletion(completion);
 
-    } else if (valueCount == 1 ||
+    } else if (binCount == 1 ||
 	       m_descriptor->sampleType ==
 	       Vamp::Plugin::OutputDescriptor::VariableSampleRate) {
 
--- a/transform/FeatureExtractionPluginTransform.h	Mon Apr 03 17:18:27 2006 +0000
+++ b/transform/FeatureExtractionPluginTransform.h	Wed Apr 05 16:52:30 2006 +0000
@@ -47,6 +47,9 @@
 
     void setCompletion(int);
 
+    void getFrames(int channel, int channelCount,
+                   long startFrame, long size, float *buffer);
+
     // just casts
     DenseTimeValueModel *getInput();
     template <typename ModelClass> ModelClass *getOutput() {