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 #include "MatchVampPlugin.h"
|
cannam@0
|
18
|
cannam@0
|
19 #include "Matcher.h"
|
Chris@74
|
20 #include "MatchFeatureFeeder.h"
|
Chris@74
|
21 #include "FeatureExtractor.h"
|
cannam@0
|
22 #include "Path.h"
|
cannam@0
|
23
|
cannam@0
|
24 #include <vamp/vamp.h>
|
cannam@0
|
25 #include <vamp-sdk/PluginAdapter.h>
|
cannam@0
|
26 #include <vamp-sdk/RealTime.h>
|
cannam@0
|
27
|
cannam@0
|
28 #include <vector>
|
cannam@0
|
29 #include <algorithm>
|
cannam@0
|
30
|
cannam@0
|
31 //static int extant = 0;
|
cannam@0
|
32
|
cannam@0
|
33 #ifdef _WIN32
|
cannam@0
|
34 HANDLE
|
cannam@0
|
35 MatchVampPlugin::m_serialisingMutex;
|
cannam@0
|
36 #else
|
cannam@0
|
37 pthread_mutex_t
|
cannam@0
|
38 MatchVampPlugin::m_serialisingMutex;
|
cannam@0
|
39 #endif
|
cannam@0
|
40
|
cannam@0
|
41 bool
|
cannam@0
|
42 MatchVampPlugin::m_serialisingMutexInitialised = false;
|
cannam@0
|
43
|
Chris@10
|
44 // We want to ensure our freq map / crossover bin in Matcher.cpp are
|
Chris@10
|
45 // always valid with a fixed FFT length in seconds, so must reject low
|
Chris@10
|
46 // sample rates
|
Chris@10
|
47 static float sampleRateMin = 5000.f;
|
Chris@10
|
48
|
Chris@52
|
49 static float defaultStepTime = 0.020f;
|
Chris@15
|
50
|
cannam@0
|
51 MatchVampPlugin::MatchVampPlugin(float inputSampleRate) :
|
cannam@0
|
52 Plugin(inputSampleRate),
|
Chris@52
|
53 m_stepSize(int(inputSampleRate * defaultStepTime + 0.001)),
|
Chris@15
|
54 m_stepTime(defaultStepTime),
|
Chris@16
|
55 m_blockSize(2048),
|
cannam@0
|
56 m_serialise(false),
|
cannam@0
|
57 m_begin(true),
|
Chris@17
|
58 m_locked(false),
|
Chris@138
|
59 m_smooth(false),
|
Chris@74
|
60 m_frameNo(0),
|
Chris@113
|
61 m_params(defaultStepTime),
|
Chris@113
|
62 m_defaultParams(defaultStepTime),
|
Chris@38
|
63 m_feParams(inputSampleRate, m_blockSize),
|
Chris@103
|
64 m_defaultFeParams(inputSampleRate, m_blockSize),
|
Chris@161
|
65 m_secondReferenceFrequency(m_defaultFeParams.referenceFrequency),
|
Chris@103
|
66 m_fcParams(),
|
Chris@143
|
67 m_defaultFcParams(),
|
Chris@143
|
68 m_dParams(),
|
Chris@143
|
69 m_defaultDParams()
|
cannam@0
|
70 {
|
Chris@10
|
71 if (inputSampleRate < sampleRateMin) {
|
Chris@10
|
72 std::cerr << "MatchVampPlugin::MatchVampPlugin: input sample rate "
|
Chris@10
|
73 << inputSampleRate << " < min supported rate "
|
Chris@10
|
74 << sampleRateMin << ", plugin will refuse to initialise"
|
Chris@10
|
75 << std::endl;
|
Chris@10
|
76 }
|
Chris@10
|
77
|
cannam@0
|
78 if (!m_serialisingMutexInitialised) {
|
cannam@0
|
79 m_serialisingMutexInitialised = true;
|
cannam@0
|
80 #ifdef _WIN32
|
cannam@0
|
81 m_serialisingMutex = CreateMutex(NULL, FALSE, NULL);
|
cannam@0
|
82 #else
|
cannam@0
|
83 pthread_mutex_init(&m_serialisingMutex, 0);
|
cannam@0
|
84 #endif
|
cannam@0
|
85 }
|
cannam@0
|
86
|
Chris@107
|
87 m_pipeline = 0;
|
cannam@0
|
88 // std::cerr << "MatchVampPlugin::MatchVampPlugin(" << this << "): extant = " << ++extant << std::endl;
|
cannam@0
|
89 }
|
cannam@0
|
90
|
cannam@0
|
91 MatchVampPlugin::~MatchVampPlugin()
|
cannam@0
|
92 {
|
cannam@0
|
93 // std::cerr << "MatchVampPlugin::~MatchVampPlugin(" << this << "): extant = " << --extant << std::endl;
|
cannam@0
|
94
|
Chris@107
|
95 delete m_pipeline;
|
cannam@0
|
96
|
cannam@0
|
97 if (m_locked) {
|
cannam@0
|
98 #ifdef _WIN32
|
cannam@0
|
99 ReleaseMutex(m_serialisingMutex);
|
cannam@0
|
100 #else
|
cannam@0
|
101 pthread_mutex_unlock(&m_serialisingMutex);
|
cannam@0
|
102 #endif
|
cannam@0
|
103 m_locked = false;
|
cannam@0
|
104 }
|
cannam@0
|
105 }
|
cannam@0
|
106
|
cannam@0
|
107 string
|
cannam@0
|
108 MatchVampPlugin::getIdentifier() const
|
cannam@0
|
109 {
|
cannam@0
|
110 return "match";
|
cannam@0
|
111 }
|
cannam@0
|
112
|
cannam@0
|
113 string
|
cannam@0
|
114 MatchVampPlugin::getName() const
|
cannam@0
|
115 {
|
cannam@0
|
116 return "Match Performance Aligner";
|
cannam@0
|
117 }
|
cannam@0
|
118
|
cannam@0
|
119 string
|
cannam@0
|
120 MatchVampPlugin::getDescription() const
|
cannam@0
|
121 {
|
cannam@0
|
122 return "Calculate alignment between two performances in separate channel inputs";
|
cannam@0
|
123 }
|
cannam@0
|
124
|
cannam@0
|
125 string
|
cannam@0
|
126 MatchVampPlugin::getMaker() const
|
cannam@0
|
127 {
|
cannam@0
|
128 return "Simon Dixon (plugin by Chris Cannam)";
|
cannam@0
|
129 }
|
cannam@0
|
130
|
cannam@0
|
131 int
|
cannam@0
|
132 MatchVampPlugin::getPluginVersion() const
|
cannam@0
|
133 {
|
Chris@137
|
134 return 3;
|
cannam@0
|
135 }
|
cannam@0
|
136
|
cannam@0
|
137 string
|
cannam@0
|
138 MatchVampPlugin::getCopyright() const
|
cannam@0
|
139 {
|
cannam@0
|
140 return "GPL";
|
cannam@0
|
141 }
|
cannam@0
|
142
|
cannam@0
|
143 MatchVampPlugin::ParameterList
|
cannam@0
|
144 MatchVampPlugin::getParameterDescriptors() const
|
cannam@0
|
145 {
|
cannam@0
|
146 ParameterList list;
|
cannam@0
|
147
|
cannam@0
|
148 ParameterDescriptor desc;
|
Chris@18
|
149
|
Chris@162
|
150 desc.identifier = "freq1";
|
Chris@162
|
151 desc.name = "Tuning frequency of first input";
|
Chris@162
|
152 desc.description = "Tuning frequency (concert A) for the reference audio.";
|
Chris@162
|
153 desc.minValue = 220.0;
|
Chris@162
|
154 desc.maxValue = 880.0;
|
Chris@162
|
155 desc.defaultValue = (float)m_defaultFeParams.referenceFrequency;
|
Chris@162
|
156 desc.isQuantized = false;
|
Chris@162
|
157 desc.unit = "Hz";
|
Chris@162
|
158 list.push_back(desc);
|
Chris@162
|
159
|
Chris@162
|
160 desc.identifier = "freq2";
|
Chris@162
|
161 desc.name = "Tuning frequency of second input";
|
Chris@162
|
162 desc.description = "Tuning frequency (concert A) for the other audio.";
|
Chris@162
|
163 desc.minValue = 220.0;
|
Chris@162
|
164 desc.maxValue = 880.0;
|
Chris@162
|
165 desc.defaultValue = (float)m_defaultFeParams.referenceFrequency;
|
Chris@162
|
166 desc.isQuantized = false;
|
Chris@162
|
167 desc.unit = "Hz";
|
Chris@162
|
168 list.push_back(desc);
|
Chris@162
|
169
|
Chris@177
|
170 desc.identifier = "minfreq";
|
Chris@177
|
171 desc.name = "Minimum frequency";
|
Chris@177
|
172 desc.description = "Minimum frequency to include in features.";
|
Chris@177
|
173 desc.minValue = 0.0;
|
Chris@177
|
174 desc.maxValue = (float)m_inputSampleRate / 4.f;
|
Chris@177
|
175 desc.defaultValue = (float)m_defaultFeParams.minFrequency;
|
Chris@177
|
176 desc.isQuantized = false;
|
Chris@177
|
177 desc.unit = "Hz";
|
Chris@177
|
178 list.push_back(desc);
|
Chris@177
|
179
|
Chris@177
|
180 desc.identifier = "maxfreq";
|
Chris@177
|
181 desc.name = "Maximum frequency";
|
Chris@177
|
182 desc.description = "Maximum frequency to include in features.";
|
Chris@177
|
183 desc.minValue = 1000.0;
|
Chris@177
|
184 desc.maxValue = (float)m_inputSampleRate / 2.f;
|
Chris@177
|
185 desc.defaultValue = (float)m_defaultFeParams.maxFrequency;
|
Chris@177
|
186 desc.isQuantized = false;
|
Chris@177
|
187 desc.unit = "Hz";
|
Chris@177
|
188 list.push_back(desc);
|
Chris@177
|
189
|
Chris@162
|
190 desc.unit = "";
|
Chris@162
|
191
|
Chris@162
|
192 desc.identifier = "usechroma";
|
Chris@162
|
193 desc.name = "Feature type";
|
Chris@162
|
194 desc.description = "Whether to use warped spectrogram or chroma frequency map";
|
cannam@0
|
195 desc.minValue = 0;
|
cannam@0
|
196 desc.maxValue = 1;
|
Chris@162
|
197 desc.defaultValue = m_defaultFeParams.useChromaFrequencyMap ? 1 : 0;
|
Chris@162
|
198 desc.isQuantized = true;
|
Chris@162
|
199 desc.quantizeStep = 1;
|
Chris@162
|
200 desc.valueNames.clear();
|
Chris@162
|
201 desc.valueNames.push_back("Spectral");
|
Chris@162
|
202 desc.valueNames.push_back("Chroma");
|
Chris@162
|
203 list.push_back(desc);
|
Chris@162
|
204
|
Chris@162
|
205 desc.valueNames.clear();
|
Chris@162
|
206
|
Chris@162
|
207 desc.identifier = "usespecdiff";
|
Chris@162
|
208 desc.name = "Use feature difference";
|
Chris@162
|
209 desc.description = "Whether to use half-wave rectified feature-to-feature difference instead of straight spectral or chroma feature";
|
Chris@162
|
210 desc.minValue = 0;
|
Chris@162
|
211 desc.maxValue = 1;
|
Chris@180
|
212 desc.defaultValue = (float)m_defaultFcParams.order;
|
cannam@0
|
213 desc.isQuantized = true;
|
cannam@0
|
214 desc.quantizeStep = 1;
|
cannam@0
|
215 list.push_back(desc);
|
cannam@0
|
216
|
Chris@18
|
217 desc.identifier = "framenorm";
|
Chris@162
|
218 desc.name = "Frame normalisation";
|
Chris@162
|
219 desc.description = "Type of normalisation to use for features";
|
Chris@18
|
220 desc.minValue = 0;
|
Chris@18
|
221 desc.maxValue = 2;
|
Chris@180
|
222 desc.defaultValue = (float)m_defaultFcParams.norm;
|
Chris@18
|
223 desc.isQuantized = true;
|
Chris@18
|
224 desc.quantizeStep = 1;
|
Chris@18
|
225 desc.valueNames.clear();
|
Chris@18
|
226 desc.valueNames.push_back("None");
|
Chris@162
|
227 desc.valueNames.push_back("Sum to 1");
|
Chris@162
|
228 desc.valueNames.push_back("Long-term average");
|
Chris@18
|
229 list.push_back(desc);
|
Chris@18
|
230 desc.valueNames.clear();
|
Chris@148
|
231 desc.defaultValue = (float)m_defaultFcParams.silenceThreshold;
|
Chris@151
|
232
|
Chris@156
|
233 desc.identifier = "metric";
|
Chris@156
|
234 desc.name = "Distance metric";
|
Chris@156
|
235 desc.description = "Metric for distance calculations.";
|
Chris@156
|
236 desc.minValue = 0;
|
Chris@157
|
237 desc.maxValue = 2;
|
Chris@180
|
238 desc.defaultValue = (float)m_defaultDParams.metric;
|
Chris@156
|
239 desc.isQuantized = true;
|
Chris@156
|
240 desc.quantizeStep = 1;
|
Chris@156
|
241 desc.valueNames.clear();
|
Chris@157
|
242 desc.valueNames.push_back("Manhattan");
|
Chris@156
|
243 desc.valueNames.push_back("Euclidean");
|
Chris@156
|
244 desc.valueNames.push_back("Cosine");
|
Chris@156
|
245 list.push_back(desc);
|
Chris@156
|
246 desc.valueNames.clear();
|
Chris@156
|
247
|
Chris@162
|
248 desc.identifier = "distnorm";
|
Chris@162
|
249 desc.name = "Distance normalisation";
|
Chris@162
|
250 desc.description = "Type of normalisation to use for distance metric";
|
Chris@162
|
251 desc.minValue = 0;
|
Chris@162
|
252 desc.maxValue = 2;
|
Chris@180
|
253 desc.defaultValue = (float)m_defaultDParams.norm;
|
Chris@162
|
254 desc.isQuantized = true;
|
Chris@162
|
255 desc.quantizeStep = 1;
|
Chris@162
|
256 desc.valueNames.clear();
|
Chris@162
|
257 desc.valueNames.push_back("None");
|
Chris@162
|
258 desc.valueNames.push_back("Sum of frames");
|
Chris@162
|
259 desc.valueNames.push_back("Log sum of frames");
|
Chris@162
|
260 list.push_back(desc);
|
Chris@162
|
261 desc.valueNames.clear();
|
Chris@162
|
262
|
Chris@162
|
263 desc.identifier = "silencethreshold";
|
Chris@162
|
264 desc.name = "Silence threshold";
|
Chris@162
|
265 desc.description = "Total frame energy threshold below which a feature will be regarded as silent";
|
Chris@162
|
266 desc.minValue = 0;
|
Chris@165
|
267 desc.maxValue = 0.1f;
|
Chris@165
|
268 desc.defaultValue = (float)m_defaultFcParams.silenceThreshold;
|
Chris@162
|
269 desc.isQuantized = false;
|
Chris@162
|
270 list.push_back(desc);
|
Chris@162
|
271
|
Chris@151
|
272 desc.identifier = "noise";
|
Chris@162
|
273 desc.name = "Add noise";
|
Chris@151
|
274 desc.description = "Whether to mix in a small constant white noise term when calculating feature distance. This can improve alignment against sources containing cleanly synthesised audio.";
|
Chris@151
|
275 desc.minValue = 0;
|
Chris@151
|
276 desc.maxValue = 1;
|
Chris@180
|
277 desc.defaultValue = (float)m_defaultDParams.noise;
|
Chris@151
|
278 desc.isQuantized = true;
|
Chris@151
|
279 desc.quantizeStep = 1;
|
Chris@151
|
280 list.push_back(desc);
|
Chris@136
|
281
|
Chris@25
|
282 desc.identifier = "gradientlimit";
|
Chris@162
|
283 desc.name = "Gradient limit";
|
Chris@18
|
284 desc.description = "Limit of number of frames that will be accepted from one source without a frame from the other source being accepted";
|
Chris@18
|
285 desc.minValue = 1;
|
Chris@18
|
286 desc.maxValue = 10;
|
Chris@180
|
287 desc.defaultValue = (float)m_defaultParams.maxRunCount;
|
Chris@18
|
288 desc.isQuantized = true;
|
Chris@18
|
289 desc.quantizeStep = 1;
|
Chris@18
|
290 list.push_back(desc);
|
Chris@18
|
291
|
Chris@25
|
292 desc.identifier = "zonewidth";
|
Chris@162
|
293 desc.name = "Search zone width";
|
Chris@25
|
294 desc.description = "Width of the search zone (error margin) either side of the ongoing match position, in seconds";
|
Chris@25
|
295 desc.minValue = 1;
|
Chris@25
|
296 desc.maxValue = 60;
|
Chris@52
|
297 desc.defaultValue = (float)m_defaultParams.blockTime;
|
Chris@25
|
298 desc.isQuantized = true;
|
Chris@25
|
299 desc.quantizeStep = 1;
|
Chris@25
|
300 desc.unit = "s";
|
Chris@25
|
301 list.push_back(desc);
|
Chris@25
|
302
|
Chris@83
|
303 desc.identifier = "diagonalweight";
|
Chris@162
|
304 desc.name = "Diagonal weight";
|
Chris@83
|
305 desc.description = "Weight applied to cost of diagonal step relative to horizontal or vertical step. The default of 2.0 is good for gross tracking of quite different performances; closer to 1.0 produces a smoother path for performances more similar in tempo";
|
Chris@83
|
306 desc.minValue = 1.0;
|
Chris@86
|
307 desc.maxValue = 2.0;
|
Chris@138
|
308 desc.defaultValue = (float)m_defaultParams.diagonalWeight;
|
Chris@83
|
309 desc.isQuantized = false;
|
Chris@83
|
310 desc.unit = "";
|
Chris@83
|
311 list.push_back(desc);
|
Chris@83
|
312
|
Chris@32
|
313 desc.identifier = "smooth";
|
Chris@162
|
314 desc.name = "Use path smoothing";
|
Chris@138
|
315 desc.description = "Smooth the path by replacing steps with diagonals. (This was enabled by default in earlier versions of the MATCH plugin, but the default now is to produce an un-smoothed path.)";
|
Chris@32
|
316 desc.minValue = 0;
|
Chris@32
|
317 desc.maxValue = 1;
|
Chris@138
|
318 desc.defaultValue = 0;
|
Chris@32
|
319 desc.isQuantized = true;
|
Chris@32
|
320 desc.quantizeStep = 1;
|
Chris@32
|
321 desc.unit = "";
|
Chris@32
|
322 list.push_back(desc);
|
Chris@32
|
323
|
Chris@162
|
324 desc.identifier = "serialise";
|
Chris@162
|
325 desc.name = "Serialise plugin invocations";
|
Chris@162
|
326 desc.description = "Reduce potential memory load at the expense of multiprocessor performance by serialising multi-threaded plugin runs";
|
Chris@162
|
327 desc.minValue = 0;
|
Chris@162
|
328 desc.maxValue = 1;
|
Chris@162
|
329 desc.defaultValue = 0;
|
Chris@162
|
330 desc.isQuantized = true;
|
Chris@162
|
331 desc.quantizeStep = 1;
|
Chris@161
|
332 list.push_back(desc);
|
Chris@161
|
333
|
cannam@0
|
334 return list;
|
cannam@0
|
335 }
|
cannam@0
|
336
|
cannam@0
|
337 float
|
cannam@0
|
338 MatchVampPlugin::getParameter(std::string name) const
|
cannam@0
|
339 {
|
cannam@0
|
340 if (name == "serialise") {
|
cannam@0
|
341 return m_serialise ? 1.0 : 0.0;
|
Chris@18
|
342 } else if (name == "framenorm") {
|
Chris@180
|
343 return (float)m_fcParams.norm;
|
Chris@18
|
344 } else if (name == "distnorm") {
|
Chris@180
|
345 return (float)m_dParams.norm;
|
Chris@18
|
346 } else if (name == "usespecdiff") {
|
Chris@180
|
347 return (float)m_fcParams.order;
|
Chris@18
|
348 } else if (name == "usechroma") {
|
Chris@38
|
349 return m_feParams.useChromaFrequencyMap ? 1.0 : 0.0;
|
Chris@25
|
350 } else if (name == "gradientlimit") {
|
Chris@180
|
351 return (float)m_params.maxRunCount;
|
Chris@83
|
352 } else if (name == "diagonalweight") {
|
Chris@83
|
353 return m_params.diagonalWeight;
|
Chris@25
|
354 } else if (name == "zonewidth") {
|
Chris@52
|
355 return (float)m_params.blockTime;
|
Chris@32
|
356 } else if (name == "smooth") {
|
Chris@32
|
357 return m_smooth ? 1.0 : 0.0;
|
Chris@136
|
358 } else if (name == "silencethreshold") {
|
Chris@148
|
359 return (float)m_fcParams.silenceThreshold;
|
Chris@156
|
360 } else if (name == "metric") {
|
Chris@180
|
361 return (float)m_dParams.metric;
|
Chris@151
|
362 } else if (name == "noise") {
|
Chris@151
|
363 return m_dParams.noise;
|
Chris@161
|
364 } else if (name == "freq1") {
|
Chris@161
|
365 return (float)m_feParams.referenceFrequency;
|
Chris@161
|
366 } else if (name == "freq2") {
|
Chris@161
|
367 return (float)m_secondReferenceFrequency;
|
Chris@177
|
368 } else if (name == "minfreq") {
|
Chris@177
|
369 return (float)m_feParams.minFrequency;
|
Chris@177
|
370 } else if (name == "maxfreq") {
|
Chris@177
|
371 return (float)m_feParams.maxFrequency;
|
cannam@0
|
372 }
|
Chris@18
|
373
|
cannam@0
|
374 return 0.0;
|
cannam@0
|
375 }
|
cannam@0
|
376
|
cannam@0
|
377 void
|
cannam@0
|
378 MatchVampPlugin::setParameter(std::string name, float value)
|
cannam@0
|
379 {
|
cannam@0
|
380 if (name == "serialise") {
|
cannam@0
|
381 m_serialise = (value > 0.5);
|
Chris@18
|
382 } else if (name == "framenorm") {
|
Chris@103
|
383 m_fcParams.norm = (FeatureConditioner::Normalisation)(int(value + 0.1));
|
Chris@18
|
384 } else if (name == "distnorm") {
|
Chris@143
|
385 m_dParams.norm = (DistanceMetric::DistanceNormalisation)(int(value + 0.1));
|
Chris@18
|
386 } else if (name == "usespecdiff") {
|
Chris@103
|
387 m_fcParams.order = (FeatureConditioner::OutputOrder)(int(value + 0.1));
|
Chris@18
|
388 } else if (name == "usechroma") {
|
Chris@38
|
389 m_feParams.useChromaFrequencyMap = (value > 0.5);
|
Chris@25
|
390 } else if (name == "gradientlimit") {
|
Chris@18
|
391 m_params.maxRunCount = int(value + 0.1);
|
Chris@83
|
392 } else if (name == "diagonalweight") {
|
Chris@83
|
393 m_params.diagonalWeight = value;
|
Chris@25
|
394 } else if (name == "zonewidth") {
|
Chris@25
|
395 m_params.blockTime = value;
|
Chris@32
|
396 } else if (name == "smooth") {
|
Chris@32
|
397 m_smooth = (value > 0.5);
|
Chris@136
|
398 } else if (name == "silencethreshold") {
|
Chris@136
|
399 m_fcParams.silenceThreshold = value;
|
Chris@156
|
400 } else if (name == "metric") {
|
Chris@156
|
401 m_dParams.metric = (DistanceMetric::Metric)(int(value + 0.1));
|
Chris@151
|
402 } else if (name == "noise") {
|
Chris@151
|
403 m_dParams.noise = (DistanceMetric::NoiseAddition)(int(value + 0.1));
|
Chris@161
|
404 } else if (name == "freq1") {
|
Chris@161
|
405 m_feParams.referenceFrequency = value;
|
Chris@161
|
406 } else if (name == "freq2") {
|
Chris@161
|
407 m_secondReferenceFrequency = value;
|
Chris@177
|
408 } else if (name == "minfreq") {
|
Chris@177
|
409 m_feParams.minFrequency = value;
|
Chris@177
|
410 } else if (name == "maxfreq") {
|
Chris@177
|
411 m_feParams.maxFrequency = value;
|
cannam@0
|
412 }
|
cannam@0
|
413 }
|
cannam@0
|
414
|
cannam@0
|
415 size_t
|
cannam@0
|
416 MatchVampPlugin::getPreferredStepSize() const
|
cannam@0
|
417 {
|
Chris@52
|
418 return int(m_inputSampleRate * defaultStepTime + 0.001);
|
cannam@0
|
419 }
|
cannam@0
|
420
|
cannam@0
|
421 size_t
|
cannam@0
|
422 MatchVampPlugin::getPreferredBlockSize() const
|
cannam@0
|
423 {
|
Chris@15
|
424 return 2048;
|
cannam@0
|
425 }
|
cannam@0
|
426
|
cannam@0
|
427 void
|
Chris@17
|
428 MatchVampPlugin::createMatchers()
|
cannam@0
|
429 {
|
Chris@17
|
430 m_params.hopTime = m_stepTime;
|
Chris@38
|
431 m_feParams.fftSize = m_blockSize;
|
Chris@107
|
432
|
Chris@161
|
433 m_pipeline = new MatchPipeline(m_feParams, m_fcParams, m_dParams, m_params,
|
Chris@161
|
434 m_secondReferenceFrequency);
|
cannam@0
|
435 }
|
cannam@0
|
436
|
cannam@0
|
437 bool
|
cannam@0
|
438 MatchVampPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
cannam@0
|
439 {
|
Chris@10
|
440 if (m_inputSampleRate < sampleRateMin) {
|
Chris@10
|
441 std::cerr << "MatchVampPlugin::MatchVampPlugin: input sample rate "
|
Chris@10
|
442 << m_inputSampleRate << " < min supported rate "
|
Chris@10
|
443 << sampleRateMin << std::endl;
|
Chris@10
|
444 return false;
|
Chris@10
|
445 }
|
cannam@0
|
446 if (channels < getMinChannelCount() ||
|
cannam@0
|
447 channels > getMaxChannelCount()) return false;
|
cannam@1
|
448 if (stepSize > blockSize/2 ||
|
cannam@0
|
449 blockSize != getPreferredBlockSize()) return false;
|
Chris@15
|
450
|
Chris@180
|
451 m_stepSize = (int)stepSize;
|
Chris@15
|
452 m_stepTime = float(stepSize) / m_inputSampleRate;
|
Chris@180
|
453 m_blockSize = (int)blockSize;
|
Chris@15
|
454
|
Chris@15
|
455 createMatchers();
|
cannam@0
|
456 m_begin = true;
|
cannam@0
|
457 m_locked = false;
|
Chris@15
|
458
|
cannam@0
|
459 return true;
|
cannam@0
|
460 }
|
cannam@0
|
461
|
cannam@0
|
462 void
|
cannam@0
|
463 MatchVampPlugin::reset()
|
cannam@0
|
464 {
|
Chris@107
|
465 delete m_pipeline;
|
Chris@107
|
466 m_pipeline = 0;
|
Chris@74
|
467 m_frameNo = 0;
|
cannam@6
|
468 createMatchers();
|
cannam@6
|
469 m_begin = true;
|
cannam@6
|
470 m_locked = false;
|
cannam@0
|
471 }
|
cannam@0
|
472
|
cannam@0
|
473 MatchVampPlugin::OutputList
|
cannam@0
|
474 MatchVampPlugin::getOutputDescriptors() const
|
cannam@0
|
475 {
|
cannam@0
|
476 OutputList list;
|
cannam@0
|
477
|
Chris@52
|
478 float outRate = 1.0f / m_stepTime;
|
cannam@0
|
479
|
cannam@0
|
480 OutputDescriptor desc;
|
cannam@0
|
481 desc.identifier = "path";
|
cannam@0
|
482 desc.name = "Path";
|
cannam@0
|
483 desc.description = "Alignment path";
|
cannam@0
|
484 desc.unit = "";
|
cannam@0
|
485 desc.hasFixedBinCount = true;
|
cannam@0
|
486 desc.binCount = 1;
|
cannam@0
|
487 desc.hasKnownExtents = false;
|
cannam@0
|
488 desc.isQuantized = true;
|
cannam@0
|
489 desc.quantizeStep = 1;
|
cannam@0
|
490 desc.sampleType = OutputDescriptor::VariableSampleRate;
|
cannam@0
|
491 desc.sampleRate = outRate;
|
Chris@180
|
492 m_pathOutNo = int(list.size());
|
cannam@0
|
493 list.push_back(desc);
|
cannam@0
|
494
|
cannam@0
|
495 desc.identifier = "a_b";
|
cannam@0
|
496 desc.name = "A-B Timeline";
|
cannam@0
|
497 desc.description = "Timing in performance B corresponding to moments in performance A";
|
cannam@0
|
498 desc.unit = "sec";
|
cannam@0
|
499 desc.hasFixedBinCount = true;
|
cannam@0
|
500 desc.binCount = 1;
|
cannam@0
|
501 desc.hasKnownExtents = false;
|
cannam@0
|
502 desc.isQuantized = false;
|
cannam@0
|
503 desc.sampleType = OutputDescriptor::VariableSampleRate;
|
cannam@0
|
504 desc.sampleRate = outRate;
|
Chris@180
|
505 m_abOutNo = int(list.size());
|
cannam@0
|
506 list.push_back(desc);
|
cannam@0
|
507
|
cannam@0
|
508 desc.identifier = "b_a";
|
cannam@0
|
509 desc.name = "B-A Timeline";
|
cannam@0
|
510 desc.description = "Timing in performance A corresponding to moments in performance B";
|
cannam@0
|
511 desc.unit = "sec";
|
cannam@0
|
512 desc.hasFixedBinCount = true;
|
cannam@0
|
513 desc.binCount = 1;
|
cannam@0
|
514 desc.hasKnownExtents = false;
|
cannam@0
|
515 desc.isQuantized = false;
|
cannam@0
|
516 desc.sampleType = OutputDescriptor::VariableSampleRate;
|
cannam@0
|
517 desc.sampleRate = outRate;
|
Chris@180
|
518 m_baOutNo = int(list.size());
|
cannam@0
|
519 list.push_back(desc);
|
cannam@0
|
520
|
cannam@0
|
521 desc.identifier = "a_b_divergence";
|
cannam@0
|
522 desc.name = "A-B Divergence";
|
cannam@0
|
523 desc.description = "Difference between timings in performances A and B";
|
cannam@0
|
524 desc.unit = "sec";
|
cannam@0
|
525 desc.hasFixedBinCount = true;
|
cannam@0
|
526 desc.binCount = 1;
|
cannam@0
|
527 desc.hasKnownExtents = false;
|
cannam@0
|
528 desc.isQuantized = false;
|
cannam@0
|
529 desc.sampleType = OutputDescriptor::VariableSampleRate;
|
cannam@0
|
530 desc.sampleRate = outRate;
|
Chris@180
|
531 m_abDivOutNo = int(list.size());
|
cannam@0
|
532 list.push_back(desc);
|
cannam@0
|
533
|
cannam@0
|
534 desc.identifier = "a_b_temporatio";
|
cannam@0
|
535 desc.name = "A-B Tempo Ratio";
|
cannam@0
|
536 desc.description = "Ratio of tempi between performances A and B";
|
cannam@0
|
537 desc.unit = "";
|
cannam@0
|
538 desc.hasFixedBinCount = true;
|
cannam@0
|
539 desc.binCount = 1;
|
cannam@0
|
540 desc.hasKnownExtents = false;
|
cannam@0
|
541 desc.isQuantized = false;
|
cannam@0
|
542 desc.sampleType = OutputDescriptor::VariableSampleRate;
|
cannam@0
|
543 desc.sampleRate = outRate;
|
Chris@180
|
544 m_abRatioOutNo = int(list.size());
|
cannam@0
|
545 list.push_back(desc);
|
cannam@0
|
546
|
Chris@38
|
547 int featureSize = FeatureExtractor(m_feParams).getFeatureSize();
|
Chris@38
|
548
|
Chris@15
|
549 desc.identifier = "a_features";
|
Chris@140
|
550 desc.name = "Raw A Features";
|
Chris@15
|
551 desc.description = "Spectral features extracted from performance A";
|
Chris@15
|
552 desc.unit = "";
|
Chris@15
|
553 desc.hasFixedBinCount = true;
|
Chris@38
|
554 desc.binCount = featureSize;
|
Chris@15
|
555 desc.hasKnownExtents = false;
|
Chris@15
|
556 desc.isQuantized = false;
|
Chris@16
|
557 desc.sampleType = OutputDescriptor::FixedSampleRate;
|
Chris@15
|
558 desc.sampleRate = outRate;
|
Chris@180
|
559 m_aFeaturesOutNo = int(list.size());
|
Chris@16
|
560 list.push_back(desc);
|
Chris@16
|
561
|
Chris@16
|
562 desc.identifier = "b_features";
|
Chris@140
|
563 desc.name = "Raw B Features";
|
Chris@16
|
564 desc.description = "Spectral features extracted from performance B";
|
Chris@16
|
565 desc.unit = "";
|
Chris@16
|
566 desc.hasFixedBinCount = true;
|
Chris@38
|
567 desc.binCount = featureSize;
|
Chris@16
|
568 desc.hasKnownExtents = false;
|
Chris@16
|
569 desc.isQuantized = false;
|
Chris@16
|
570 desc.sampleType = OutputDescriptor::FixedSampleRate;
|
Chris@16
|
571 desc.sampleRate = outRate;
|
Chris@180
|
572 m_bFeaturesOutNo = int(list.size());
|
Chris@15
|
573 list.push_back(desc);
|
Chris@15
|
574
|
Chris@140
|
575 desc.identifier = "a_cfeatures";
|
Chris@140
|
576 desc.name = "Conditioned A Features";
|
Chris@140
|
577 desc.description = "Spectral features extracted from performance A, after normalisation and conditioning";
|
Chris@140
|
578 desc.unit = "";
|
Chris@140
|
579 desc.hasFixedBinCount = true;
|
Chris@140
|
580 desc.binCount = featureSize;
|
Chris@140
|
581 desc.hasKnownExtents = false;
|
Chris@140
|
582 desc.isQuantized = false;
|
Chris@140
|
583 desc.sampleType = OutputDescriptor::FixedSampleRate;
|
Chris@140
|
584 desc.sampleRate = outRate;
|
Chris@180
|
585 m_caFeaturesOutNo = int(list.size());
|
Chris@140
|
586 list.push_back(desc);
|
Chris@140
|
587
|
Chris@140
|
588 desc.identifier = "b_cfeatures";
|
Chris@140
|
589 desc.name = "Conditioned B Features";
|
Chris@140
|
590 desc.description = "Spectral features extracted from performance B, after norrmalisation and conditioning";
|
Chris@140
|
591 desc.unit = "";
|
Chris@140
|
592 desc.hasFixedBinCount = true;
|
Chris@140
|
593 desc.binCount = featureSize;
|
Chris@140
|
594 desc.hasKnownExtents = false;
|
Chris@140
|
595 desc.isQuantized = false;
|
Chris@140
|
596 desc.sampleType = OutputDescriptor::FixedSampleRate;
|
Chris@140
|
597 desc.sampleRate = outRate;
|
Chris@180
|
598 m_cbFeaturesOutNo = int(list.size());
|
Chris@140
|
599 list.push_back(desc);
|
Chris@140
|
600
|
Chris@163
|
601 desc.identifier = "overall_cost";
|
Chris@163
|
602 desc.name = "Overall Cost";
|
Chris@163
|
603 desc.description = "Normalised overall path cost for the cheapest path";
|
Chris@163
|
604 desc.unit = "";
|
Chris@163
|
605 desc.hasFixedBinCount = true;
|
Chris@163
|
606 desc.binCount = 1;
|
Chris@163
|
607 desc.hasKnownExtents = false;
|
Chris@163
|
608 desc.isQuantized = false;
|
Chris@163
|
609 desc.sampleType = OutputDescriptor::FixedSampleRate;
|
Chris@163
|
610 desc.sampleRate = 1;
|
Chris@180
|
611 m_overallCostOutNo = int(list.size());
|
Chris@163
|
612 list.push_back(desc);
|
Chris@163
|
613
|
cannam@0
|
614 return list;
|
cannam@0
|
615 }
|
cannam@0
|
616
|
cannam@0
|
617 MatchVampPlugin::FeatureSet
|
cannam@0
|
618 MatchVampPlugin::process(const float *const *inputBuffers,
|
cannam@0
|
619 Vamp::RealTime timestamp)
|
cannam@0
|
620 {
|
cannam@0
|
621 if (m_begin) {
|
cannam@0
|
622 if (!m_locked && m_serialise) {
|
cannam@0
|
623 m_locked = true;
|
cannam@0
|
624 #ifdef _WIN32
|
cannam@0
|
625 WaitForSingleObject(m_serialisingMutex, INFINITE);
|
cannam@0
|
626 #else
|
cannam@0
|
627 pthread_mutex_lock(&m_serialisingMutex);
|
cannam@0
|
628 #endif
|
cannam@0
|
629 }
|
Chris@10
|
630 m_startTime = timestamp;
|
cannam@0
|
631 m_begin = false;
|
cannam@0
|
632 }
|
cannam@0
|
633
|
cannam@0
|
634 // std::cerr << timestamp.toString();
|
cannam@0
|
635
|
Chris@107
|
636 m_pipeline->feedFrequencyDomainAudio(inputBuffers[0], inputBuffers[1]);
|
Chris@74
|
637
|
Chris@140
|
638 FeatureSet returnFeatures;
|
Chris@140
|
639
|
Chris@185
|
640 feature_t f1, f2;
|
Chris@140
|
641 m_pipeline->extractFeatures(f1, f2);
|
Chris@16
|
642
|
Chris@185
|
643 feature_t cf1, cf2;
|
Chris@140
|
644 m_pipeline->extractConditionedFeatures(cf1, cf2);
|
Chris@16
|
645
|
Chris@16
|
646 Feature f;
|
Chris@16
|
647 f.hasTimestamp = false;
|
Chris@16
|
648
|
Chris@74
|
649 f.values.clear();
|
Chris@74
|
650 for (int j = 0; j < (int)f1.size(); ++j) {
|
Chris@74
|
651 f.values.push_back(float(f1[j]));
|
Chris@16
|
652 }
|
Chris@74
|
653 returnFeatures[m_aFeaturesOutNo].push_back(f);
|
Chris@16
|
654
|
Chris@74
|
655 f.values.clear();
|
Chris@74
|
656 for (int j = 0; j < (int)f2.size(); ++j) {
|
Chris@74
|
657 f.values.push_back(float(f2[j]));
|
Chris@16
|
658 }
|
Chris@74
|
659 returnFeatures[m_bFeaturesOutNo].push_back(f);
|
cannam@0
|
660
|
Chris@140
|
661 f.values.clear();
|
Chris@140
|
662 for (int j = 0; j < (int)cf1.size(); ++j) {
|
Chris@140
|
663 f.values.push_back(float(cf1[j]));
|
Chris@140
|
664 }
|
Chris@140
|
665 returnFeatures[m_caFeaturesOutNo].push_back(f);
|
Chris@140
|
666
|
Chris@140
|
667 f.values.clear();
|
Chris@140
|
668 for (int j = 0; j < (int)cf2.size(); ++j) {
|
Chris@140
|
669 f.values.push_back(float(cf2[j]));
|
Chris@140
|
670 }
|
Chris@140
|
671 returnFeatures[m_cbFeaturesOutNo].push_back(f);
|
Chris@140
|
672
|
cannam@0
|
673 // std::cerr << ".";
|
cannam@0
|
674 // std::cerr << std::endl;
|
cannam@0
|
675
|
Chris@74
|
676 ++m_frameNo;
|
Chris@74
|
677
|
Chris@16
|
678 return returnFeatures;
|
cannam@0
|
679 }
|
cannam@0
|
680
|
cannam@0
|
681 MatchVampPlugin::FeatureSet
|
cannam@0
|
682 MatchVampPlugin::getRemainingFeatures()
|
cannam@0
|
683 {
|
Chris@107
|
684 m_pipeline->finish();
|
Chris@74
|
685
|
Chris@63
|
686 FeatureSet returnFeatures;
|
Chris@63
|
687
|
cannam@0
|
688 std::vector<int> pathx;
|
cannam@0
|
689 std::vector<int> pathy;
|
Chris@155
|
690 int len = m_pipeline->retrievePath(m_smooth, pathx, pathy);
|
cannam@0
|
691
|
Chris@173
|
692 double cost = m_pipeline->getOverallCost();
|
Chris@163
|
693 Feature costFeature;
|
Chris@163
|
694 costFeature.hasTimestamp = false;
|
Chris@163
|
695 costFeature.values.push_back((float)cost);
|
Chris@163
|
696 returnFeatures[m_overallCostOutNo].push_back(costFeature);
|
Chris@163
|
697
|
cannam@0
|
698 int prevx = 0;
|
cannam@0
|
699 int prevy = 0;
|
cannam@0
|
700
|
Chris@30
|
701 for (int i = 0; i < len; ++i) {
|
cannam@0
|
702
|
cannam@0
|
703 int x = pathx[i];
|
cannam@0
|
704 int y = pathy[i];
|
cannam@0
|
705
|
cannam@0
|
706 Vamp::RealTime xt = Vamp::RealTime::frame2RealTime
|
Chris@180
|
707 (x * m_stepSize, int(m_inputSampleRate + 0.5));
|
cannam@0
|
708 Vamp::RealTime yt = Vamp::RealTime::frame2RealTime
|
Chris@180
|
709 (y * m_stepSize, int(m_inputSampleRate + 0.5));
|
cannam@0
|
710
|
cannam@0
|
711 Feature feature;
|
cannam@0
|
712 feature.hasTimestamp = true;
|
Chris@10
|
713 feature.timestamp = m_startTime + xt;
|
cannam@0
|
714 feature.values.clear();
|
Chris@52
|
715 feature.values.push_back(float(yt.sec + double(yt.nsec)/1.0e9));
|
Chris@16
|
716 returnFeatures[m_pathOutNo].push_back(feature);
|
cannam@0
|
717
|
cannam@0
|
718 if (x != prevx) {
|
cannam@0
|
719
|
cannam@0
|
720 feature.hasTimestamp = true;
|
Chris@10
|
721 feature.timestamp = m_startTime + xt;
|
cannam@0
|
722 feature.values.clear();
|
Chris@52
|
723 feature.values.push_back(float(yt.sec + yt.msec()/1000.0));
|
Chris@16
|
724 returnFeatures[m_abOutNo].push_back(feature);
|
cannam@0
|
725
|
cannam@0
|
726 Vamp::RealTime diff = yt - xt;
|
cannam@0
|
727 feature.values.clear();
|
Chris@52
|
728 feature.values.push_back(float(diff.sec + diff.msec()/1000.0));
|
Chris@16
|
729 returnFeatures[m_abDivOutNo].push_back(feature);
|
cannam@0
|
730
|
cannam@0
|
731 if (i > 0) {
|
cannam@0
|
732 int lookback = 100; //!!! arbitrary
|
cannam@0
|
733 if (lookback > i) lookback = i;
|
cannam@0
|
734 int xdiff = x - pathx[i-lookback];
|
cannam@0
|
735 int ydiff = y - pathy[i-lookback];
|
cannam@0
|
736 if (xdiff != 0 && ydiff != 0) {
|
cannam@0
|
737 float ratio = float(ydiff)/float(xdiff);
|
cannam@0
|
738 if (ratio < 8 && ratio > (1.0/8)) { //!!! just for now, since we aren't dealing properly with silence yet
|
cannam@0
|
739 feature.values.clear();
|
cannam@0
|
740 feature.values.push_back(ratio);
|
Chris@16
|
741 returnFeatures[m_abRatioOutNo].push_back(feature);
|
cannam@0
|
742 }
|
cannam@0
|
743 }
|
cannam@0
|
744 }
|
cannam@0
|
745 }
|
cannam@0
|
746
|
cannam@0
|
747 if (y != prevy) {
|
cannam@0
|
748 feature.hasTimestamp = true;
|
Chris@10
|
749 feature.timestamp = m_startTime + yt;
|
cannam@0
|
750 feature.values.clear();
|
Chris@52
|
751 feature.values.push_back(float(xt.sec + xt.msec()/1000.0));
|
Chris@16
|
752 returnFeatures[m_baOutNo].push_back(feature);
|
cannam@0
|
753 }
|
cannam@0
|
754
|
cannam@0
|
755 prevx = x;
|
cannam@0
|
756 prevy = y;
|
cannam@0
|
757 }
|
cannam@0
|
758
|
Chris@107
|
759 delete m_pipeline;
|
Chris@107
|
760 m_pipeline = 0;
|
cannam@0
|
761
|
cannam@0
|
762 if (m_locked) {
|
cannam@0
|
763 #ifdef _WIN32
|
cannam@0
|
764 ReleaseMutex(m_serialisingMutex);
|
cannam@0
|
765 #else
|
cannam@0
|
766 pthread_mutex_unlock(&m_serialisingMutex);
|
cannam@0
|
767 #endif
|
cannam@0
|
768 m_locked = false;
|
cannam@0
|
769 }
|
cannam@0
|
770
|
cannam@0
|
771 return returnFeatures;
|
cannam@0
|
772
|
cannam@0
|
773
|
cannam@0
|
774 /*
|
Chris@30
|
775 for (int i = 0; i < len; ++i) {
|
cannam@0
|
776 std::cerr << i << ": [" << pathx[i] << "," << pathy[i] << "]" << std::endl;
|
cannam@0
|
777 }
|
cannam@0
|
778
|
cannam@0
|
779 std::cerr << std::endl;
|
cannam@0
|
780 std::cerr << "File: A" << std::endl;
|
cannam@0
|
781 std::cerr << "Marks: -1" << std::endl;
|
cannam@0
|
782 std::cerr << "FixedPoints: true 0" << std::endl;
|
cannam@0
|
783 std::cerr << "0" << std::endl;
|
cannam@0
|
784 std::cerr << "0" << std::endl;
|
cannam@0
|
785 std::cerr << "0" << std::endl;
|
cannam@0
|
786 std::cerr << "0" << std::endl;
|
cannam@0
|
787 std::cerr << "File: B" << std::endl;
|
cannam@0
|
788 std::cerr << "Marks: 0" << std::endl;
|
cannam@0
|
789 std::cerr << "FixedPoints: true 0" << std::endl;
|
cannam@0
|
790 std::cerr << "0.02" << std::endl;
|
cannam@0
|
791 std::cerr << "0.02" << std::endl;
|
cannam@0
|
792
|
Chris@30
|
793 std::cerr << len << std::endl;
|
Chris@30
|
794 for (int i = 0; i < len; ++i) {
|
cannam@0
|
795 std::cerr << pathx[i] << std::endl;
|
cannam@0
|
796 }
|
cannam@0
|
797
|
Chris@30
|
798 std::cerr << len << std::endl;
|
Chris@30
|
799 for (int i = 0; i < len; ++i) {
|
cannam@0
|
800 std::cerr << pathy[i] << std::endl;
|
cannam@0
|
801 }
|
cannam@0
|
802 */
|
cannam@0
|
803 }
|
cannam@0
|
804
|
cannam@0
|
805 static Vamp::PluginAdapter<MatchVampPlugin> mvpAdapter;
|
cannam@0
|
806
|
cannam@0
|
807 const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int version,
|
cannam@0
|
808 unsigned int index)
|
cannam@0
|
809 {
|
cannam@0
|
810 if (version < 1) return 0;
|
cannam@0
|
811
|
cannam@0
|
812 switch (index) {
|
cannam@0
|
813 case 0: return mvpAdapter.getDescriptor();
|
cannam@0
|
814 default: return 0;
|
cannam@0
|
815 }
|
cannam@0
|
816 }
|