diff vamp-sdk/hostext/PluginSummarisingAdapter.cpp @ 188:5a6446a2346a

* More work on summarising adapter -- fixes for segmentation &c
author cannam
date Mon, 15 Sep 2008 16:04:25 +0000
parents ed8aa954e72f
children d1bdcd4a226f
line wrap: on
line diff
--- a/vamp-sdk/hostext/PluginSummarisingAdapter.cpp	Fri Sep 12 16:27:07 2008 +0000
+++ b/vamp-sdk/hostext/PluginSummarisingAdapter.cpp	Mon Sep 15 16:04:25 2008 +0000
@@ -232,6 +232,7 @@
                                                     AveragingMethod avg)
 {
     if (!m_reduced) {
+        accumulateFinalDurations();
         segment();
         reduce();
         m_reduced = true;
@@ -321,6 +322,7 @@
                                                         AveragingMethod avg)
 {
     if (!m_reduced) {
+        accumulateFinalDurations();
         segment();
         reduce();
         m_reduced = true;
@@ -485,6 +487,10 @@
             m_accumulators[output].results[acount - 1].duration =
                 m_lastTimestamp - m_prevTimestamps[output];
         }
+        
+        std::cerr << "so duration for result no " << acount-1 << " is "
+                  << m_accumulators[output].results[acount-1].duration
+                  << std::endl;
     }
 }
 
@@ -502,12 +508,11 @@
     end = m_lastTimestamp;
 
     if (i != m_boundaries.end()) {
+        end = *i;
+    }
 
-        end = *i;
-
-        if (i != m_boundaries.begin()) {
-            start = *--i;
-        }
+    if (i != m_boundaries.begin()) {
+        start = *--i;
     }
     
     std::cerr << "findSegmentBounds: " << t << " is in segment " << start << " -> " << end << std::endl;
@@ -525,6 +530,9 @@
         int output = i->first;
         OutputAccumulator &source = i->second;
 
+        std::cerr << "segment: total results for output " << output << " = "
+                  << source.results.size() << std::endl;
+
         //!!! This is basically nonsense if the results have no values
         //!!! (i.e. their times and counts are the only things of
         //!!! interest) but perhaps it's the user's problem if they
@@ -611,8 +619,6 @@
 void
 PluginSummarisingAdapter::Impl::reduce()
 {
-    accumulateFinalDurations();
-
     for (OutputSegmentAccumulatorMap::iterator i =
              m_segmentedAccumulators.begin();
          i != m_segmentedAccumulators.end(); ++i) {
@@ -628,11 +634,18 @@
 
             int sz = accumulator.results.size();
 
+            std::cerr << "reduce: segment starting at " << segmentStart
+                      << " on output " << output << " has " << sz << " result(s)" << std::endl;
+
             double totalDuration = 0.0;
             //!!! is this right?
             if (sz > 0) {
-                totalDuration = toSec(accumulator.results[sz-1].time +
-                                      accumulator.results[sz-1].duration);
+                std::cerr << "last time = " << accumulator.results[sz-1].time 
+                          << ", duration = " << accumulator.results[sz-1].duration
+                          << std::endl;
+                totalDuration = toSec((accumulator.results[sz-1].time +
+                                       accumulator.results[sz-1].duration) -
+                                      segmentStart);
             }
 
             for (int bin = 0; bin < accumulator.bins; ++bin) {
@@ -679,6 +692,14 @@
                 summary.minimum = valvec[0].value;
                 summary.maximum = valvec[sz-1].value;
 
+                std::cerr << "total duration = " << totalDuration << std::endl;
+
+                std::cerr << "value vector for medians:" << std::endl;
+                for (int k = 0; k < sz; ++k) {
+                    std::cerr << "(" << valvec[k].value << "," << valvec[k].duration << ") ";
+                }
+                std::cerr << std::endl;
+
                 if (sz % 2 == 1) {
                     summary.median = valvec[sz/2].value;
                 } else {