Mercurial > hg > match-vamp
comparison src/Matcher.h @ 74:b9aa663a607b refactors
Pull out feature extractor calls from Matcher, remove MatchFeeder, have only the feeder-from-features and use that in MatchVampPlugin
author | Chris Cannam |
---|---|
date | Wed, 19 Nov 2014 11:59:03 +0000 |
parents | c3c50d5e05b7 |
children | 0042b4d42167 |
comparison
equal
deleted
inserted
replaced
73:7e3c1bc0984a | 74:b9aa663a607b |
---|---|
21 #include <iostream> | 21 #include <iostream> |
22 #include <sstream> | 22 #include <sstream> |
23 #include <cmath> | 23 #include <cmath> |
24 | 24 |
25 #include "DistanceMetric.h" | 25 #include "DistanceMetric.h" |
26 #include "FeatureExtractor.h" | |
27 | 26 |
28 using std::vector; | 27 using std::vector; |
29 using std::string; | 28 using std::string; |
30 using std::cerr; | 29 using std::cerr; |
31 using std::endl; | 30 using std::endl; |
32 | 31 |
33 /** Represents an audio stream that can be matched to another audio | 32 /** Represents an audio feature stream that can be matched to another |
34 * stream of the same piece of music. The matching algorithm uses | 33 * audio stream of the same piece of music. The matching algorithm |
35 * dynamic time warping. | 34 * uses dynamic time warping. |
36 */ | 35 */ |
37 class Matcher | 36 class Matcher |
38 { | 37 { |
39 public: | 38 public: |
40 enum Advance { | 39 enum Advance { |
85 */ | 84 */ |
86 int maxRunCount; | 85 int maxRunCount; |
87 }; | 86 }; |
88 | 87 |
89 /** Constructor for Matcher. | 88 /** Constructor for Matcher. |
90 * | 89 * |
91 * @param p The Matcher representing the performance with which | 90 * A Matcher expects to be provided with feature vectors |
92 * this one is going to be matched. Some information is shared | 91 * calculated by some external code (for example, a |
93 * between the two matchers (currently one possesses the distance | 92 * FeatureExtractor). Call consumeFeatureVector to provide each |
94 * matrix and optimal path matrix). | 93 * feature frame. |
95 */ | |
96 Matcher(Parameters parameters, | |
97 FeatureExtractor::Parameters featureParams, | |
98 Matcher *p); | |
99 | |
100 /** Constructor for Matcher using externally supplied features. | |
101 * A Matcher made using this constructor will not carry out its | |
102 * own feature extraction from frequency-domain audio data, but | |
103 * instead will accept arbitrary feature frames calculated by | |
104 * some external code. | |
105 * | 94 * |
106 * @param p The Matcher representing the performance with which | 95 * @param p The Matcher representing the performance with which |
107 * this one is going to be matched. Some information is shared | 96 * this one is going to be matched. Some information is shared |
108 * between the two matchers (currently one possesses the distance | 97 * between the two matchers (currently one possesses the distance |
109 * matrix and optimal path matrix). | 98 * matrix and optimal path matrix). |
110 * | 99 * |
111 * @param featureSize Number of values in each feature vector. | 100 * @param featureSize Number of values in each of the feature |
101 * vectors that will be provided. | |
112 */ | 102 */ |
113 Matcher(Parameters parameters, Matcher *p, int featureSize); | 103 Matcher(Parameters parameters, Matcher *p, int featureSize); |
114 | 104 |
115 ~Matcher(); | 105 ~Matcher(); |
116 | 106 |
119 * | 109 * |
120 * @param p the Matcher representing the other performance | 110 * @param p the Matcher representing the other performance |
121 */ | 111 */ |
122 void setOtherMatcher(Matcher *p) { | 112 void setOtherMatcher(Matcher *p) { |
123 m_otherMatcher = p; | 113 m_otherMatcher = p; |
124 } // setOtherMatcher() | 114 } |
125 | 115 |
126 int getFrameCount() { | 116 int getFrameCount() { |
127 return m_frameCount; | 117 return m_frameCount; |
128 } | 118 } |
129 | 119 |
130 int getOtherFrameCount() { | 120 int getOtherFrameCount() { |
131 return m_otherMatcher->getFrameCount(); | 121 return m_otherMatcher->getFrameCount(); |
132 } | 122 } |
123 | |
124 /** Processes a feature vector frame, presumably calculated from | |
125 * audio data by some external code such as a FeatureExtractor. | |
126 * Calculates the distance to all frames stored in the | |
127 * otherMatcher and stores in the distance matrix, before | |
128 * updating the optimal path matrix using the dynamic time | |
129 * warping algorithm. | |
130 * | |
131 * The supplied feature must be of the size that was passed as | |
132 * featureSize to the constructor. | |
133 */ | |
134 void consumeFeatureVector(std::vector<double> feature); | |
133 | 135 |
134 /** Tests whether a location is in range in the minimum cost matrix. | 136 /** Tests whether a location is in range in the minimum cost matrix. |
135 * | 137 * |
136 * @param i the frame number of this Matcher | 138 * @param i the frame number of this Matcher |
137 * @param j the frame number of the other Matcher | 139 * @param j the frame number of the other Matcher |
214 /** Create internal structures and reset. */ | 216 /** Create internal structures and reset. */ |
215 void init(); | 217 void init(); |
216 | 218 |
217 /** The distXSize value has changed: resize internal buffers. */ | 219 /** The distXSize value has changed: resize internal buffers. */ |
218 void size(); | 220 void size(); |
219 | |
220 /** Process a frequency-domain frame of audio data using the | |
221 * built-in FeatureExtractor, then calculating the distance to | |
222 * all frames stored in the otherMatcher and storing them in the | |
223 * distance matrix, and finally updating the optimal path matrix | |
224 * using the dynamic time warping algorithm. | |
225 * | |
226 * Return value is the frame (post-processed, with warping, | |
227 * rectification, and normalisation as appropriate). | |
228 * | |
229 * The Matcher must have been constructed using the constructor | |
230 * without an external featureSize parameter in order to use this | |
231 * function. (Otherwise it will be expecting you to call | |
232 * consumeFeatureVector.) | |
233 */ | |
234 std::vector<double> consumeFrame(double *reBuffer, double *imBuffer); | |
235 | |
236 /** Processes a feature vector frame (presumably calculated from | |
237 * audio data by some external code). As consumeFrame, except | |
238 * that it does not calculate a feature from audio data but | |
239 * instead uses the supplied feature directly. | |
240 * | |
241 * The Matcher must have been constructed using the constructor | |
242 * that accepts an external featureSize parameter in order to | |
243 * use this function. The supplied feature must be of the size | |
244 * that was passed to the constructor. | |
245 */ | |
246 void consumeFeatureVector(std::vector<double> feature); | |
247 | 221 |
248 /** Updates an entry in the distance matrix and the optimal path matrix. | 222 /** Updates an entry in the distance matrix and the optimal path matrix. |
249 * | 223 * |
250 * @param i the frame number of this Matcher | 224 * @param i the frame number of this Matcher |
251 * @param j the frame number of the other Matcher | 225 * @param j the frame number of the other Matcher |
313 * and first and last vectors */ | 287 * and first and last vectors */ |
314 int m_distXSize; | 288 int m_distXSize; |
315 | 289 |
316 bool m_initialised; | 290 bool m_initialised; |
317 | 291 |
318 FeatureExtractor m_featureExtractor; | |
319 DistanceMetric m_metric; | 292 DistanceMetric m_metric; |
320 | 293 |
321 friend class MatchFeeder; | 294 friend class MatchFeeder; |
322 friend class MatchFeatureFeeder; | 295 friend class MatchFeatureFeeder; |
323 | 296 |