# HG changeset patch # User Chris Cannam # Date 1456834883 0 # Node ID 55de53d7c777008997721bb43051a67c3b3772d2 # Parent a13635e9c4407ac648ea6fe26aa41d2313b6398e# Parent fae1ba2cb534696018f9964b97986a7e26875ac6 Merge diff -r fae1ba2cb534 -r 55de53d7c777 src/vamp-hostsdk/PluginSummarisingAdapter.cpp --- a/src/vamp-hostsdk/PluginSummarisingAdapter.cpp Sun Dec 13 12:25:11 2015 +0000 +++ b/src/vamp-hostsdk/PluginSummarisingAdapter.cpp Tue Mar 01 12:21:23 2016 +0000 @@ -41,6 +41,8 @@ #include #include +using namespace std; + //#define DEBUG_PLUGIN_SUMMARISING_ADAPTER 1 //#define DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT 1 @@ -80,7 +82,7 @@ SegmentBoundaries m_boundaries; - typedef std::vector ValueList; + typedef vector ValueList; struct Result { // smaller than Feature RealTime time; @@ -88,7 +90,7 @@ ValueList values; // bin number -> value }; - typedef std::vector ResultList; + typedef vector ResultList; struct OutputAccumulator { int bins; @@ -96,14 +98,14 @@ OutputAccumulator() : bins(0) { } }; - typedef std::map OutputAccumulatorMap; + typedef map OutputAccumulatorMap; OutputAccumulatorMap m_accumulators; // output number -> accumulator - typedef std::map SegmentAccumulatorMap; - typedef std::map OutputSegmentAccumulatorMap; + typedef map SegmentAccumulatorMap; + typedef map OutputSegmentAccumulatorMap; OutputSegmentAccumulatorMap m_segmentedAccumulators; // output -> segmented - typedef std::map OutputTimestampMap; + typedef map OutputTimestampMap; OutputTimestampMap m_prevTimestamps; // output number -> timestamp OutputTimestampMap m_prevDurations; // output number -> durations @@ -128,9 +130,9 @@ double variance_c; }; - typedef std::map OutputSummary; - typedef std::map SummarySegmentMap; - typedef std::map OutputSummarySegmentMap; + typedef map OutputSummary; + typedef map SummarySegmentMap; + typedef map OutputSummarySegmentMap; OutputSummarySegmentMap m_summaries; @@ -144,7 +146,7 @@ void segment(); void reduce(); - std::string getSummaryLabel(SummaryType type, AveragingMethod avg); + string getSummaryLabel(SummaryType type, AveragingMethod avg); }; static RealTime INVALID_DURATION(INT_MIN, INT_MIN); @@ -245,12 +247,16 @@ RealTime timestamp) { if (m_reduced) { - std::cerr << "WARNING: Cannot call PluginSummarisingAdapter::process() or getRemainingFeatures() after one of the getSummary methods" << std::endl; + cerr << "WARNING: Cannot call PluginSummarisingAdapter::process() or getRemainingFeatures() after one of the getSummary methods" << endl; } FeatureSet fs = m_plugin->process(inputBuffers, timestamp); accumulate(fs, timestamp, false); m_endTime = timestamp + RealTime::frame2RealTime(m_stepSize, int(m_inputSampleRate + 0.5)); +#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER + cerr << "timestamp = " << timestamp << ", end time becomes " << m_endTime + << endl; +#endif return fs; } @@ -258,7 +264,7 @@ PluginSummarisingAdapter::Impl::getRemainingFeatures() { if (m_reduced) { - std::cerr << "WARNING: Cannot call PluginSummarisingAdapter::process() or getRemainingFeatures() after one of the getSummary methods" << std::endl; + cerr << "WARNING: Cannot call PluginSummarisingAdapter::process() or getRemainingFeatures() after one of the getSummary methods" << endl; } FeatureSet fs = m_plugin->getRemainingFeatures(); accumulate(fs, m_endTime, true); @@ -270,12 +276,12 @@ { m_boundaries = b; #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "PluginSummarisingAdapter::setSummarySegmentBoundaries: boundaries are:" << std::endl; + cerr << "PluginSummarisingAdapter::setSummarySegmentBoundaries: boundaries are:" << endl; for (SegmentBoundaries::const_iterator i = m_boundaries.begin(); i != m_boundaries.end(); ++i) { - std::cerr << *i << " "; + cerr << *i << " "; } - std::cerr << std::endl; + cerr << endl; #endif } @@ -420,12 +426,12 @@ } } -std::string +string PluginSummarisingAdapter::Impl::getSummaryLabel(SummaryType type, AveragingMethod avg) { - std::string label; - std::string avglabel; + string label; + string avglabel; if (avg == SampleAverage) avglabel = ", sample average"; else avglabel = ", continuous-time average"; @@ -450,7 +456,11 @@ PluginSummarisingAdapter::Impl::accumulate(int output, const Feature &f, RealTime timestamp, - bool /* final */) + bool +#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER + final +#endif + ) { // What should happen if a feature's duration spans a segment // boundary? I think we probably want to chop it, and pretend @@ -466,7 +476,7 @@ // into segments). #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "output " << output << ": timestamp " << timestamp << ", prev timestamp " << m_prevTimestamps[output] << ", final " << final << std::endl; + cerr << "output " << output << ": timestamp " << timestamp << ", prev timestamp " << m_prevTimestamps[output] << ", final " << final << endl; #endif // At each process step, accumulate() is called once for each @@ -507,19 +517,19 @@ if (m_prevDurations[output] != INVALID_DURATION) { prevDuration = m_prevDurations[output]; #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "Previous duration from previous feature: " << prevDuration << std::endl; + cerr << "Previous duration from previous feature: " << prevDuration << endl; #endif } else { prevDuration = timestamp - m_prevTimestamps[output]; #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "Previous duration from diff: " << timestamp << " - " - << m_prevTimestamps[output] << std::endl; + cerr << "Previous duration from diff: " << timestamp << " - " + << m_prevTimestamps[output] << endl; #endif } #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "output " << output << ": "; - std::cerr << "Pushing previous duration as " << prevDuration << std::endl; + cerr << "output " << output << ": "; + cerr << "Pushing previous duration as " << prevDuration << endl; #endif m_accumulators[output].results @@ -536,6 +546,9 @@ RealTime et = timestamp; et = et + f.duration; if (et > m_endTime) m_endTime = et; +#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER + cerr << "feature has duration, updating end time to " << m_endTime << endl; +#endif } Result result; @@ -566,14 +579,14 @@ if (acount == 0) continue; #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "output " << output << ": "; + cerr << "output " << output << ": "; #endif if (m_prevDurations.find(output) != m_prevDurations.end() && m_prevDurations[output] != INVALID_DURATION) { #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "Pushing final duration from feature as " << m_prevDurations[output] << std::endl; + cerr << "Pushing final duration from feature as " << m_prevDurations[output] << endl; #endif m_accumulators[output].results[acount - 1].duration = @@ -582,7 +595,7 @@ } else { #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "Pushing final duration from diff as " << m_endTime << " - " << m_prevTimestamps[output] << std::endl; + cerr << "Pushing final duration from diff as " << m_endTime << " - " << m_prevTimestamps[output] << endl; #endif m_accumulators[output].results[acount - 1].duration = @@ -590,9 +603,9 @@ } #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "so duration for result no " << acount-1 << " is " + cerr << "so duration for result no " << acount-1 << " is " << m_accumulators[output].results[acount-1].duration - << std::endl; + << endl; #endif } } @@ -603,10 +616,10 @@ RealTime &end) { #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT - std::cerr << "findSegmentBounds: t = " << t << std::endl; + cerr << "findSegmentBounds: t = " << t << endl; #endif - SegmentBoundaries::const_iterator i = std::upper_bound + SegmentBoundaries::const_iterator i = upper_bound (m_boundaries.begin(), m_boundaries.end(), t); start = RealTime::zeroTime; @@ -621,7 +634,7 @@ } #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT - std::cerr << "findSegmentBounds: " << t << " is in segment " << start << " -> " << end << std::endl; + cerr << "findSegmentBounds: " << t << " is in segment " << start << " -> " << end << endl; #endif } @@ -629,7 +642,7 @@ PluginSummarisingAdapter::Impl::segment() { #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT - std::cerr << "segment: starting" << std::endl; + cerr << "segment: starting" << endl; #endif for (OutputAccumulatorMap::iterator i = m_accumulators.begin(); @@ -639,8 +652,8 @@ OutputAccumulator &source = i->second; #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT - std::cerr << "segment: total results for output " << output << " = " - << source.results.size() << std::endl; + cerr << "segment: total results for output " << output << " = " + << source.results.size() << endl; #endif // This is basically nonsense if the results have no values @@ -658,7 +671,7 @@ RealTime resultEnd = resultStart + source.results[n].duration; #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT - std::cerr << "output: " << output << ", result start = " << resultStart << ", end = " << resultEnd << std::endl; + cerr << "output: " << output << ", result start = " << resultStart << ", end = " << resultEnd << endl; #endif RealTime segmentStart = RealTime::zeroTime; @@ -669,8 +682,8 @@ while (segmentEnd < resultEnd) { #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT - std::cerr << "segment end " << segmentEnd << " < result end " - << resultEnd << " (with result start " << resultStart << ")" << std::endl; + cerr << "segment end " << segmentEnd << " < result end " + << resultEnd << " (with result start " << resultStart << ")" << endl; #endif findSegmentBounds(resultStart, segmentStart, segmentEnd); @@ -697,7 +710,7 @@ chunk.values = source.results[n].values; #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT - std::cerr << "chunk for segment " << segmentStart << ": from " << chunk.time << ", duration " << chunk.duration << std::endl; + cerr << "chunk for segment " << segmentStart << ": from " << chunk.time << ", duration " << chunk.duration << endl; #endif m_segmentedAccumulators[output][segmentStart].results @@ -750,18 +763,18 @@ int sz = accumulator.results.size(); #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "reduce: segment starting at " << segmentStart - << " on output " << output << " has " << sz << " result(s)" << std::endl; + cerr << "reduce: segment starting at " << segmentStart + << " on output " << output << " has " << sz << " result(s)" << endl; #endif double totalDuration = 0.0; //!!! is this right? if (sz > 0) { #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "last time = " << accumulator.results[sz-1].time + cerr << "last time = " << accumulator.results[sz-1].time << ", duration = " << accumulator.results[sz-1].duration << " (step = " << m_stepSize << ", block = " << m_blockSize << ")" - << std::endl; + << endl; #endif totalDuration = toSec((accumulator.results[sz-1].time + accumulator.results[sz-1].duration) - @@ -772,6 +785,10 @@ // work on all values over time for a single bin +#ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER + cerr << "bin " << bin << ":" << endl; +#endif + OutputBinSummary summary; summary.count = sz; @@ -791,7 +808,7 @@ if (sz == 0) continue; - std::vector valvec; + vector valvec; for (int k = 0; k < sz; ++k) { while (int(accumulator.results[k].values.size()) < @@ -807,22 +824,22 @@ toSec(accumulator.results[k].duration))); } - std::sort(valvec.begin(), valvec.end()); + sort(valvec.begin(), valvec.end()); summary.minimum = valvec[0].value; summary.maximum = valvec[sz-1].value; #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "total duration = " << totalDuration << std::endl; + cerr << "total duration = " << totalDuration << endl; #endif #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER /* - std::cerr << "value vector for medians:" << std::endl; + cerr << "value vector for medians:" << endl; for (int k = 0; k < sz; ++k) { - std::cerr << "(" << valvec[k].value << "," << valvec[k].duration << ") "; + cerr << "(" << valvec[k].value << "," << valvec[k].duration << ") "; } - std::cerr << std::endl; + cerr << endl; */ #endif @@ -844,11 +861,11 @@ } #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "median_c = " << summary.median_c << std::endl; - std::cerr << "median = " << summary.median << std::endl; + cerr << "median_c = " << summary.median_c << endl; + cerr << "median = " << summary.median << endl; #endif - std::map distribution; + map distribution; for (int k = 0; k < sz; ++k) { summary.sum += accumulator.results[k].values[bin]; @@ -857,7 +874,7 @@ int md = 0; - for (std::map::iterator di = distribution.begin(); + for (map::iterator di = distribution.begin(); di != distribution.end(); ++di) { if (di->second > md) { md = di->second; @@ -867,7 +884,7 @@ distribution.clear(); - std::map distribution_c; + map distribution_c; for (int k = 0; k < sz; ++k) { distribution_c[accumulator.results[k].values[bin]] @@ -876,7 +893,7 @@ double mrd = 0.0; - for (std::map::iterator di = distribution_c.begin(); + for (map::iterator di = distribution_c.begin(); di != distribution_c.end(); ++di) { if (di->second > mrd) { mrd = di->second; @@ -897,8 +914,8 @@ } #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "mean_c = " << sum_c << " / " << totalDuration << " = " - << sum_c / totalDuration << " (sz = " << sz << ")" << std::endl; + cerr << "mean_c = " << sum_c << " / " << totalDuration << " = " + << sum_c / totalDuration << " (sz = " << sz << ")" << endl; #endif summary.mean_c = sum_c / totalDuration; @@ -918,8 +935,8 @@ double mean = summary.sum / summary.count; #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER - std::cerr << "mean = " << summary.sum << " / " << summary.count << " = " - << summary.sum / summary.count << std::endl; + cerr << "mean = " << summary.sum << " / " << summary.count << " = " + << summary.sum / summary.count << endl; #endif for (int k = 0; k < sz; ++k) {