annotate src/MatchFeatureFeeder.cpp @ 154:4159f6b71942 structure

More cost query methods
author Chris Cannam
date Fri, 23 Jan 2015 14:55:19 +0000
parents 42381e437fcd
children 2b61e0cb6847
rev   line source
cannam@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@0 2
cannam@0 3 /*
cannam@0 4 Vamp feature extraction plugin using the MATCH audio alignment
cannam@0 5 algorithm.
cannam@0 6
cannam@0 7 Centre for Digital Music, Queen Mary, University of London.
cannam@0 8 This file copyright 2007 Simon Dixon, Chris Cannam and QMUL.
cannam@0 9
cannam@0 10 This program is free software; you can redistribute it and/or
cannam@0 11 modify it under the terms of the GNU General Public License as
cannam@0 12 published by the Free Software Foundation; either version 2 of the
cannam@0 13 License, or (at your option) any later version. See the file
cannam@0 14 COPYING included with this distribution for more information.
cannam@0 15 */
cannam@0 16
Chris@24 17 #include "MatchFeatureFeeder.h"
cannam@0 18
Chris@14 19 using std::vector;
Chris@14 20
Chris@24 21 MatchFeatureFeeder::MatchFeatureFeeder(Matcher *m1, Matcher *m2) :
Chris@74 22 m_pm1(m1), m_pm2(m2)
cannam@0 23 {
Chris@74 24 m_finder = new Finder(m1);
cannam@0 25 }
cannam@0 26
Chris@24 27 MatchFeatureFeeder::~MatchFeatureFeeder()
cannam@0 28 {
Chris@74 29 delete m_finder;
cannam@0 30 }
cannam@0 31
cannam@0 32 void
Chris@154 33 MatchFeatureFeeder::setMatchers(Matcher *m1, Matcher *m2)
Chris@154 34 {
Chris@154 35 m_pm1 = m1;
Chris@154 36 m_pm2 = m2;
Chris@154 37 m_finder->setMatcher(m_pm1);
Chris@154 38 }
Chris@154 39
Chris@154 40 void
Chris@24 41 MatchFeatureFeeder::feed(vector<double> f1, vector<double> f2)
cannam@0 42 {
Chris@49 43 // We maintain two FIFO queues of feature vectors, one per input
Chris@49 44 // stream. When the match-feeder function is entered, it knows
Chris@49 45 // that it has at least one feature in each queue. It loops,
Chris@49 46 // processing up to one feature per matcher, until a queue is
Chris@49 47 // empty. Then it returns, to be called again with more data.
Chris@49 48
Chris@60 49 if (!f1.empty()) {
Chris@74 50 m_q1.push(f1);
Chris@60 51 }
Chris@60 52
Chris@60 53 if (!f2.empty()) {
Chris@74 54 m_q2.push(f2);
Chris@60 55 }
Chris@14 56
Chris@74 57 while (!m_q1.empty() && !m_q2.empty()) {
Chris@63 58 feedBlock();
Chris@63 59 }
Chris@63 60 }
Chris@63 61
Chris@63 62 void
Chris@63 63 MatchFeatureFeeder::finish()
Chris@63 64 {
Chris@74 65 while (!m_q1.empty() || !m_q2.empty()) {
Chris@24 66 feedBlock();
Chris@14 67 }
Chris@14 68 }
Chris@14 69
Chris@24 70 void
Chris@24 71 MatchFeatureFeeder::feedBlock()
Chris@14 72 {
Chris@74 73 if (m_q1.empty()) { // ended
Chris@60 74 feed2();
Chris@74 75 } else if (m_q2.empty()) { // ended
Chris@60 76 feed1();
Chris@78 77 } else if (m_pm1->getFrameCount() < m_pm1->getBlockSize()) { // fill initial block
Chris@24 78 feed1();
Chris@24 79 feed2();
Chris@78 80 } else if (m_pm1->isOverrunning()) { // slope constraints
Chris@24 81 feed2();
Chris@78 82 } else if (m_pm2->isOverrunning()) {
Chris@24 83 feed1();
cannam@0 84 } else {
Chris@74 85 switch (m_finder->getExpandDirection
Chris@78 86 (m_pm1->getFrameCount()-1, m_pm2->getFrameCount()-1)) {
Chris@45 87 case Matcher::AdvanceThis:
Chris@24 88 feed1();
cannam@0 89 break;
Chris@45 90 case Matcher::AdvanceOther:
Chris@24 91 feed2();
cannam@0 92 break;
Chris@45 93 case Matcher::AdvanceBoth:
Chris@24 94 feed1();
Chris@24 95 feed2();
cannam@0 96 break;
Chris@45 97 case Matcher::AdvanceNone:
Chris@74 98 cerr << "m_finder says AdvanceNone!" << endl;
Chris@45 99 break;
cannam@0 100 }
cannam@0 101 }
Chris@135 102
Chris@135 103 m_fpx.push_back(m_pm2->getFrameCount());
Chris@135 104 m_fpy.push_back(m_pm1->getFrameCount());
cannam@0 105 }
cannam@0 106
Chris@24 107 void
Chris@24 108 MatchFeatureFeeder::feed1()
cannam@0 109 {
Chris@74 110 m_pm1->consumeFeatureVector(m_q1.front());
Chris@74 111 m_q1.pop();
cannam@0 112 }
cannam@0 113
Chris@24 114 void
Chris@24 115 MatchFeatureFeeder::feed2()
cannam@0 116 {
Chris@74 117 m_pm2->consumeFeatureVector(m_q2.front());
Chris@74 118 m_q2.pop();
cannam@0 119 }
cannam@0 120