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