Mercurial > hg > match-vamp
view src/MatchFeatureFeeder.cpp @ 170:1af39ce8d44b structure
Fixes to copy ctor, operator= -- but these shouldn't be necessary, should restructure
author | Chris Cannam |
---|---|
date | Fri, 06 Feb 2015 11:46:23 +0000 |
parents | 70636e3c5a46 |
children | bb4507f24dc9 |
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ /* Vamp feature extraction plugin using the MATCH audio alignment algorithm. Centre for Digital Music, Queen Mary, University of London. This file copyright 2007 Simon Dixon, Chris Cannam and QMUL. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the file COPYING included with this distribution for more information. */ #include "MatchFeatureFeeder.h" using std::vector; MatchFeatureFeeder::MatchFeatureFeeder(Matcher *m1, Matcher *m2) : m_pm1(m1), m_pm2(m2), m_finder(m_pm1) { } MatchFeatureFeeder::~MatchFeatureFeeder() { } MatchFeatureFeeder::MatchFeatureFeeder(const MatchFeatureFeeder &other) : m_pm1(other.m_pm1), m_pm2(other.m_pm2), m_finder(m_pm1), m_q1(other.m_q1), m_q2(other.m_q2), m_fpx(other.m_fpx), m_fpy(other.m_fpy) { } MatchFeatureFeeder & MatchFeatureFeeder::operator=(const MatchFeatureFeeder &other) { m_pm1 = other.m_pm1; m_pm2 = other.m_pm2; m_finder = Finder(m_pm1); m_q1 = other.m_q1; m_q2 = other.m_q2; m_fpx = other.m_fpx; m_fpy = other.m_fpy; cerr << "MatchFeatureFeeder::operator=(): queue lengths: " << m_q1.size() << ", " << m_q2.size() << endl; return *this; } void MatchFeatureFeeder::setMatchers(Matcher *m1, Matcher *m2) { m_pm1 = m1; m_pm2 = m2; m_finder.setMatcher(m_pm1); } void MatchFeatureFeeder::feed(vector<double> f1, vector<double> f2) { // We maintain two FIFO queues of feature vectors, one per input // stream. When the match-feeder function is entered, it knows // that it has at least one feature in each queue. It loops, // processing up to one feature per matcher, until a queue is // empty. Then it returns, to be called again with more data. if (!f1.empty()) { m_q1.push(f1); } if (!f2.empty()) { m_q2.push(f2); } while (!m_q1.empty() && !m_q2.empty()) { feedBlock(); } } int MatchFeatureFeeder::getEstimatedReferenceFrame() { if (m_pm1->getFrameCount() == 0 || m_pm2->getFrameCount() == 0) { return 0; } int bestRow = 0; double bestCost = 0; if (!m_finder.getBestColCost(m_pm2->getFrameCount()-1, bestRow, bestCost)) { return -1; } else { return bestRow; } } void MatchFeatureFeeder::finish() { while (!m_q1.empty() || !m_q2.empty()) { feedBlock(); } } void MatchFeatureFeeder::feedBlock() { if (m_q1.empty()) { // ended feed2(); } else if (m_q2.empty()) { // ended feed1(); } else if (m_pm1->getFrameCount() < m_pm1->getBlockSize()) { // fill initial block feed1(); feed2(); } else if (m_pm1->isOverrunning()) { // slope constraints feed2(); } else if (m_pm2->isOverrunning()) { feed1(); } else { switch (m_finder.getExpandDirection (m_pm1->getFrameCount()-1, m_pm2->getFrameCount()-1)) { case Matcher::AdvanceThis: feed1(); break; case Matcher::AdvanceOther: feed2(); break; case Matcher::AdvanceBoth: feed1(); feed2(); break; case Matcher::AdvanceNone: cerr << "m_finder says AdvanceNone!" << endl; break; } } m_fpx.push_back(m_pm2->getFrameCount()); m_fpy.push_back(m_pm1->getFrameCount()); } void MatchFeatureFeeder::feed1() { m_pm1->consumeFeatureVector(m_q1.front()); m_q1.pop(); } void MatchFeatureFeeder::feed2() { m_pm2->consumeFeatureVector(m_q2.front()); m_q2.pop(); }