annotate MatchFeatureFeeder.cpp @ 24:89929e9e54fb

Add MatchFeatureFeeder, permitting the aligner to be driven from external data
author Chris Cannam
date Fri, 10 Oct 2014 17:45:28 +0100
parents MatchFeeder.cpp@b15106b0abcd
children
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@24 35 q1.push(f1);
Chris@24 36 q2.push(f2);
Chris@14 37
Chris@14 38 while (!q1.empty() && !q2.empty()) {
Chris@24 39 feedBlock();
Chris@14 40 }
Chris@14 41 }
Chris@14 42
Chris@24 43 void
Chris@24 44 MatchFeatureFeeder::feedBlock()
Chris@14 45 {
Chris@24 46 if (pm1->frameCount < pm1->blockSize) { // fill initial block
Chris@24 47 feed1();
Chris@24 48 feed2();
Chris@14 49 }
Chris@15 50 else if (pm1->runCount >= pm1->params.maxRunCount) { // slope constraints
Chris@24 51 feed2();
Chris@15 52 } else if (pm2->runCount >= pm2->params.maxRunCount) {
Chris@24 53 feed1();
cannam@0 54 } else {
cannam@0 55 switch (finder->getExpandDirection
cannam@0 56 (pm1->frameCount-1, pm2->frameCount-1)) {
cannam@0 57 case ADVANCE_THIS:
Chris@24 58 feed1();
cannam@0 59 break;
cannam@0 60 case ADVANCE_OTHER:
Chris@24 61 feed2();
cannam@0 62 break;
cannam@0 63 case ADVANCE_BOTH:
Chris@24 64 feed1();
Chris@24 65 feed2();
cannam@0 66 break;
cannam@0 67 }
cannam@0 68 }
cannam@0 69 }
cannam@0 70
Chris@24 71 void
Chris@24 72 MatchFeatureFeeder::feed1()
cannam@0 73 {
Chris@24 74 pm1->consumeFeatureVector(q1.front());
cannam@0 75 q1.pop();
cannam@0 76 }
cannam@0 77
Chris@24 78 void
Chris@24 79 MatchFeatureFeeder::feed2()
cannam@0 80 {
Chris@24 81 pm2->consumeFeatureVector(q2.front());
cannam@0 82 q2.pop();
cannam@0 83 }
cannam@0 84