comparison 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
comparison
equal deleted inserted replaced
187:ed8aa954e72f 188:5a6446a2346a
230 PluginSummarisingAdapter::Impl::getSummaryForOutput(int output, 230 PluginSummarisingAdapter::Impl::getSummaryForOutput(int output,
231 SummaryType type, 231 SummaryType type,
232 AveragingMethod avg) 232 AveragingMethod avg)
233 { 233 {
234 if (!m_reduced) { 234 if (!m_reduced) {
235 accumulateFinalDurations();
235 segment(); 236 segment();
236 reduce(); 237 reduce();
237 m_reduced = true; 238 m_reduced = true;
238 } 239 }
239 240
319 Plugin::FeatureSet 320 Plugin::FeatureSet
320 PluginSummarisingAdapter::Impl::getSummaryForAllOutputs(SummaryType type, 321 PluginSummarisingAdapter::Impl::getSummaryForAllOutputs(SummaryType type,
321 AveragingMethod avg) 322 AveragingMethod avg)
322 { 323 {
323 if (!m_reduced) { 324 if (!m_reduced) {
325 accumulateFinalDurations();
324 segment(); 326 segment();
325 reduce(); 327 reduce();
326 m_reduced = true; 328 m_reduced = true;
327 } 329 }
328 330
483 std::cerr << "Pushing final duration from diff as " << m_lastTimestamp << " - " << m_prevTimestamps[output] << std::endl; 485 std::cerr << "Pushing final duration from diff as " << m_lastTimestamp << " - " << m_prevTimestamps[output] << std::endl;
484 486
485 m_accumulators[output].results[acount - 1].duration = 487 m_accumulators[output].results[acount - 1].duration =
486 m_lastTimestamp - m_prevTimestamps[output]; 488 m_lastTimestamp - m_prevTimestamps[output];
487 } 489 }
490
491 std::cerr << "so duration for result no " << acount-1 << " is "
492 << m_accumulators[output].results[acount-1].duration
493 << std::endl;
488 } 494 }
489 } 495 }
490 496
491 void 497 void
492 PluginSummarisingAdapter::Impl::findSegmentBounds(RealTime t, 498 PluginSummarisingAdapter::Impl::findSegmentBounds(RealTime t,
500 506
501 start = RealTime::zeroTime; 507 start = RealTime::zeroTime;
502 end = m_lastTimestamp; 508 end = m_lastTimestamp;
503 509
504 if (i != m_boundaries.end()) { 510 if (i != m_boundaries.end()) {
505
506 end = *i; 511 end = *i;
507 512 }
508 if (i != m_boundaries.begin()) { 513
509 start = *--i; 514 if (i != m_boundaries.begin()) {
510 } 515 start = *--i;
511 } 516 }
512 517
513 std::cerr << "findSegmentBounds: " << t << " is in segment " << start << " -> " << end << std::endl; 518 std::cerr << "findSegmentBounds: " << t << " is in segment " << start << " -> " << end << std::endl;
514 } 519 }
515 520
522 for (OutputAccumulatorMap::iterator i = m_accumulators.begin(); 527 for (OutputAccumulatorMap::iterator i = m_accumulators.begin();
523 i != m_accumulators.end(); ++i) { 528 i != m_accumulators.end(); ++i) {
524 529
525 int output = i->first; 530 int output = i->first;
526 OutputAccumulator &source = i->second; 531 OutputAccumulator &source = i->second;
532
533 std::cerr << "segment: total results for output " << output << " = "
534 << source.results.size() << std::endl;
527 535
528 //!!! This is basically nonsense if the results have no values 536 //!!! This is basically nonsense if the results have no values
529 //!!! (i.e. their times and counts are the only things of 537 //!!! (i.e. their times and counts are the only things of
530 //!!! interest) but perhaps it's the user's problem if they 538 //!!! interest) but perhaps it's the user's problem if they
531 //!!! ask for segmentation in that case 539 //!!! ask for segmentation in that case
609 } 617 }
610 618
611 void 619 void
612 PluginSummarisingAdapter::Impl::reduce() 620 PluginSummarisingAdapter::Impl::reduce()
613 { 621 {
614 accumulateFinalDurations();
615
616 for (OutputSegmentAccumulatorMap::iterator i = 622 for (OutputSegmentAccumulatorMap::iterator i =
617 m_segmentedAccumulators.begin(); 623 m_segmentedAccumulators.begin();
618 i != m_segmentedAccumulators.end(); ++i) { 624 i != m_segmentedAccumulators.end(); ++i) {
619 625
620 int output = i->first; 626 int output = i->first;
626 RealTime segmentStart = j->first; 632 RealTime segmentStart = j->first;
627 OutputAccumulator &accumulator = j->second; 633 OutputAccumulator &accumulator = j->second;
628 634
629 int sz = accumulator.results.size(); 635 int sz = accumulator.results.size();
630 636
637 std::cerr << "reduce: segment starting at " << segmentStart
638 << " on output " << output << " has " << sz << " result(s)" << std::endl;
639
631 double totalDuration = 0.0; 640 double totalDuration = 0.0;
632 //!!! is this right? 641 //!!! is this right?
633 if (sz > 0) { 642 if (sz > 0) {
634 totalDuration = toSec(accumulator.results[sz-1].time + 643 std::cerr << "last time = " << accumulator.results[sz-1].time
635 accumulator.results[sz-1].duration); 644 << ", duration = " << accumulator.results[sz-1].duration
645 << std::endl;
646 totalDuration = toSec((accumulator.results[sz-1].time +
647 accumulator.results[sz-1].duration) -
648 segmentStart);
636 } 649 }
637 650
638 for (int bin = 0; bin < accumulator.bins; ++bin) { 651 for (int bin = 0; bin < accumulator.bins; ++bin) {
639 652
640 // work on all values over time for a single bin 653 // work on all values over time for a single bin
676 689
677 std::sort(valvec.begin(), valvec.end()); 690 std::sort(valvec.begin(), valvec.end());
678 691
679 summary.minimum = valvec[0].value; 692 summary.minimum = valvec[0].value;
680 summary.maximum = valvec[sz-1].value; 693 summary.maximum = valvec[sz-1].value;
694
695 std::cerr << "total duration = " << totalDuration << std::endl;
696
697 std::cerr << "value vector for medians:" << std::endl;
698 for (int k = 0; k < sz; ++k) {
699 std::cerr << "(" << valvec[k].value << "," << valvec[k].duration << ") ";
700 }
701 std::cerr << std::endl;
681 702
682 if (sz % 2 == 1) { 703 if (sz % 2 == 1) {
683 summary.median = valvec[sz/2].value; 704 summary.median = valvec[sz/2].value;
684 } else { 705 } else {
685 summary.median = (valvec[sz/2].value + valvec[sz/2 + 1].value) / 2; 706 summary.median = (valvec[sz/2].value + valvec[sz/2 + 1].value) / 2;