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