annotate src/MatchFeatureFeeder.cpp @ 63:a540137d393b refactors_no_float

Fix handling of empty queues -- we should continue processing when a queue is empty only if we've reached end of file on both
author Chris Cannam
date Tue, 18 Nov 2014 10:03:36 +0000
parents faa523be20f9
children da9ead46abe9
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) :
cannam@0 22 pm1(m1), pm2(m2)
cannam@0 23 {
cannam@0 24 finder = new Finder(m1, m2);
cannam@0 25 }
cannam@0 26
Chris@24 27 MatchFeatureFeeder::~MatchFeatureFeeder()
cannam@0 28 {
cannam@0 29 delete finder;
cannam@0 30 }
cannam@0 31
cannam@0 32 void
Chris@24 33 MatchFeatureFeeder::feed(vector<double> f1, vector<double> 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@60 42 q1.push(f1);
Chris@60 43 }
Chris@60 44
Chris@60 45 if (!f2.empty()) {
Chris@60 46 q2.push(f2);
Chris@60 47 }
Chris@14 48
Chris@63 49 while (!q1.empty() && !q2.empty()) {
Chris@63 50 feedBlock();
Chris@63 51 }
Chris@63 52 }
Chris@63 53
Chris@63 54 void
Chris@63 55 MatchFeatureFeeder::finish()
Chris@63 56 {
Chris@60 57 while (!q1.empty() || !q2.empty()) {
Chris@24 58 feedBlock();
Chris@14 59 }
Chris@14 60 }
Chris@14 61
Chris@24 62 void
Chris@24 63 MatchFeatureFeeder::feedBlock()
Chris@14 64 {
Chris@60 65 if (q1.empty()) { // ended
Chris@60 66 feed2();
Chris@60 67 } else if (q2.empty()) { // ended
Chris@60 68 feed1();
Chris@60 69 } else if (pm1->m_frameCount < pm1->m_blockSize) { // fill initial block
Chris@24 70 feed1();
Chris@24 71 feed2();
Chris@60 72 } else if (pm1->m_runCount >= pm1->m_params.maxRunCount) { // slope constraints
Chris@24 73 feed2();
Chris@43 74 } else if (pm2->m_runCount >= pm2->m_params.maxRunCount) {
Chris@24 75 feed1();
cannam@0 76 } else {
cannam@0 77 switch (finder->getExpandDirection
Chris@43 78 (pm1->m_frameCount-1, pm2->m_frameCount-1)) {
cannam@0 79 case ADVANCE_THIS:
Chris@24 80 feed1();
cannam@0 81 break;
cannam@0 82 case ADVANCE_OTHER:
Chris@24 83 feed2();
cannam@0 84 break;
cannam@0 85 case ADVANCE_BOTH:
Chris@24 86 feed1();
Chris@24 87 feed2();
cannam@0 88 break;
cannam@0 89 }
cannam@0 90 }
cannam@0 91 }
cannam@0 92
Chris@24 93 void
Chris@24 94 MatchFeatureFeeder::feed1()
cannam@0 95 {
Chris@24 96 pm1->consumeFeatureVector(q1.front());
cannam@0 97 q1.pop();
cannam@0 98 }
cannam@0 99
Chris@24 100 void
Chris@24 101 MatchFeatureFeeder::feed2()
cannam@0 102 {
Chris@24 103 pm2->consumeFeatureVector(q2.front());
cannam@0 104 q2.pop();
cannam@0 105 }
cannam@0 106