Mercurial > hg > match-vamp
changeset 181:8e7f96432570 types
Introduce (though don't use properly) types header; get to build
author | Chris Cannam |
---|---|
date | Thu, 19 Feb 2015 16:45:42 +0000 |
parents | d1bc89794cd4 |
children | a67663dc698d |
files | src/Finder.cpp src/Finder.h src/MatchFeatureFeeder.cpp src/Matcher.cpp src/Matcher.h src/Types.h |
diffstat | 6 files changed, 103 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Finder.cpp Thu Feb 19 16:14:33 2015 +0000 +++ b/src/Finder.cpp Thu Feb 19 16:45:42 2015 +0000 @@ -122,14 +122,14 @@ } } -Matcher::Advance +advance_t Finder::getExpandDirection() { return getExpandDirection(m_m->getFrameCount() - 1, m_m->getOtherFrameCount() - 1); } -Matcher::Advance +advance_t Finder::getExpandDirection(int row, int col) { // To determine which direction to expand the search area in, we @@ -156,14 +156,14 @@ if (bestRow == row) { if (bestCol == col) { - return Matcher::AdvanceBoth; + return AdvanceBoth; } else { - return Matcher::AdvanceThis; + return AdvanceThis; } } else if (bestCol == col) { - return Matcher::AdvanceOther; + return AdvanceOther; } else { - return Matcher::AdvanceNone; + return AdvanceNone; } } @@ -184,21 +184,21 @@ for (int c = rowStart; c < rowStop; c++) { float newCost = m_m->getDistance(r, c); - Matcher::Advance dir = Matcher::AdvanceNone; + advance_t dir = AdvanceNone; if (r > r1) { // not first row double min = -1; if ((c > prevRowStart) && (c <= prevRowStop)) { // diagonal from (r-1,c-1) min = m_m->getPathCost(r-1, c-1) + newCost * diagonalWeight; - dir = Matcher::AdvanceBoth; + dir = AdvanceBoth; } if ((c >= prevRowStart) && (c < prevRowStop)) { // vertical from (r-1,c) double cost = m_m->getPathCost(r-1, c) + newCost; if ((min < 0) || (cost < min)) { min = cost; - dir = Matcher::AdvanceThis; + dir = AdvanceThis; } } if (c > rowStart) { @@ -206,7 +206,7 @@ double cost = m_m->getPathCost(r, c-1) + newCost; if ((min < 0) || (cost < min)) { min = cost; - dir = Matcher::AdvanceOther; + dir = AdvanceOther; } } @@ -214,7 +214,7 @@ } else if (c > rowStart) { // first row // horizontal from (r,c-1) - m_m->setPathCost(r, c, Matcher::AdvanceOther, + m_m->setPathCost(r, c, AdvanceOther, m_m->getPathCost(r, c-1) + newCost); } } @@ -254,7 +254,7 @@ float newCost = m_m->getDistance(r, c); double updateTo = -1.0; - Matcher::Advance dir = Matcher::AdvanceNone; + advance_t dir = AdvanceNone; if (r > r1) { // not first row double min = -1; @@ -263,7 +263,7 @@ min = m_m->getPathCost(r-1, c-1) + newCost * diagonalWeight; err.prevCost = m_m->getPathCost(r-1, c-1); err.distance = newCost * diagonalWeight; - dir = Matcher::AdvanceBoth; + dir = AdvanceBoth; } if ((c >= prevRowStart) && (c < prevRowStop)) { // vertical from (r-1,c) @@ -272,7 +272,7 @@ min = cost; err.prevCost = m_m->getPathCost(r-1, c); err.distance = newCost; - dir = Matcher::AdvanceThis; + dir = AdvanceThis; } } if (c > rowStart) { @@ -282,7 +282,7 @@ min = cost; err.prevCost = m_m->getPathCost(r, c-1); err.distance = newCost; - dir = Matcher::AdvanceOther; + dir = AdvanceOther; } } @@ -295,11 +295,11 @@ updateTo = m_m->getPathCost(r, c-1) + newCost; err.prevCost = m_m->getPathCost(r, c-1); err.distance = newCost; - dir = Matcher::AdvanceOther; + dir = AdvanceOther; } } - if (dir != Matcher::AdvanceNone) { + if (dir != AdvanceNone) { if (m_m->getAdvance(r, c) != dir) { err.type = ErrorPosition::WrongAdvance; err.r = r; @@ -476,20 +476,20 @@ pathy.push_back(y); switch (m_m->getAdvance(y, x)) { - case Matcher::AdvanceThis: + case AdvanceThis: // cerr << ", going down (dist = " << getDistance() << ")" << endl; y--; break; - case Matcher::AdvanceOther: + case AdvanceOther: // cerr << ", going left (dist = " << getDistance() << ")" << endl; x--; break; - case Matcher::AdvanceBoth: + case AdvanceBoth: // cerr << ", going diag (dist = " << getDistance() << ")" << endl; x--; y--; break; - case Matcher::AdvanceNone: // this would indicate a bug, but we wouldn't want to hang + case AdvanceNone: // this would indicate a bug, but we wouldn't want to hang cerr << "WARNING: Neither matcher advanced in path backtrack at (" << x << "," << y << ")" << endl; if (x > y) { x--;
--- a/src/Finder.h Thu Feb 19 16:14:33 2015 +0000 +++ b/src/Finder.h Thu Feb 19 16:45:42 2015 +0000 @@ -73,13 +73,13 @@ * Calculate which direction to expand the search area in, given * its current extents. */ - Matcher::Advance getExpandDirection(); + advance_t getExpandDirection(); /** * Calculate which direction to expand the search area in, given * that so far it extends as far as the point at (row, col). */ - Matcher::Advance getExpandDirection(int row, int col); + advance_t getExpandDirection(int row, int col); /** Calculates a rectangle of the path cost matrix so that the * minimum cost path between the bottom left and top right @@ -124,8 +124,8 @@ float distance; double costWas; double costShouldBe; - Matcher::Advance advanceWas; - Matcher::Advance advanceShouldBe; + advance_t advanceWas; + advance_t advanceShouldBe; }; ErrorPosition checkPathCostMatrix(); void checkAndReport();
--- a/src/MatchFeatureFeeder.cpp Thu Feb 19 16:14:33 2015 +0000 +++ b/src/MatchFeatureFeeder.cpp Thu Feb 19 16:45:42 2015 +0000 @@ -90,17 +90,17 @@ feed1(); } else { switch (m_finder.getExpandDirection()) { - case Matcher::AdvanceThis: + case AdvanceThis: feed1(); break; - case Matcher::AdvanceOther: + case AdvanceOther: feed2(); break; - case Matcher::AdvanceBoth: + case AdvanceBoth: feed1(); feed2(); break; - case Matcher::AdvanceNone: + case AdvanceNone: cerr << "m_finder says AdvanceNone!" << endl; break; }
--- a/src/Matcher.cpp Thu Feb 19 16:14:33 2015 +0000 +++ b/src/Matcher.cpp Thu Feb 19 16:45:42 2015 +0000 @@ -207,7 +207,7 @@ } void -Matcher::setPathCost(int i, int j, Advance dir, double pathCost) +Matcher::setPathCost(int i, int j, advance_t dir, double pathCost) { if (m_firstPM) { if (!isInRange(i, j)) { @@ -235,7 +235,7 @@ int distSize = (m_params.maxRunCount + 1) * m_blockSize; m_bestPathCost.resize(m_distXSize, vector<double>(distSize, -1)); m_distance.resize(m_distXSize, vector<float>(distSize, -1)); - m_advance.resize(m_distXSize, vector<Advance>(distSize, AdvanceNone)); + m_advance.resize(m_distXSize, vector<advance_t>(distSize, AdvanceNone)); m_first.resize(m_distXSize, 0); m_last.resize(m_distXSize, 0); } @@ -275,8 +275,8 @@ vector<double> bpcOld = m_bestPathCost[m_frameCount - m_blockSize]; vector<double> bpcNew(len, -1.0); - vector<Advance> adOld = m_advance[m_frameCount - m_blockSize]; - vector<Advance> adNew(len, AdvanceNone); + vector<advance_t> adOld = m_advance[m_frameCount - m_blockSize]; + vector<advance_t> adNew(len, AdvanceNone); for (int i = 0; i < len; ++i) { dNew[i] = dOld[i]; @@ -406,7 +406,7 @@ } void -Matcher::updateValue(int i, int j, Advance dir, double value, float distance) +Matcher::updateValue(int i, int j, advance_t dir, double value, float distance) { float weighted = distance; if (dir == AdvanceBoth) { @@ -440,7 +440,7 @@ } } -Matcher::Advance +advance_t Matcher::getAdvance(int i, int j) { if (m_firstPM) {
--- a/src/Matcher.h Thu Feb 19 16:14:33 2015 +0000 +++ b/src/Matcher.h Thu Feb 19 16:45:42 2015 +0000 @@ -14,8 +14,8 @@ COPYING included with this distribution for more information. */ -#ifndef _MATCHER_H_ -#define _MATCHER_H_ +#ifndef MATCHER_H +#define MATCHER_H #include <vector> #include <iostream> @@ -23,6 +23,7 @@ #include <cmath> #include "DistanceMetric.h" +#include "Types.h" using std::vector; using std::string; @@ -36,13 +37,7 @@ class Matcher { public: - enum Advance { - AdvanceNone, - AdvanceBoth, - AdvanceThis, - AdvanceOther - }; - static string advanceToString(Advance a) { + static string advanceToString(advance_t a) { switch (a) { case AdvanceNone: return "AdvanceNone"; case AdvanceBoth: return "AdvanceBoth"; @@ -233,7 +228,7 @@ * minimum cost * @param value the cost of the minimum cost path to set for this location */ - void setPathCost(int i, int j, Advance dir, double value); + void setPathCost(int i, int j, advance_t dir, double value); /** Retrieves a value from the minimum cost matrix, normalised for * path length. @@ -252,7 +247,7 @@ * @return the direction from which this position is reached with * minimum cost */ - Advance getAdvance(int i, int j); + advance_t getAdvance(int i, int j); protected: /** Create internal structures and reset. */ @@ -270,7 +265,7 @@ * @param value the cost of the minimum path except the current step * @param dMN the distance cost between the two frames */ - void updateValue(int i, int j, Advance dir, double value, float dMN); + void updateValue(int i, int j, advance_t dir, double value, float dMN); void calcAdvance(); @@ -315,7 +310,7 @@ vector<vector<float> > m_distance; /** The advance direction matrix. */ - vector<vector<Advance> > m_advance; + vector<vector<advance_t> > m_advance; /** The bounds of each row of data in the distance, path cost, and * advance direction matrices.*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Types.h Thu Feb 19 16:45:42 2015 +0000 @@ -0,0 +1,60 @@ +/* -*- 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 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. +*/ + +#ifndef MATCH_TYPES_H +#define MATCH_TYPES_H + +#include <vector> + +/// A single value in a feature vector +typedef double featurebin_t; + +/// A feature vector +typedef std::vector<featurebin_t> feature_t; + +/// The distance between two feature vectors +typedef float distance_t; + +/// A distance vector +typedef std::vector<distance_t> distvec_t; + +/// A distance matrix +typedef std::vector<distvec_t> distmat_t; + +/// The integrated distance (path cost) from the origin to a given point +typedef double pathcost_t; + +/// A vector of path costs +typedef std::vector<pathcost_t> pathvec_t; + +/// A matrix of path costs +typedef std::vector<pathcost_t> pathmat_t; + +/// A direction advance instruction or state +enum advance_t { + AdvanceNone, + AdvanceBoth, + AdvanceThis, + AdvanceOther +}; + +/// A vector of advance directions +typedef std::vector<advance_t> advancevec_t; + +/// A matrix of advance directions +typedef std::vector<advancevec_t> advancemat_t; + + +#endif