comparison src/MatchVampPlugin.cpp @ 107:a07b962e9f03 feature_conditioner

Use MatchPipeline in MatchVampPlugin
author Chris Cannam
date Thu, 04 Dec 2014 13:48:17 +0000
parents 6636aca831c0
children 4b263ef50c9b 46a652da1415
comparison
equal deleted inserted replaced
106:921a88e8859d 107:a07b962e9f03
56 m_serialise(false), 56 m_serialise(false),
57 m_begin(true), 57 m_begin(true),
58 m_locked(false), 58 m_locked(false),
59 m_smooth(true), 59 m_smooth(true),
60 m_frameNo(0), 60 m_frameNo(0),
61 m_lastFrameIn1(0),
62 m_lastFrameIn2(0),
63 m_params(inputSampleRate, defaultStepTime, m_blockSize), 61 m_params(inputSampleRate, defaultStepTime, m_blockSize),
64 m_defaultParams(inputSampleRate, defaultStepTime, m_blockSize), 62 m_defaultParams(inputSampleRate, defaultStepTime, m_blockSize),
65 m_feParams(inputSampleRate, m_blockSize), 63 m_feParams(inputSampleRate, m_blockSize),
66 m_defaultFeParams(inputSampleRate, m_blockSize), 64 m_defaultFeParams(inputSampleRate, m_blockSize),
67 m_fcParams(), 65 m_fcParams(),
81 #else 79 #else
82 pthread_mutex_init(&m_serialisingMutex, 0); 80 pthread_mutex_init(&m_serialisingMutex, 0);
83 #endif 81 #endif
84 } 82 }
85 83
86 m_pm1 = 0; 84 m_pipeline = 0;
87 m_pm2 = 0;
88 m_fe1 = 0;
89 m_fe2 = 0;
90 m_feeder = 0;
91 // std::cerr << "MatchVampPlugin::MatchVampPlugin(" << this << "): extant = " << ++extant << std::endl; 85 // std::cerr << "MatchVampPlugin::MatchVampPlugin(" << this << "): extant = " << ++extant << std::endl;
92 } 86 }
93 87
94 MatchVampPlugin::~MatchVampPlugin() 88 MatchVampPlugin::~MatchVampPlugin()
95 { 89 {
96 // std::cerr << "MatchVampPlugin::~MatchVampPlugin(" << this << "): extant = " << --extant << std::endl; 90 // std::cerr << "MatchVampPlugin::~MatchVampPlugin(" << this << "): extant = " << --extant << std::endl;
97 91
98 delete m_feeder; 92 delete m_pipeline;
99 delete m_fe1;
100 delete m_fe2;
101 delete m_pm1;
102 delete m_pm2;
103 93
104 if (m_locked) { 94 if (m_locked) {
105 #ifdef _WIN32 95 #ifdef _WIN32
106 ReleaseMutex(m_serialisingMutex); 96 ReleaseMutex(m_serialisingMutex);
107 #else 97 #else
325 MatchVampPlugin::createMatchers() 315 MatchVampPlugin::createMatchers()
326 { 316 {
327 m_params.hopTime = m_stepTime; 317 m_params.hopTime = m_stepTime;
328 m_params.fftSize = m_blockSize; 318 m_params.fftSize = m_blockSize;
329 m_feParams.fftSize = m_blockSize; 319 m_feParams.fftSize = m_blockSize;
330 m_fe1 = new FeatureExtractor(m_feParams); 320
331 m_fe2 = new FeatureExtractor(m_feParams); 321 m_pipeline = new MatchPipeline(m_feParams, m_fcParams, m_params);
332 m_fc1 = new FeatureConditioner(m_fcParams);
333 m_fc2 = new FeatureConditioner(m_fcParams);
334 m_pm1 = new Matcher(m_params, 0);
335 m_pm2 = new Matcher(m_params, m_pm1);
336 m_pm1->setOtherMatcher(m_pm2);
337 m_feeder = new MatchFeatureFeeder(m_pm1, m_pm2);
338 } 322 }
339 323
340 bool 324 bool
341 MatchVampPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize) 325 MatchVampPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize)
342 { 326 {
363 } 347 }
364 348
365 void 349 void
366 MatchVampPlugin::reset() 350 MatchVampPlugin::reset()
367 { 351 {
368 delete m_feeder; 352 delete m_pipeline;
369 delete m_fe1; 353 m_pipeline = 0;
370 delete m_fe2;
371 delete m_fc1;
372 delete m_fc2;
373 delete m_pm1;
374 delete m_pm2;
375
376 m_feeder = 0;
377 m_fe1 = 0;
378 m_fe2 = 0;
379 m_fc1 = 0;
380 m_fc2 = 0;
381 m_pm1 = 0;
382 m_pm2 = 0;
383
384 m_frameNo = 0; 354 m_frameNo = 0;
385 m_lastFrameIn1 = 0;
386 m_lastFrameIn2 = 0;
387
388 createMatchers(); 355 createMatchers();
389 m_begin = true; 356 m_begin = true;
390 m_locked = false; 357 m_locked = false;
391 } 358 }
392 359
493 list.push_back(desc); 460 list.push_back(desc);
494 461
495 return list; 462 return list;
496 } 463 }
497 464
498 bool
499 MatchVampPlugin::aboveThreshold(const float *frame)
500 {
501 float threshold = 1e-5f;
502 float rms = 0.f;
503 for (int i = 0; i < m_blockSize/2 + 2; ++i) {
504 rms += frame[i] * frame[i];
505 }
506 rms = sqrtf(rms / (m_blockSize/2 + 2));
507 return (rms > threshold);
508 }
509
510 MatchVampPlugin::FeatureSet 465 MatchVampPlugin::FeatureSet
511 MatchVampPlugin::process(const float *const *inputBuffers, 466 MatchVampPlugin::process(const float *const *inputBuffers,
512 Vamp::RealTime timestamp) 467 Vamp::RealTime timestamp)
513 { 468 {
514 if (m_begin) { 469 if (m_begin) {
524 m_begin = false; 479 m_begin = false;
525 } 480 }
526 481
527 // std::cerr << timestamp.toString(); 482 // std::cerr << timestamp.toString();
528 483
529 if (aboveThreshold(inputBuffers[0])) m_lastFrameIn1 = m_frameNo; 484 m_pipeline->feedFrequencyDomainAudio(inputBuffers[0], inputBuffers[1]);
530 if (aboveThreshold(inputBuffers[1])) m_lastFrameIn2 = m_frameNo; 485
531 486 vector<double> f1, f2;
532 vector<double> f1 = m_fc1->process(m_fe1->process(inputBuffers[0])); 487 m_pipeline->extractConditionedFeatures(f1, f2);
533 vector<double> f2 = m_fc1->process(m_fe2->process(inputBuffers[1]));
534
535 m_feeder->feed(f1, f2);
536 488
537 FeatureSet returnFeatures; 489 FeatureSet returnFeatures;
538 490
539 Feature f; 491 Feature f;
540 f.hasTimestamp = false; 492 f.hasTimestamp = false;
560 } 512 }
561 513
562 MatchVampPlugin::FeatureSet 514 MatchVampPlugin::FeatureSet
563 MatchVampPlugin::getRemainingFeatures() 515 MatchVampPlugin::getRemainingFeatures()
564 { 516 {
565 m_feeder->finish(); 517 m_pipeline->finish();
566 518
567 FeatureSet returnFeatures; 519 FeatureSet returnFeatures;
568 520
569 Finder *finder = m_feeder->getFinder(); 521 Finder *finder = m_pipeline->getFinder();
570 finder->setDurations(m_lastFrameIn1, m_lastFrameIn2);
571 std::vector<int> pathx; 522 std::vector<int> pathx;
572 std::vector<int> pathy; 523 std::vector<int> pathy;
573 int len = finder->retrievePath(m_smooth, pathx, pathy); 524 int len = finder->retrievePath(m_smooth, pathx, pathy);
574 525
575 int prevx = 0; 526 int prevx = 0;
631 582
632 prevx = x; 583 prevx = x;
633 prevy = y; 584 prevy = y;
634 } 585 }
635 586
636 delete m_feeder; 587 delete m_pipeline;
637 delete m_pm1; 588 m_pipeline = 0;
638 delete m_pm2;
639 m_feeder = 0;
640 m_pm1 = 0;
641 m_pm2 = 0;
642 589
643 if (m_locked) { 590 if (m_locked) {
644 #ifdef _WIN32 591 #ifdef _WIN32
645 ReleaseMutex(m_serialisingMutex); 592 ReleaseMutex(m_serialisingMutex);
646 #else 593 #else