diff transform/FeatureExtractionPluginTransform.cpp @ 182:21a76c9ed5c3

* Merge transform directory from sv-match-alignment branch (the previous comment included notes for this stuff, but I missed it in the actual merge) * Fix crash when a transform fails to create an output model and the thread that created the transform then deletes its input model thinking it's no longer needed, even though the transform run thread is still using it -- fix is to wait() on the transform before returning the null output model
author Chris Cannam
date Fri, 28 Sep 2007 16:15:06 +0000
parents dab257bd9d2d
children ebd906049fb6
line wrap: on
line diff
--- a/transform/FeatureExtractionPluginTransform.cpp	Fri Sep 28 14:32:45 2007 +0000
+++ b/transform/FeatureExtractionPluginTransform.cpp	Fri Sep 28 16:15:06 2007 +0000
@@ -220,6 +220,7 @@
 
 FeatureExtractionPluginTransform::~FeatureExtractionPluginTransform()
 {
+    std::cerr << "FeatureExtractionPluginTransform::~FeatureExtractionPluginTransform()" << std::endl;
     delete m_plugin;
     delete m_descriptor;
 }
@@ -241,6 +242,8 @@
     DenseTimeValueModel *input = getInput();
     if (!input) return;
 
+    if (!m_output) return;
+
     while (!input->isReady()) {
 /*
         if (dynamic_cast<WaveFileModel *>(input)) {
@@ -253,8 +256,6 @@
         sleep(1);
     }
 
-    if (!m_output) return;
-
     size_t sampleRate = m_input->getSampleRate();
 
     size_t channelCount = input->getChannelCount();
@@ -297,16 +298,35 @@
 
     long startFrame = m_input->getStartFrame();
     long   endFrame = m_input->getEndFrame();
-    long blockFrame = startFrame;
+
+    long contextStart = m_context.startFrame;
+    long contextDuration = m_context.duration;
+
+    if (contextStart == 0 || contextStart < startFrame) {
+        contextStart = startFrame;
+    }
+
+    if (contextDuration == 0) {
+        contextDuration = endFrame - contextStart;
+    }
+    if (contextStart + contextDuration > endFrame) {
+        contextDuration = endFrame - contextStart;
+    }
+
+    long blockFrame = contextStart;
 
     long prevCompletion = 0;
 
+    setCompletion(0);
+
     while (!m_abandoned) {
 
         if (frequencyDomain) {
-            if (blockFrame - int(m_context.blockSize)/2 > endFrame) break;
+            if (blockFrame - int(m_context.blockSize)/2 >
+                contextStart + contextDuration) break;
         } else {
-            if (blockFrame >= endFrame) break;
+            if (blockFrame >= 
+                contextStart + contextDuration) break;
         }
 
 //	std::cerr << "FeatureExtractionPluginTransform::run: blockFrame "
@@ -314,8 +334,8 @@
 //                  << m_context.blockSize << std::endl;
 
 	long completion =
-	    (((blockFrame - startFrame) / m_context.stepSize) * 99) /
-	    (   (endFrame - startFrame) / m_context.stepSize);
+	    (((blockFrame - contextStart) / m_context.stepSize) * 99) /
+	    (contextDuration / m_context.stepSize);
 
 	// channelCount is either m_input->channelCount or 1
 
@@ -341,7 +361,7 @@
 	    addFeature(blockFrame, feature);
 	}
 
-	if (blockFrame == startFrame || completion > prevCompletion) {
+	if (blockFrame == contextStart || completion > prevCompletion) {
 	    setCompletion(completion);
 	    prevCompletion = completion;
 	}
@@ -500,8 +520,8 @@
 	binCount = m_descriptor->binCount;
     }
 
-//    std::cerr << "FeatureExtractionPluginTransform::setCompletion("
-//              << completion << ")" << std::endl;
+    std::cerr << "FeatureExtractionPluginTransform::setCompletion("
+              << completion << ")" << std::endl;
 
     if (binCount == 0) {