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