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