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@191
|
46 * Find the location and normalised path cost of the column with
|
Chris@191
|
47 * the cheapest path cost within the given row. If the row is out
|
Chris@191
|
48 * of range, return false and leave the bestCol and bestCost
|
Chris@191
|
49 * variables unchanged.
|
Chris@154
|
50 */
|
Chris@191
|
51 bool getBestRowCost(int row, int &bestCol, normpathcost_t &bestCost);
|
Chris@154
|
52
|
Chris@154
|
53 /**
|
Chris@191
|
54 * Find the location and normalised path cost of the row with the
|
Chris@191
|
55 * cheapest path cost within the given column. If the column is
|
Chris@191
|
56 * out of range, return false and leave the bestRow and bestCost
|
Chris@191
|
57 * variables unchanged.
|
Chris@154
|
58 */
|
Chris@191
|
59 bool getBestColCost(int col, int &bestRow, normpathcost_t &bestCost);
|
Chris@154
|
60
|
Chris@154
|
61 /**
|
Chris@191
|
62 * Find the location and normalised path cost of the cheapest path
|
Chris@191
|
63 * cost within the final row and column of the search area, given
|
Chris@191
|
64 * that the area extends as far as the point at (row, col). This
|
Chris@191
|
65 * is used by getExpandDirection and can also be used, for
|
Chris@191
|
66 * example, to determine the current best estimate alignment for a
|
Chris@191
|
67 * frame we have just reached.
|
Chris@147
|
68 */
|
Chris@147
|
69 void getBestEdgeCost(int row, int col,
|
Chris@147
|
70 int &bestRow, int &bestCol,
|
Chris@191
|
71 normpathcost_t &bestCost);
|
Chris@147
|
72
|
Chris@147
|
73 /**
|
Chris@147
|
74 * Calculate which direction to expand the search area in, given
|
Chris@171
|
75 * its current extents.
|
Chris@171
|
76 */
|
Chris@181
|
77 advance_t getExpandDirection();
|
Chris@171
|
78
|
Chris@171
|
79 /**
|
Chris@171
|
80 * Calculate which direction to expand the search area in, given
|
Chris@147
|
81 * that so far it extends as far as the point at (row, col).
|
Chris@147
|
82 */
|
Chris@181
|
83 advance_t getExpandDirection(int row, int col);
|
Chris@45
|
84
|
cannam@0
|
85 /** Calculates a rectangle of the path cost matrix so that the
|
cannam@0
|
86 * minimum cost path between the bottom left and top right
|
cannam@0
|
87 * corners can be computed. Caches previous values to avoid
|
cannam@0
|
88 * calling find() multiple times, and is several times faster as
|
cannam@0
|
89 * a result.
|
cannam@0
|
90 *
|
cannam@0
|
91 * @param r1 the bottom of the rectangle to be calculated
|
cannam@0
|
92 * @param c1 the left side of the rectangle to be calculated
|
cannam@0
|
93 * @param r2 the top of the rectangle to be calculated
|
cannam@0
|
94 * @param c2 the right side of the rectangle to be calculated
|
cannam@0
|
95 */
|
cannam@0
|
96 void recalculatePathCostMatrix(int r1, int c1, int r2, int c2);
|
cannam@0
|
97
|
Chris@30
|
98 /**
|
Chris@30
|
99 * Track back after all of the matchers have been fed in order to
|
Chris@30
|
100 * obtain the lowest cost path available. Path x and y coordinate
|
Chris@30
|
101 * pairs are returned in corresponding elements of pathx and
|
Chris@30
|
102 * pathy. Return value is the length of the returned path: only
|
Chris@30
|
103 * this many elements from pathx and pathy are valid (any
|
Chris@30
|
104 * subsequent ones may be spurious).
|
Chris@31
|
105 *
|
Chris@31
|
106 * @param smooth whether to smooth the path before returning it
|
Chris@30
|
107 */
|
Chris@31
|
108 int retrievePath(bool smooth, std::vector<int> &pathx, std::vector<int> &pathy);
|
Chris@72
|
109
|
Chris@163
|
110 /**
|
Chris@163
|
111 * Get the path cost for the overall path to the end of both
|
Chris@163
|
112 * sources.
|
Chris@163
|
113 */
|
Chris@182
|
114 pathcost_t getOverallCost();
|
Chris@163
|
115
|
Chris@72
|
116 protected:
|
Chris@82
|
117 #ifdef PERFORM_ERROR_CHECKS
|
Chris@81
|
118 struct ErrorPosition {
|
Chris@86
|
119 enum Type { NoError = 0, WrongCost, WrongAdvance, NoAdvance };
|
Chris@81
|
120 ErrorPosition() : type(NoError) { }
|
Chris@81
|
121 Type type;
|
Chris@81
|
122 int r;
|
Chris@81
|
123 int c;
|
Chris@182
|
124 pathcost_t prevCost;
|
Chris@182
|
125 distance_t distance;
|
Chris@182
|
126 pathcost_t costWas;
|
Chris@182
|
127 pathcost_t costShouldBe;
|
Chris@181
|
128 advance_t advanceWas;
|
Chris@181
|
129 advance_t advanceShouldBe;
|
Chris@81
|
130 };
|
Chris@81
|
131 ErrorPosition checkPathCostMatrix();
|
Chris@92
|
132 void checkAndReport();
|
Chris@82
|
133 #endif
|
Chris@167
|
134
|
Chris@147
|
135 Matcher *m_m; // I do not own this
|
Chris@147
|
136
|
Chris@72
|
137 int m_duration1;
|
Chris@72
|
138 int m_duration2;
|
Chris@147
|
139 };
|
cannam@0
|
140
|
cannam@0
|
141 #endif
|