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