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
|
cannam@0
|
25 /** Maps cost matrix coordinates into an efficient
|
cannam@0
|
26 * (linear instead of quadratic space) representation.
|
cannam@0
|
27 * Stores result of most recent mapping for fast
|
cannam@0
|
28 * sequential access.
|
cannam@0
|
29 */
|
cannam@0
|
30 class Finder {
|
cannam@0
|
31
|
cannam@0
|
32 protected:
|
cannam@0
|
33 Matcher *pm1, *pm2;
|
cannam@0
|
34 int index1, index2, bestRow, bestCol;
|
cannam@0
|
35 int *rowRange;
|
cannam@0
|
36 int *colRange;
|
cannam@0
|
37
|
cannam@0
|
38 public:
|
cannam@0
|
39 Finder(Matcher *p1, Matcher *p2);
|
cannam@0
|
40
|
cannam@0
|
41 ~Finder();
|
cannam@0
|
42
|
cannam@0
|
43 /** Sets up the instance variables to point to the given
|
cannam@0
|
44 * coordinate in the distance matrix.
|
cannam@0
|
45 *
|
cannam@0
|
46 * @param i1 frameNumber in the first Matcher
|
cannam@0
|
47 * @param i2 frameNumber in the second Matcher
|
cannam@0
|
48 * @return true iff the point (i2,i1) is represented in the distance matrix
|
cannam@0
|
49 */
|
cannam@0
|
50 bool find(int i1, int i2);
|
cannam@0
|
51
|
cannam@0
|
52 /** Returns the range [lo,hi) of legal column indices for the
|
cannam@0
|
53 * given row. */
|
cannam@0
|
54 void getColRange(int row, int *range);
|
cannam@0
|
55
|
cannam@0
|
56 /** Returns the range [lo,hi) of legal row indices for the given
|
cannam@0
|
57 * column. */
|
cannam@0
|
58 void getRowRange(int col, int *range);
|
cannam@0
|
59
|
Chris@45
|
60 Matcher::Advance getExpandDirection(int row, int col);
|
Chris@45
|
61 Matcher::Advance getExpandDirection(int row, int col, bool check);
|
cannam@0
|
62
|
Chris@45
|
63 float getDistance(int row, int col);
|
Chris@45
|
64 void setDistance(int row, int col, float b);
|
cannam@0
|
65
|
Chris@45
|
66 float getPathCost(int row, int col);
|
Chris@45
|
67 float getRawPathCost(int row, int col); //!!!???
|
Chris@45
|
68 void setPathCost(int row, int col, float i);
|
cannam@0
|
69
|
Chris@45
|
70 Matcher::Advance getAdvance();
|
Chris@45
|
71 void setAdvance(Matcher::Advance a);
|
Chris@45
|
72
|
Chris@45
|
73 float getDistance();
|
Chris@45
|
74 void setDistance(float b);
|
cannam@0
|
75
|
Chris@45
|
76 float getPathCost();
|
Chris@45
|
77 void setPathCost(float i);
|
cannam@0
|
78
|
cannam@0
|
79 /** Calculates a rectangle of the path cost matrix so that the
|
cannam@0
|
80 * minimum cost path between the bottom left and top right
|
cannam@0
|
81 * corners can be computed. Caches previous values to avoid
|
cannam@0
|
82 * calling find() multiple times, and is several times faster as
|
cannam@0
|
83 * a result.
|
cannam@0
|
84 *
|
cannam@0
|
85 * @param r1 the bottom of the rectangle to be calculated
|
cannam@0
|
86 * @param c1 the left side of the rectangle to be calculated
|
cannam@0
|
87 * @param r2 the top of the rectangle to be calculated
|
cannam@0
|
88 * @param c2 the right side of the rectangle to be calculated
|
cannam@0
|
89 */
|
cannam@0
|
90 void recalculatePathCostMatrix(int r1, int c1, int r2, int c2);
|
cannam@0
|
91
|
Chris@30
|
92 /**
|
Chris@30
|
93 * Track back after all of the matchers have been fed in order to
|
Chris@30
|
94 * obtain the lowest cost path available. Path x and y coordinate
|
Chris@30
|
95 * pairs are returned in corresponding elements of pathx and
|
Chris@30
|
96 * pathy. Return value is the length of the returned path: only
|
Chris@30
|
97 * this many elements from pathx and pathy are valid (any
|
Chris@30
|
98 * subsequent ones may be spurious).
|
Chris@31
|
99 *
|
Chris@31
|
100 * @param smooth whether to smooth the path before returning it
|
Chris@30
|
101 */
|
Chris@31
|
102 int retrievePath(bool smooth, std::vector<int> &pathx, std::vector<int> &pathy);
|
Chris@30
|
103
|
cannam@0
|
104 }; // class Finder
|
cannam@0
|
105
|
cannam@0
|
106 #endif
|