annotate src/Finder.h @ 172:30d59e1e4232 structure

Minor tidy
author Chris Cannam
date Fri, 06 Feb 2015 18:09:18 +0000
parents bb4507f24dc9
children eeed3498fe96
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
cannam@0 17 #ifndef _FINDER_H_
cannam@0 18 #define _FINDER_H_
cannam@0 19
cannam@0 20 #include <vector>
cannam@0 21 #include <iostream>
cannam@0 22
cannam@0 23 #include "Matcher.h"
cannam@0 24
Chris@72 25 class Finder
Chris@72 26 {
cannam@0 27 public:
Chris@72 28 Finder(Matcher *pm);
cannam@0 29
Chris@167 30 // default copy ctor and operator= are fine
Chris@167 31
cannam@0 32 ~Finder();
cannam@0 33
Chris@154 34 void setMatcher(Matcher *pm);
Chris@154 35
Chris@60 36 /**
Chris@60 37 * Tell the finder that one or both files ends sooner than it
Chris@60 38 * thought, i.e. that some of the trailing features are silence or
Chris@60 39 * otherwise to be ignored. d1 and d2 are feature frame counts for
Chris@60 40 * matchers 1 and 2 respectively. If this is not called, the full
Chris@60 41 * duration of each input will be considered.
Chris@60 42 */
Chris@60 43 void setDurations(int d1, int d2);
Chris@147 44
Chris@147 45 /**
Chris@154 46 * Find the location and cost of the column with the cheapest path
Chris@154 47 * cost within the given row. If the row is out of range, return
Chris@154 48 * false and leave the bestCol and bestCost variables unchanged.
Chris@154 49 */
Chris@154 50 bool getBestRowCost(int row, int &bestCol, double &bestCost);
Chris@154 51
Chris@154 52 /**
Chris@154 53 * Find the location and cost of the row with the cheapest path
Chris@154 54 * cost within the given column. If the column is out of range,
Chris@154 55 * return false and leave the bestRow and bestCost variables
Chris@154 56 * unchanged.
Chris@154 57 */
Chris@154 58 bool getBestColCost(int col, int &bestRow, double &bestCost);
Chris@154 59
Chris@154 60 /**
Chris@147 61 * Find the location and cost of the cheapest path cost within the
Chris@147 62 * final row and column of the search area, given that the area
Chris@147 63 * extends as far as the point at (row, col). This is used by
Chris@147 64 * getExpandDirection and can also be used, for example, to
Chris@147 65 * determine the current best estimate alignment for a frame we
Chris@147 66 * have just reached.
Chris@147 67 */
Chris@147 68 void getBestEdgeCost(int row, int col,
Chris@147 69 int &bestRow, int &bestCol,
Chris@147 70 double &bestCost);
Chris@147 71
Chris@147 72 /**
Chris@147 73 * Calculate which direction to expand the search area in, given
Chris@171 74 * its current extents.
Chris@171 75 */
Chris@171 76 Matcher::Advance getExpandDirection();
Chris@171 77
Chris@171 78 /**
Chris@171 79 * Calculate which direction to expand the search area in, given
Chris@147 80 * that so far it extends as far as the point at (row, col).
Chris@147 81 */
Chris@45 82 Matcher::Advance getExpandDirection(int row, int col);
Chris@45 83
cannam@0 84 /** Calculates a rectangle of the path cost matrix so that the
cannam@0 85 * minimum cost path between the bottom left and top right
cannam@0 86 * corners can be computed. Caches previous values to avoid
cannam@0 87 * calling find() multiple times, and is several times faster as
cannam@0 88 * a result.
cannam@0 89 *
cannam@0 90 * @param r1 the bottom of the rectangle to be calculated
cannam@0 91 * @param c1 the left side of the rectangle to be calculated
cannam@0 92 * @param r2 the top of the rectangle to be calculated
cannam@0 93 * @param c2 the right side of the rectangle to be calculated
cannam@0 94 */
cannam@0 95 void recalculatePathCostMatrix(int r1, int c1, int r2, int c2);
cannam@0 96
Chris@30 97 /**
Chris@30 98 * Track back after all of the matchers have been fed in order to
Chris@30 99 * obtain the lowest cost path available. Path x and y coordinate
Chris@30 100 * pairs are returned in corresponding elements of pathx and
Chris@30 101 * pathy. Return value is the length of the returned path: only
Chris@30 102 * this many elements from pathx and pathy are valid (any
Chris@30 103 * subsequent ones may be spurious).
Chris@31 104 *
Chris@31 105 * @param smooth whether to smooth the path before returning it
Chris@30 106 */
Chris@31 107 int retrievePath(bool smooth, std::vector<int> &pathx, std::vector<int> &pathy);
Chris@72 108
Chris@72 109 protected:
Chris@82 110 #ifdef PERFORM_ERROR_CHECKS
Chris@81 111 struct ErrorPosition {
Chris@86 112 enum Type { NoError = 0, WrongCost, WrongAdvance, NoAdvance };
Chris@81 113 ErrorPosition() : type(NoError) { }
Chris@81 114 Type type;
Chris@81 115 int r;
Chris@81 116 int c;
Chris@81 117 double prevCost;
Chris@81 118 float distance;
Chris@81 119 double costWas;
Chris@81 120 double costShouldBe;
Chris@84 121 Matcher::Advance advanceWas;
Chris@84 122 Matcher::Advance advanceShouldBe;
Chris@81 123 };
Chris@81 124 ErrorPosition checkPathCostMatrix();
Chris@92 125 void checkAndReport();
Chris@82 126 #endif
Chris@167 127
Chris@147 128 Matcher *m_m; // I do not own this
Chris@147 129
Chris@72 130 int m_duration1;
Chris@72 131 int m_duration2;
Chris@147 132 };
cannam@0 133
cannam@0 134 #endif