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@162
|
170 desc.unit = "";
|
Chris@162
|
171
|
Chris@162
|
172 desc.identifier = "usechroma";
|
Chris@162
|
173 desc.name = "Feature type";
|
Chris@162
|
174 desc.description = "Whether to use warped spectrogram or chroma frequency map";
|
cannam@0
|
175 desc.minValue = 0;
|
cannam@0
|
176 desc.maxValue = 1;
|
Chris@162
|
177 desc.defaultValue = m_defaultFeParams.useChromaFrequencyMap ? 1 : 0;
|
Chris@162
|
178 desc.isQuantized = true;
|
Chris@162
|
179 desc.quantizeStep = 1;
|
Chris@162
|
180 desc.valueNames.clear();
|
Chris@162
|
181 desc.valueNames.push_back("Spectral");
|
Chris@162
|
182 desc.valueNames.push_back("Chroma");
|
Chris@162
|
183 list.push_back(desc);
|
Chris@162
|
184
|
Chris@162
|
185 desc.valueNames.clear();
|
Chris@162
|
186
|
Chris@162
|
187 desc.identifier = "usespecdiff";
|
Chris@162
|
188 desc.name = "Use feature difference";
|
Chris@162
|
189 desc.description = "Whether to use half-wave rectified feature-to-feature difference instead of straight spectral or chroma feature";
|
Chris@162
|
190 desc.minValue = 0;
|
Chris@162
|
191 desc.maxValue = 1;
|
Chris@162
|
192 desc.defaultValue = (int)m_defaultFcParams.order;
|
cannam@0
|
193 desc.isQuantized = true;
|
cannam@0
|
194 desc.quantizeStep = 1;
|
cannam@0
|
195 list.push_back(desc);
|
cannam@0
|
196
|
Chris@18
|
197 desc.identifier = "framenorm";
|
Chris@162
|
198 desc.name = "Frame normalisation";
|
Chris@162
|
199 desc.description = "Type of normalisation to use for features";
|
Chris@18
|
200 desc.minValue = 0;
|
Chris@18
|
201 desc.maxValue = 2;
|
Chris@103
|
202 desc.defaultValue = (int)m_defaultFcParams.norm;
|
Chris@18
|
203 desc.isQuantized = true;
|
Chris@18
|
204 desc.quantizeStep = 1;
|
Chris@18
|
205 desc.valueNames.clear();
|
Chris@18
|
206 desc.valueNames.push_back("None");
|
Chris@162
|
207 desc.valueNames.push_back("Sum to 1");
|
Chris@162
|
208 desc.valueNames.push_back("Long-term average");
|
Chris@18
|
209 list.push_back(desc);
|
Chris@18
|
210 desc.valueNames.clear();
|
Chris@148
|
211 desc.defaultValue = (float)m_defaultFcParams.silenceThreshold;
|
Chris@151
|
212
|
Chris@156
|
213 desc.identifier = "metric";
|
Chris@156
|
214 desc.name = "Distance metric";
|
Chris@156
|
215 desc.description = "Metric for distance calculations.";
|
Chris@156
|
216 desc.minValue = 0;
|
Chris@157
|
217 desc.maxValue = 2;
|
Chris@156
|
218 desc.defaultValue = (int)m_defaultDParams.metric;
|
Chris@156
|
219 desc.isQuantized = true;
|
Chris@156
|
220 desc.quantizeStep = 1;
|
Chris@156
|
221 desc.valueNames.clear();
|
Chris@157
|
222 desc.valueNames.push_back("Manhattan");
|
Chris@156
|
223 desc.valueNames.push_back("Euclidean");
|
Chris@156
|
224 desc.valueNames.push_back("Cosine");
|
Chris@156
|
225 list.push_back(desc);
|
Chris@156
|
226 desc.valueNames.clear();
|
Chris@156
|
227
|
Chris@162
|
228 desc.identifier = "distnorm";
|
Chris@162
|
229 desc.name = "Distance normalisation";
|
Chris@162
|
230 desc.description = "Type of normalisation to use for distance metric";
|
Chris@162
|
231 desc.minValue = 0;
|
Chris@162
|
232 desc.maxValue = 2;
|
Chris@162
|
233 desc.defaultValue = (int)m_defaultDParams.norm;
|
Chris@162
|
234 desc.isQuantized = true;
|
Chris@162
|
235 desc.quantizeStep = 1;
|
Chris@162
|
236 desc.valueNames.clear();
|
Chris@162
|
237 desc.valueNames.push_back("None");
|
Chris@162
|
238 desc.valueNames.push_back("Sum of frames");
|
Chris@162
|
239 desc.valueNames.push_back("Log sum of frames");
|
Chris@162
|
240 list.push_back(desc);
|
Chris@162
|
241 desc.valueNames.clear();
|
Chris@162
|
242
|
Chris@162
|
243 desc.identifier = "silencethreshold";
|
Chris@162
|
244 desc.name = "Silence threshold";
|
Chris@162
|
245 desc.description = "Total frame energy threshold below which a feature will be regarded as silent";
|
Chris@162
|
246 desc.minValue = 0;
|
Chris@165
|
247 desc.maxValue = 0.1f;
|
Chris@165
|
248 desc.defaultValue = (float)m_defaultFcParams.silenceThreshold;
|
Chris@162
|
249 desc.isQuantized = false;
|
Chris@162
|
250 list.push_back(desc);
|
Chris@162
|
251
|
Chris@151
|
252 desc.identifier = "noise";
|
Chris@162
|
253 desc.name = "Add noise";
|
Chris@151
|
254 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
|
255 desc.minValue = 0;
|
Chris@151
|
256 desc.maxValue = 1;
|
Chris@151
|
257 desc.defaultValue = (int)m_defaultDParams.noise;
|
Chris@151
|
258 desc.isQuantized = true;
|
Chris@151
|
259 desc.quantizeStep = 1;
|
Chris@151
|
260 list.push_back(desc);
|
Chris@136
|
261
|
Chris@25
|
262 desc.identifier = "gradientlimit";
|
Chris@162
|
263 desc.name = "Gradient limit";
|
Chris@18
|
264 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
|
265 desc.minValue = 1;
|
Chris@18
|
266 desc.maxValue = 10;
|
Chris@18
|
267 desc.defaultValue = m_defaultParams.maxRunCount;
|
Chris@18
|
268 desc.isQuantized = true;
|
Chris@18
|
269 desc.quantizeStep = 1;
|
Chris@18
|
270 list.push_back(desc);
|
Chris@18
|
271
|
Chris@25
|
272 desc.identifier = "zonewidth";
|
Chris@162
|
273 desc.name = "Search zone width";
|
Chris@25
|
274 desc.description = "Width of the search zone (error margin) either side of the ongoing match position, in seconds";
|
Chris@25
|
275 desc.minValue = 1;
|
Chris@25
|
276 desc.maxValue = 60;
|
Chris@52
|
277 desc.defaultValue = (float)m_defaultParams.blockTime;
|
Chris@25
|
278 desc.isQuantized = true;
|
Chris@25
|
279 desc.quantizeStep = 1;
|
Chris@25
|
280 desc.unit = "s";
|
Chris@25
|
281 list.push_back(desc);
|
Chris@25
|
282
|
Chris@83
|
283 desc.identifier = "diagonalweight";
|
Chris@162
|
284 desc.name = "Diagonal weight";
|
Chris@83
|
285 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
|
286 desc.minValue = 1.0;
|
Chris@86
|
287 desc.maxValue = 2.0;
|
Chris@138
|
288 desc.defaultValue = (float)m_defaultParams.diagonalWeight;
|
Chris@83
|
289 desc.isQuantized = false;
|
Chris@83
|
290 desc.unit = "";
|
Chris@83
|
291 list.push_back(desc);
|
Chris@83
|
292
|
Chris@32
|
293 desc.identifier = "smooth";
|
Chris@162
|
294 desc.name = "Use path smoothing";
|
Chris@138
|
295 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
|
296 desc.minValue = 0;
|
Chris@32
|
297 desc.maxValue = 1;
|
Chris@138
|
298 desc.defaultValue = 0;
|
Chris@32
|
299 desc.isQuantized = true;
|
Chris@32
|
300 desc.quantizeStep = 1;
|
Chris@32
|
301 desc.unit = "";
|
Chris@32
|
302 list.push_back(desc);
|
Chris@32
|
303
|
Chris@162
|
304 desc.identifier = "serialise";
|
Chris@162
|
305 desc.name = "Serialise plugin invocations";
|
Chris@162
|
306 desc.description = "Reduce potential memory load at the expense of multiprocessor performance by serialising multi-threaded plugin runs";
|
Chris@162
|
307 desc.minValue = 0;
|
Chris@162
|
308 desc.maxValue = 1;
|
Chris@162
|
309 desc.defaultValue = 0;
|
Chris@162
|
310 desc.isQuantized = true;
|
Chris@162
|
311 desc.quantizeStep = 1;
|
Chris@161
|
312 list.push_back(desc);
|
Chris@161
|
313
|
cannam@0
|
314 return list;
|
cannam@0
|
315 }
|
cannam@0
|
316
|
cannam@0
|
317 float
|
cannam@0
|
318 MatchVampPlugin::getParameter(std::string name) const
|
cannam@0
|
319 {
|
cannam@0
|
320 if (name == "serialise") {
|
cannam@0
|
321 return m_serialise ? 1.0 : 0.0;
|
Chris@18
|
322 } else if (name == "framenorm") {
|
Chris@103
|
323 return (int)m_fcParams.norm;
|
Chris@18
|
324 } else if (name == "distnorm") {
|
Chris@143
|
325 return (int)m_dParams.norm;
|
Chris@18
|
326 } else if (name == "usespecdiff") {
|
Chris@103
|
327 return (int)m_fcParams.order;
|
Chris@18
|
328 } else if (name == "usechroma") {
|
Chris@38
|
329 return m_feParams.useChromaFrequencyMap ? 1.0 : 0.0;
|
Chris@25
|
330 } else if (name == "gradientlimit") {
|
Chris@18
|
331 return m_params.maxRunCount;
|
Chris@83
|
332 } else if (name == "diagonalweight") {
|
Chris@83
|
333 return m_params.diagonalWeight;
|
Chris@25
|
334 } else if (name == "zonewidth") {
|
Chris@52
|
335 return (float)m_params.blockTime;
|
Chris@32
|
336 } else if (name == "smooth") {
|
Chris@32
|
337 return m_smooth ? 1.0 : 0.0;
|
Chris@136
|
338 } else if (name == "silencethreshold") {
|
Chris@148
|
339 return (float)m_fcParams.silenceThreshold;
|
Chris@156
|
340 } else if (name == "metric") {
|
Chris@156
|
341 return (int)m_dParams.metric;
|
Chris@151
|
342 } else if (name == "noise") {
|
Chris@151
|
343 return m_dParams.noise;
|
Chris@161
|
344 } else if (name == "freq1") {
|
Chris@161
|
345 return (float)m_feParams.referenceFrequency;
|
Chris@161
|
346 } else if (name == "freq2") {
|
Chris@161
|
347 return (float)m_secondReferenceFrequency;
|
cannam@0
|
348 }
|
Chris@18
|
349
|
cannam@0
|
350 return 0.0;
|
cannam@0
|
351 }
|
cannam@0
|
352
|
cannam@0
|
353 void
|
cannam@0
|
354 MatchVampPlugin::setParameter(std::string name, float value)
|
cannam@0
|
355 {
|
cannam@0
|
356 if (name == "serialise") {
|
cannam@0
|
357 m_serialise = (value > 0.5);
|
Chris@18
|
358 } else if (name == "framenorm") {
|
Chris@103
|
359 m_fcParams.norm = (FeatureConditioner::Normalisation)(int(value + 0.1));
|
Chris@18
|
360 } else if (name == "distnorm") {
|
Chris@143
|
361 m_dParams.norm = (DistanceMetric::DistanceNormalisation)(int(value + 0.1));
|
Chris@18
|
362 } else if (name == "usespecdiff") {
|
Chris@103
|
363 m_fcParams.order = (FeatureConditioner::OutputOrder)(int(value + 0.1));
|
Chris@18
|
364 } else if (name == "usechroma") {
|
Chris@38
|
365 m_feParams.useChromaFrequencyMap = (value > 0.5);
|
Chris@25
|
366 } else if (name == "gradientlimit") {
|
Chris@18
|
367 m_params.maxRunCount = int(value + 0.1);
|
Chris@83
|
368 } else if (name == "diagonalweight") {
|
Chris@83
|
369 m_params.diagonalWeight = value;
|
Chris@25
|
370 } else if (name == "zonewidth") {
|
Chris@25
|
371 m_params.blockTime = value;
|
Chris@32
|
372 } else if (name == "smooth") {
|
Chris@32
|
373 m_smooth = (value > 0.5);
|
Chris@136
|
374 } else if (name == "silencethreshold") {
|
Chris@136
|
375 m_fcParams.silenceThreshold = value;
|
Chris@156
|
376 } else if (name == "metric") {
|
Chris@156
|
377 m_dParams.metric = (DistanceMetric::Metric)(int(value + 0.1));
|
Chris@151
|
378 } else if (name == "noise") {
|
Chris@151
|
379 m_dParams.noise = (DistanceMetric::NoiseAddition)(int(value + 0.1));
|
Chris@161
|
380 } else if (name == "freq1") {
|
Chris@161
|
381 m_feParams.referenceFrequency = value;
|
Chris@161
|
382 } else if (name == "freq2") {
|
Chris@161
|
383 m_secondReferenceFrequency = value;
|
cannam@0
|
384 }
|
cannam@0
|
385 }
|
cannam@0
|
386
|
cannam@0
|
387 size_t
|
cannam@0
|
388 MatchVampPlugin::getPreferredStepSize() const
|
cannam@0
|
389 {
|
Chris@52
|
390 return int(m_inputSampleRate * defaultStepTime + 0.001);
|
cannam@0
|
391 }
|
cannam@0
|
392
|
cannam@0
|
393 size_t
|
cannam@0
|
394 MatchVampPlugin::getPreferredBlockSize() const
|
cannam@0
|
395 {
|
Chris@15
|
396 return 2048;
|
cannam@0
|
397 }
|
cannam@0
|
398
|
cannam@0
|
399 void
|
Chris@17
|
400 MatchVampPlugin::createMatchers()
|
cannam@0
|
401 {
|
Chris@17
|
402 m_params.hopTime = m_stepTime;
|
Chris@38
|
403 m_feParams.fftSize = m_blockSize;
|
Chris@107
|
404
|
Chris@163
|
405 cerr << "creating pipeline with m_secondReferenceFrequency = "
|
Chris@163
|
406 << m_secondReferenceFrequency << endl;
|
Chris@161
|
407 m_pipeline = new MatchPipeline(m_feParams, m_fcParams, m_dParams, m_params,
|
Chris@161
|
408 m_secondReferenceFrequency);
|
Chris@163
|
409 cerr << "done" << endl;
|
cannam@0
|
410 }
|
cannam@0
|
411
|
cannam@0
|
412 bool
|
cannam@0
|
413 MatchVampPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
cannam@0
|
414 {
|
Chris@10
|
415 if (m_inputSampleRate < sampleRateMin) {
|
Chris@10
|
416 std::cerr << "MatchVampPlugin::MatchVampPlugin: input sample rate "
|
Chris@10
|
417 << m_inputSampleRate << " < min supported rate "
|
Chris@10
|
418 << sampleRateMin << std::endl;
|
Chris@10
|
419 return false;
|
Chris@10
|
420 }
|
cannam@0
|
421 if (channels < getMinChannelCount() ||
|
cannam@0
|
422 channels > getMaxChannelCount()) return false;
|
cannam@1
|
423 if (stepSize > blockSize/2 ||
|
cannam@0
|
424 blockSize != getPreferredBlockSize()) return false;
|
Chris@15
|
425
|
cannam@6
|
426 m_stepSize = stepSize;
|
Chris@15
|
427 m_stepTime = float(stepSize) / m_inputSampleRate;
|
Chris@15
|
428 m_blockSize = blockSize;
|
Chris@15
|
429
|
Chris@15
|
430 createMatchers();
|
cannam@0
|
431 m_begin = true;
|
cannam@0
|
432 m_locked = false;
|
Chris@15
|
433
|
cannam@0
|
434 return true;
|
cannam@0
|
435 }
|
cannam@0
|
436
|
cannam@0
|
437 void
|
cannam@0
|
438 MatchVampPlugin::reset()
|
cannam@0
|
439 {
|
Chris@107
|
440 delete m_pipeline;
|
Chris@107
|
441 m_pipeline = 0;
|
Chris@74
|
442 m_frameNo = 0;
|
cannam@6
|
443 createMatchers();
|
cannam@6
|
444 m_begin = true;
|
cannam@6
|
445 m_locked = false;
|
cannam@0
|
446 }
|
cannam@0
|
447
|
cannam@0
|
448 MatchVampPlugin::OutputList
|
cannam@0
|
449 MatchVampPlugin::getOutputDescriptors() const
|
cannam@0
|
450 {
|
cannam@0
|
451 OutputList list;
|
cannam@0
|
452
|
Chris@52
|
453 float outRate = 1.0f / m_stepTime;
|
cannam@0
|
454
|
cannam@0
|
455 OutputDescriptor desc;
|
cannam@0
|
456 desc.identifier = "path";
|
cannam@0
|
457 desc.name = "Path";
|
cannam@0
|
458 desc.description = "Alignment path";
|
cannam@0
|
459 desc.unit = "";
|
cannam@0
|
460 desc.hasFixedBinCount = true;
|
cannam@0
|
461 desc.binCount = 1;
|
cannam@0
|
462 desc.hasKnownExtents = false;
|
cannam@0
|
463 desc.isQuantized = true;
|
cannam@0
|
464 desc.quantizeStep = 1;
|
cannam@0
|
465 desc.sampleType = OutputDescriptor::VariableSampleRate;
|
cannam@0
|
466 desc.sampleRate = outRate;
|
Chris@16
|
467 m_pathOutNo = list.size();
|
cannam@0
|
468 list.push_back(desc);
|
cannam@0
|
469
|
cannam@0
|
470 desc.identifier = "a_b";
|
cannam@0
|
471 desc.name = "A-B Timeline";
|
cannam@0
|
472 desc.description = "Timing in performance B corresponding to moments in performance A";
|
cannam@0
|
473 desc.unit = "sec";
|
cannam@0
|
474 desc.hasFixedBinCount = true;
|
cannam@0
|
475 desc.binCount = 1;
|
cannam@0
|
476 desc.hasKnownExtents = false;
|
cannam@0
|
477 desc.isQuantized = false;
|
cannam@0
|
478 desc.sampleType = OutputDescriptor::VariableSampleRate;
|
cannam@0
|
479 desc.sampleRate = outRate;
|
Chris@16
|
480 m_abOutNo = list.size();
|
cannam@0
|
481 list.push_back(desc);
|
cannam@0
|
482
|
cannam@0
|
483 desc.identifier = "b_a";
|
cannam@0
|
484 desc.name = "B-A Timeline";
|
cannam@0
|
485 desc.description = "Timing in performance A corresponding to moments in performance B";
|
cannam@0
|
486 desc.unit = "sec";
|
cannam@0
|
487 desc.hasFixedBinCount = true;
|
cannam@0
|
488 desc.binCount = 1;
|
cannam@0
|
489 desc.hasKnownExtents = false;
|
cannam@0
|
490 desc.isQuantized = false;
|
cannam@0
|
491 desc.sampleType = OutputDescriptor::VariableSampleRate;
|
cannam@0
|
492 desc.sampleRate = outRate;
|
Chris@16
|
493 m_baOutNo = list.size();
|
cannam@0
|
494 list.push_back(desc);
|
cannam@0
|
495
|
cannam@0
|
496 desc.identifier = "a_b_divergence";
|
cannam@0
|
497 desc.name = "A-B Divergence";
|
cannam@0
|
498 desc.description = "Difference between timings in performances A and B";
|
cannam@0
|
499 desc.unit = "sec";
|
cannam@0
|
500 desc.hasFixedBinCount = true;
|
cannam@0
|
501 desc.binCount = 1;
|
cannam@0
|
502 desc.hasKnownExtents = false;
|
cannam@0
|
503 desc.isQuantized = false;
|
cannam@0
|
504 desc.sampleType = OutputDescriptor::VariableSampleRate;
|
cannam@0
|
505 desc.sampleRate = outRate;
|
Chris@16
|
506 m_abDivOutNo = list.size();
|
cannam@0
|
507 list.push_back(desc);
|
cannam@0
|
508
|
cannam@0
|
509 desc.identifier = "a_b_temporatio";
|
cannam@0
|
510 desc.name = "A-B Tempo Ratio";
|
cannam@0
|
511 desc.description = "Ratio of tempi between performances A and B";
|
cannam@0
|
512 desc.unit = "";
|
cannam@0
|
513 desc.hasFixedBinCount = true;
|
cannam@0
|
514 desc.binCount = 1;
|
cannam@0
|
515 desc.hasKnownExtents = false;
|
cannam@0
|
516 desc.isQuantized = false;
|
cannam@0
|
517 desc.sampleType = OutputDescriptor::VariableSampleRate;
|
cannam@0
|
518 desc.sampleRate = outRate;
|
Chris@16
|
519 m_abRatioOutNo = list.size();
|
cannam@0
|
520 list.push_back(desc);
|
cannam@0
|
521
|
Chris@38
|
522 int featureSize = FeatureExtractor(m_feParams).getFeatureSize();
|
Chris@38
|
523
|
Chris@15
|
524 desc.identifier = "a_features";
|
Chris@140
|
525 desc.name = "Raw A Features";
|
Chris@15
|
526 desc.description = "Spectral features extracted from performance A";
|
Chris@15
|
527 desc.unit = "";
|
Chris@15
|
528 desc.hasFixedBinCount = true;
|
Chris@38
|
529 desc.binCount = featureSize;
|
Chris@15
|
530 desc.hasKnownExtents = false;
|
Chris@15
|
531 desc.isQuantized = false;
|
Chris@16
|
532 desc.sampleType = OutputDescriptor::FixedSampleRate;
|
Chris@15
|
533 desc.sampleRate = outRate;
|
Chris@16
|
534 m_aFeaturesOutNo = list.size();
|
Chris@16
|
535 list.push_back(desc);
|
Chris@16
|
536
|
Chris@16
|
537 desc.identifier = "b_features";
|
Chris@140
|
538 desc.name = "Raw B Features";
|
Chris@16
|
539 desc.description = "Spectral features extracted from performance B";
|
Chris@16
|
540 desc.unit = "";
|
Chris@16
|
541 desc.hasFixedBinCount = true;
|
Chris@38
|
542 desc.binCount = featureSize;
|
Chris@16
|
543 desc.hasKnownExtents = false;
|
Chris@16
|
544 desc.isQuantized = false;
|
Chris@16
|
545 desc.sampleType = OutputDescriptor::FixedSampleRate;
|
Chris@16
|
546 desc.sampleRate = outRate;
|
Chris@16
|
547 m_bFeaturesOutNo = list.size();
|
Chris@15
|
548 list.push_back(desc);
|
Chris@15
|
549
|
Chris@140
|
550 desc.identifier = "a_cfeatures";
|
Chris@140
|
551 desc.name = "Conditioned A Features";
|
Chris@140
|
552 desc.description = "Spectral features extracted from performance A, after normalisation and conditioning";
|
Chris@140
|
553 desc.unit = "";
|
Chris@140
|
554 desc.hasFixedBinCount = true;
|
Chris@140
|
555 desc.binCount = featureSize;
|
Chris@140
|
556 desc.hasKnownExtents = false;
|
Chris@140
|
557 desc.isQuantized = false;
|
Chris@140
|
558 desc.sampleType = OutputDescriptor::FixedSampleRate;
|
Chris@140
|
559 desc.sampleRate = outRate;
|
Chris@140
|
560 m_caFeaturesOutNo = list.size();
|
Chris@140
|
561 list.push_back(desc);
|
Chris@140
|
562
|
Chris@140
|
563 desc.identifier = "b_cfeatures";
|
Chris@140
|
564 desc.name = "Conditioned B Features";
|
Chris@140
|
565 desc.description = "Spectral features extracted from performance B, after norrmalisation and conditioning";
|
Chris@140
|
566 desc.unit = "";
|
Chris@140
|
567 desc.hasFixedBinCount = true;
|
Chris@140
|
568 desc.binCount = featureSize;
|
Chris@140
|
569 desc.hasKnownExtents = false;
|
Chris@140
|
570 desc.isQuantized = false;
|
Chris@140
|
571 desc.sampleType = OutputDescriptor::FixedSampleRate;
|
Chris@140
|
572 desc.sampleRate = outRate;
|
Chris@140
|
573 m_cbFeaturesOutNo = list.size();
|
Chris@140
|
574 list.push_back(desc);
|
Chris@140
|
575
|
Chris@163
|
576 desc.identifier = "overall_cost";
|
Chris@163
|
577 desc.name = "Overall Cost";
|
Chris@163
|
578 desc.description = "Normalised overall path cost for the cheapest path";
|
Chris@163
|
579 desc.unit = "";
|
Chris@163
|
580 desc.hasFixedBinCount = true;
|
Chris@163
|
581 desc.binCount = 1;
|
Chris@163
|
582 desc.hasKnownExtents = false;
|
Chris@163
|
583 desc.isQuantized = false;
|
Chris@163
|
584 desc.sampleType = OutputDescriptor::FixedSampleRate;
|
Chris@163
|
585 desc.sampleRate = 1;
|
Chris@163
|
586 m_overallCostOutNo = list.size();
|
Chris@163
|
587 list.push_back(desc);
|
Chris@163
|
588
|
cannam@0
|
589 return list;
|
cannam@0
|
590 }
|
cannam@0
|
591
|
cannam@0
|
592 MatchVampPlugin::FeatureSet
|
cannam@0
|
593 MatchVampPlugin::process(const float *const *inputBuffers,
|
cannam@0
|
594 Vamp::RealTime timestamp)
|
cannam@0
|
595 {
|
cannam@0
|
596 if (m_begin) {
|
cannam@0
|
597 if (!m_locked && m_serialise) {
|
cannam@0
|
598 m_locked = true;
|
cannam@0
|
599 #ifdef _WIN32
|
cannam@0
|
600 WaitForSingleObject(m_serialisingMutex, INFINITE);
|
cannam@0
|
601 #else
|
cannam@0
|
602 pthread_mutex_lock(&m_serialisingMutex);
|
cannam@0
|
603 #endif
|
cannam@0
|
604 }
|
Chris@10
|
605 m_startTime = timestamp;
|
cannam@0
|
606 m_begin = false;
|
cannam@0
|
607 }
|
cannam@0
|
608
|
cannam@0
|
609 // std::cerr << timestamp.toString();
|
cannam@0
|
610
|
Chris@107
|
611 m_pipeline->feedFrequencyDomainAudio(inputBuffers[0], inputBuffers[1]);
|
Chris@74
|
612
|
Chris@140
|
613 FeatureSet returnFeatures;
|
Chris@140
|
614
|
Chris@107
|
615 vector<double> f1, f2;
|
Chris@140
|
616 m_pipeline->extractFeatures(f1, f2);
|
Chris@16
|
617
|
Chris@140
|
618 vector<double> cf1, cf2;
|
Chris@140
|
619 m_pipeline->extractConditionedFeatures(cf1, cf2);
|
Chris@16
|
620
|
Chris@16
|
621 Feature f;
|
Chris@16
|
622 f.hasTimestamp = false;
|
Chris@16
|
623
|
Chris@74
|
624 f.values.clear();
|
Chris@74
|
625 for (int j = 0; j < (int)f1.size(); ++j) {
|
Chris@74
|
626 f.values.push_back(float(f1[j]));
|
Chris@16
|
627 }
|
Chris@74
|
628 returnFeatures[m_aFeaturesOutNo].push_back(f);
|
Chris@16
|
629
|
Chris@74
|
630 f.values.clear();
|
Chris@74
|
631 for (int j = 0; j < (int)f2.size(); ++j) {
|
Chris@74
|
632 f.values.push_back(float(f2[j]));
|
Chris@16
|
633 }
|
Chris@74
|
634 returnFeatures[m_bFeaturesOutNo].push_back(f);
|
cannam@0
|
635
|
Chris@140
|
636 f.values.clear();
|
Chris@140
|
637 for (int j = 0; j < (int)cf1.size(); ++j) {
|
Chris@140
|
638 f.values.push_back(float(cf1[j]));
|
Chris@140
|
639 }
|
Chris@140
|
640 returnFeatures[m_caFeaturesOutNo].push_back(f);
|
Chris@140
|
641
|
Chris@140
|
642 f.values.clear();
|
Chris@140
|
643 for (int j = 0; j < (int)cf2.size(); ++j) {
|
Chris@140
|
644 f.values.push_back(float(cf2[j]));
|
Chris@140
|
645 }
|
Chris@140
|
646 returnFeatures[m_cbFeaturesOutNo].push_back(f);
|
Chris@140
|
647
|
cannam@0
|
648 // std::cerr << ".";
|
cannam@0
|
649 // std::cerr << std::endl;
|
cannam@0
|
650
|
Chris@74
|
651 ++m_frameNo;
|
Chris@74
|
652
|
Chris@16
|
653 return returnFeatures;
|
cannam@0
|
654 }
|
cannam@0
|
655
|
cannam@0
|
656 MatchVampPlugin::FeatureSet
|
cannam@0
|
657 MatchVampPlugin::getRemainingFeatures()
|
cannam@0
|
658 {
|
Chris@107
|
659 m_pipeline->finish();
|
Chris@74
|
660
|
Chris@63
|
661 FeatureSet returnFeatures;
|
Chris@63
|
662
|
cannam@0
|
663 std::vector<int> pathx;
|
cannam@0
|
664 std::vector<int> pathy;
|
Chris@155
|
665 int len = m_pipeline->retrievePath(m_smooth, pathx, pathy);
|
cannam@0
|
666
|
Chris@173
|
667 double cost = m_pipeline->getOverallCost();
|
Chris@163
|
668 Feature costFeature;
|
Chris@163
|
669 costFeature.hasTimestamp = false;
|
Chris@163
|
670 costFeature.values.push_back((float)cost);
|
Chris@163
|
671 returnFeatures[m_overallCostOutNo].push_back(costFeature);
|
Chris@163
|
672
|
cannam@0
|
673 int prevx = 0;
|
cannam@0
|
674 int prevy = 0;
|
cannam@0
|
675
|
Chris@30
|
676 for (int i = 0; i < len; ++i) {
|
cannam@0
|
677
|
cannam@0
|
678 int x = pathx[i];
|
cannam@0
|
679 int y = pathy[i];
|
cannam@0
|
680
|
cannam@0
|
681 Vamp::RealTime xt = Vamp::RealTime::frame2RealTime
|
Chris@15
|
682 (x * m_stepSize, lrintf(m_inputSampleRate));
|
cannam@0
|
683 Vamp::RealTime yt = Vamp::RealTime::frame2RealTime
|
Chris@15
|
684 (y * m_stepSize, lrintf(m_inputSampleRate));
|
cannam@0
|
685
|
cannam@0
|
686 Feature feature;
|
cannam@0
|
687 feature.hasTimestamp = true;
|
Chris@10
|
688 feature.timestamp = m_startTime + xt;
|
cannam@0
|
689 feature.values.clear();
|
Chris@52
|
690 feature.values.push_back(float(yt.sec + double(yt.nsec)/1.0e9));
|
Chris@16
|
691 returnFeatures[m_pathOutNo].push_back(feature);
|
cannam@0
|
692
|
cannam@0
|
693 if (x != prevx) {
|
cannam@0
|
694
|
cannam@0
|
695 feature.hasTimestamp = true;
|
Chris@10
|
696 feature.timestamp = m_startTime + xt;
|
cannam@0
|
697 feature.values.clear();
|
Chris@52
|
698 feature.values.push_back(float(yt.sec + yt.msec()/1000.0));
|
Chris@16
|
699 returnFeatures[m_abOutNo].push_back(feature);
|
cannam@0
|
700
|
cannam@0
|
701 Vamp::RealTime diff = yt - xt;
|
cannam@0
|
702 feature.values.clear();
|
Chris@52
|
703 feature.values.push_back(float(diff.sec + diff.msec()/1000.0));
|
Chris@16
|
704 returnFeatures[m_abDivOutNo].push_back(feature);
|
cannam@0
|
705
|
cannam@0
|
706 if (i > 0) {
|
cannam@0
|
707 int lookback = 100; //!!! arbitrary
|
cannam@0
|
708 if (lookback > i) lookback = i;
|
cannam@0
|
709 int xdiff = x - pathx[i-lookback];
|
cannam@0
|
710 int ydiff = y - pathy[i-lookback];
|
cannam@0
|
711 if (xdiff != 0 && ydiff != 0) {
|
cannam@0
|
712 float ratio = float(ydiff)/float(xdiff);
|
cannam@0
|
713 if (ratio < 8 && ratio > (1.0/8)) { //!!! just for now, since we aren't dealing properly with silence yet
|
cannam@0
|
714 feature.values.clear();
|
cannam@0
|
715 feature.values.push_back(ratio);
|
Chris@16
|
716 returnFeatures[m_abRatioOutNo].push_back(feature);
|
cannam@0
|
717 }
|
cannam@0
|
718 }
|
cannam@0
|
719 }
|
cannam@0
|
720 }
|
cannam@0
|
721
|
cannam@0
|
722 if (y != prevy) {
|
cannam@0
|
723 feature.hasTimestamp = true;
|
Chris@10
|
724 feature.timestamp = m_startTime + yt;
|
cannam@0
|
725 feature.values.clear();
|
Chris@52
|
726 feature.values.push_back(float(xt.sec + xt.msec()/1000.0));
|
Chris@16
|
727 returnFeatures[m_baOutNo].push_back(feature);
|
cannam@0
|
728 }
|
cannam@0
|
729
|
cannam@0
|
730 prevx = x;
|
cannam@0
|
731 prevy = y;
|
cannam@0
|
732 }
|
cannam@0
|
733
|
Chris@107
|
734 delete m_pipeline;
|
Chris@107
|
735 m_pipeline = 0;
|
cannam@0
|
736
|
cannam@0
|
737 if (m_locked) {
|
cannam@0
|
738 #ifdef _WIN32
|
cannam@0
|
739 ReleaseMutex(m_serialisingMutex);
|
cannam@0
|
740 #else
|
cannam@0
|
741 pthread_mutex_unlock(&m_serialisingMutex);
|
cannam@0
|
742 #endif
|
cannam@0
|
743 m_locked = false;
|
cannam@0
|
744 }
|
cannam@0
|
745
|
cannam@0
|
746 return returnFeatures;
|
cannam@0
|
747
|
cannam@0
|
748
|
cannam@0
|
749 /*
|
Chris@30
|
750 for (int i = 0; i < len; ++i) {
|
cannam@0
|
751 std::cerr << i << ": [" << pathx[i] << "," << pathy[i] << "]" << std::endl;
|
cannam@0
|
752 }
|
cannam@0
|
753
|
cannam@0
|
754 std::cerr << std::endl;
|
cannam@0
|
755 std::cerr << "File: A" << std::endl;
|
cannam@0
|
756 std::cerr << "Marks: -1" << std::endl;
|
cannam@0
|
757 std::cerr << "FixedPoints: true 0" << std::endl;
|
cannam@0
|
758 std::cerr << "0" << std::endl;
|
cannam@0
|
759 std::cerr << "0" << std::endl;
|
cannam@0
|
760 std::cerr << "0" << std::endl;
|
cannam@0
|
761 std::cerr << "0" << std::endl;
|
cannam@0
|
762 std::cerr << "File: B" << std::endl;
|
cannam@0
|
763 std::cerr << "Marks: 0" << std::endl;
|
cannam@0
|
764 std::cerr << "FixedPoints: true 0" << std::endl;
|
cannam@0
|
765 std::cerr << "0.02" << std::endl;
|
cannam@0
|
766 std::cerr << "0.02" << std::endl;
|
cannam@0
|
767
|
Chris@30
|
768 std::cerr << len << std::endl;
|
Chris@30
|
769 for (int i = 0; i < len; ++i) {
|
cannam@0
|
770 std::cerr << pathx[i] << std::endl;
|
cannam@0
|
771 }
|
cannam@0
|
772
|
Chris@30
|
773 std::cerr << len << std::endl;
|
Chris@30
|
774 for (int i = 0; i < len; ++i) {
|
cannam@0
|
775 std::cerr << pathy[i] << std::endl;
|
cannam@0
|
776 }
|
cannam@0
|
777 */
|
cannam@0
|
778 }
|
cannam@0
|
779
|
cannam@0
|
780 static Vamp::PluginAdapter<MatchVampPlugin> mvpAdapter;
|
cannam@0
|
781
|
cannam@0
|
782 const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int version,
|
cannam@0
|
783 unsigned int index)
|
cannam@0
|
784 {
|
cannam@0
|
785 if (version < 1) return 0;
|
cannam@0
|
786
|
cannam@0
|
787 switch (index) {
|
cannam@0
|
788 case 0: return mvpAdapter.getDescriptor();
|
cannam@0
|
789 default: return 0;
|
cannam@0
|
790 }
|
cannam@0
|
791 }
|