comparison vamp-sdk/hostext/PluginSummarisingAdapter.cpp @ 182:3fcac0f3afdc

* More fixes to continuous time averaging
author cannam
date Thu, 04 Sep 2008 16:15:01 +0000
parents cd16cbf80c87
children c053ababbf7e
comparison
equal deleted inserted replaced
181:cd16cbf80c87 182:3fcac0f3afdc
294 bool final) 294 bool final)
295 { 295 {
296 for (FeatureSet::const_iterator i = fs.begin(); i != fs.end(); ++i) { 296 for (FeatureSet::const_iterator i = fs.begin(); i != fs.end(); ++i) {
297 for (FeatureList::const_iterator j = i->second.begin(); 297 for (FeatureList::const_iterator j = i->second.begin();
298 j != i->second.end(); ++j) { 298 j != i->second.end(); ++j) {
299 accumulate(i->first, *j, timestamp, final); 299 if (j->hasTimestamp) {
300 accumulate(i->first, *j, j->timestamp, final);
301 } else {
302 //!!! is this correct?
303 accumulate(i->first, *j, timestamp, final);
304 }
300 } 305 }
301 } 306 }
302 } 307 }
303 308
304 void 309 void
308 bool final) 313 bool final)
309 { 314 {
310 //!!! to do: use timestamp to determine which segment we're on 315 //!!! to do: use timestamp to determine which segment we're on
311 316
312 m_accumulators[output].count++; 317 m_accumulators[output].count++;
318
319 std::cerr << "output " << output << ": timestamp " << timestamp << ", prev timestamp " << m_prevTimestamps[output] << std::endl;
320
321 //!!! m_prevDuration needs to be per output
322
323 //!!! also, this will not work if we are called repeatedly with
324 //!!! the same timestamp -- no values will be registered until a
325 //!!! new timestamp is seen -- we need a better test for "not
326 //!!! first result" below
313 327
314 if (m_prevDuration == RealTime::zeroTime) { 328 if (m_prevDuration == RealTime::zeroTime) {
315 if (m_prevTimestamps.find(output) != m_prevTimestamps.end()) { 329 if (m_prevTimestamps.find(output) != m_prevTimestamps.end()) {
316 m_prevDuration = timestamp - m_prevTimestamps[output]; 330 m_prevDuration = timestamp - m_prevTimestamps[output];
317 } 331 }
376 i != m_accumulators.end(); ++i) { 390 i != m_accumulators.end(); ++i) {
377 391
378 int output = i->first; 392 int output = i->first;
379 OutputAccumulator &accumulator = i->second; 393 OutputAccumulator &accumulator = i->second;
380 394
381 double totalDuration; 395 double totalDuration = 0.0;
382 for (int k = 0; k < accumulator.durations.size(); ++k) { 396 for (int k = 0; k < accumulator.durations.size(); ++k) {
383 totalDuration += toSec(accumulator.durations[k]); 397 totalDuration += toSec(accumulator.durations[k]);
384 } 398 }
385 399
386 for (BinValueMap::iterator j = accumulator.values.begin(); 400 for (BinValueMap::iterator j = accumulator.values.begin();
497 511
498 for (int k = 0; k < sz; ++k) { 512 for (int k = 0; k < sz; ++k) {
499 double value = values[k] * toSec(durations[k]); 513 double value = values[k] * toSec(durations[k]);
500 sum_c += value; 514 sum_c += value;
501 } 515 }
516
517 std::cerr << "mean_c = " << sum_c << " / " << totalDuration << " = "
518 << sum_c / totalDuration << std::endl;
502 519
503 summary.mean_c = sum_c / totalDuration; 520 summary.mean_c = sum_c / totalDuration;
504 521
505 for (int k = 0; k < sz; ++k) { 522 for (int k = 0; k < sz; ++k) {
506 double value = values[k] * toSec(durations[k]); 523 double value = values[k] * toSec(durations[k]);
513 530
514 //!!! still to handle: median_c 531 //!!! still to handle: median_c
515 532
516 float mean = summary.sum / summary.count; 533 float mean = summary.sum / summary.count;
517 534
535 std::cerr << "mean = " << summary.sum << " / " << summary.count << " = "
536 << summary.sum / summary.count << std::endl;
537
518 for (int k = 0; k < sz; ++k) { 538 for (int k = 0; k < sz; ++k) {
519 summary.variance += (values[k] - mean) * (values[k] - mean); 539 summary.variance += (values[k] - mean) * (values[k] - mean);
520 } 540 }
521 summary.variance /= summary.count; 541 summary.variance /= summary.count;
522 542