cannam@0: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ cannam@0: cannam@0: /* cannam@0: Vamp feature extraction plugin using the MATCH audio alignment cannam@0: algorithm. cannam@0: cannam@0: Centre for Digital Music, Queen Mary, University of London. cannam@0: This file copyright 2007 Simon Dixon, Chris Cannam and QMUL. cannam@0: cannam@0: This program is free software; you can redistribute it and/or cannam@0: modify it under the terms of the GNU General Public License as cannam@0: published by the Free Software Foundation; either version 2 of the cannam@0: License, or (at your option) any later version. See the file cannam@0: COPYING included with this distribution for more information. cannam@0: */ cannam@0: Chris@24: #include "MatchFeatureFeeder.h" cannam@0: Chris@14: using std::vector; Chris@14: Chris@24: MatchFeatureFeeder::MatchFeatureFeeder(Matcher *m1, Matcher *m2) : cannam@0: pm1(m1), pm2(m2) cannam@0: { cannam@0: finder = new Finder(m1, m2); cannam@0: } cannam@0: Chris@24: MatchFeatureFeeder::~MatchFeatureFeeder() cannam@0: { cannam@0: delete finder; cannam@0: } cannam@0: cannam@0: void Chris@24: MatchFeatureFeeder::feed(vector f1, vector f2) cannam@0: { Chris@24: q1.push(f1); Chris@24: q2.push(f2); Chris@14: Chris@14: while (!q1.empty() && !q2.empty()) { Chris@24: feedBlock(); Chris@14: } Chris@14: } Chris@14: Chris@24: void Chris@24: MatchFeatureFeeder::feedBlock() Chris@14: { Chris@43: if (pm1->m_frameCount < pm1->m_blockSize) { // fill initial block Chris@24: feed1(); Chris@24: feed2(); Chris@14: } Chris@43: else if (pm1->m_runCount >= pm1->m_params.maxRunCount) { // slope constraints Chris@24: feed2(); Chris@43: } else if (pm2->m_runCount >= pm2->m_params.maxRunCount) { Chris@24: feed1(); cannam@0: } else { cannam@0: switch (finder->getExpandDirection Chris@43: (pm1->m_frameCount-1, pm2->m_frameCount-1)) { Chris@45: case Matcher::AdvanceThis: Chris@24: feed1(); cannam@0: break; Chris@45: case Matcher::AdvanceOther: Chris@24: feed2(); cannam@0: break; Chris@45: case Matcher::AdvanceBoth: Chris@24: feed1(); Chris@24: feed2(); cannam@0: break; Chris@45: case Matcher::AdvanceNone: Chris@45: cerr << "finder says AdvanceNone!" << endl; Chris@45: break; cannam@0: } cannam@0: } cannam@0: } cannam@0: Chris@24: void Chris@24: MatchFeatureFeeder::feed1() cannam@0: { Chris@24: pm1->consumeFeatureVector(q1.front()); cannam@0: q1.pop(); cannam@0: } cannam@0: Chris@24: void Chris@24: MatchFeatureFeeder::feed2() cannam@0: { Chris@24: pm2->consumeFeatureVector(q2.front()); cannam@0: q2.pop(); cannam@0: } cannam@0: