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