annotate src/MatchFeatureFeeder.cpp @ 200:f6be68852c1d

Fix off-by-one in durations
author Chris Cannam
date Fri, 27 Feb 2015 10:05:04 +0000
parents f415747b151b
children 175c8f044e7c
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@167 22 m_pm1(m1),
Chris@167 23 m_pm2(m2),
Chris@167 24 m_finder(m_pm1)
cannam@0 25 {
cannam@0 26 }
cannam@0 27
Chris@24 28 MatchFeatureFeeder::~MatchFeatureFeeder()
cannam@0 29 {
cannam@0 30 }
cannam@0 31
Chris@154 32 void
Chris@183 33 MatchFeatureFeeder::feed(feature_t f1, feature_t f2)
cannam@0 34 {
Chris@49 35 // We maintain two FIFO queues of feature vectors, one per input
Chris@49 36 // stream. When the match-feeder function is entered, it knows
Chris@49 37 // that it has at least one feature in each queue. It loops,
Chris@49 38 // processing up to one feature per matcher, until a queue is
Chris@49 39 // empty. Then it returns, to be called again with more data.
Chris@49 40
Chris@60 41 if (!f1.empty()) {
Chris@74 42 m_q1.push(f1);
Chris@60 43 }
Chris@60 44
Chris@60 45 if (!f2.empty()) {
Chris@74 46 m_q2.push(f2);
Chris@60 47 }
Chris@14 48
Chris@74 49 while (!m_q1.empty() && !m_q2.empty()) {
Chris@63 50 feedBlock();
Chris@63 51 }
Chris@63 52 }
Chris@63 53
Chris@167 54 int
Chris@167 55 MatchFeatureFeeder::getEstimatedReferenceFrame()
Chris@167 56 {
Chris@167 57 if (m_pm1->getFrameCount() == 0 || m_pm2->getFrameCount() == 0) {
Chris@167 58 return 0;
Chris@167 59 }
Chris@167 60 int bestRow = 0;
Chris@191 61 normpathcost_t bestCost = 0;
Chris@167 62 if (!m_finder.getBestColCost(m_pm2->getFrameCount()-1, bestRow, bestCost)) {
Chris@167 63 return -1;
Chris@167 64 } else {
Chris@167 65 return bestRow;
Chris@167 66 }
Chris@167 67 }
Chris@167 68
Chris@63 69 void
Chris@63 70 MatchFeatureFeeder::finish()
Chris@63 71 {
Chris@74 72 while (!m_q1.empty() || !m_q2.empty()) {
Chris@24 73 feedBlock();
Chris@14 74 }
Chris@200 75
Chris@200 76 // cerr << "MatchFeatureFeeder::finish: have " << m_pm1->getFrameCount()
Chris@200 77 // << " reference and " << m_pm2->getFrameCount() << " other frames"
Chris@200 78 // << endl;
Chris@14 79 }
Chris@14 80
Chris@24 81 void
Chris@24 82 MatchFeatureFeeder::feedBlock()
Chris@14 83 {
Chris@74 84 if (m_q1.empty()) { // ended
Chris@60 85 feed2();
Chris@74 86 } else if (m_q2.empty()) { // ended
Chris@60 87 feed1();
Chris@171 88 } else if (m_pm1->isFillingInitialBlock()) {
Chris@24 89 feed1();
Chris@24 90 feed2();
Chris@78 91 } else if (m_pm1->isOverrunning()) { // slope constraints
Chris@24 92 feed2();
Chris@78 93 } else if (m_pm2->isOverrunning()) {
Chris@24 94 feed1();
cannam@0 95 } else {
Chris@171 96 switch (m_finder.getExpandDirection()) {
Chris@181 97 case AdvanceThis:
Chris@24 98 feed1();
cannam@0 99 break;
Chris@181 100 case AdvanceOther:
Chris@24 101 feed2();
cannam@0 102 break;
Chris@181 103 case AdvanceBoth:
Chris@24 104 feed1();
Chris@24 105 feed2();
cannam@0 106 break;
Chris@181 107 case AdvanceNone:
Chris@74 108 cerr << "m_finder says AdvanceNone!" << endl;
Chris@45 109 break;
cannam@0 110 }
cannam@0 111 }
Chris@135 112
Chris@135 113 m_fpx.push_back(m_pm2->getFrameCount());
Chris@135 114 m_fpy.push_back(m_pm1->getFrameCount());
cannam@0 115 }
cannam@0 116
Chris@24 117 void
Chris@24 118 MatchFeatureFeeder::feed1()
cannam@0 119 {
Chris@74 120 m_pm1->consumeFeatureVector(m_q1.front());
Chris@74 121 m_q1.pop();
cannam@0 122 }
cannam@0 123
Chris@24 124 void
Chris@24 125 MatchFeatureFeeder::feed2()
cannam@0 126 {
Chris@74 127 m_pm2->consumeFeatureVector(m_q2.front());
Chris@74 128 m_q2.pop();
cannam@0 129 }
cannam@0 130