annotate MatchVampPlugin.cpp @ 30:7784b0a0dd4d

Put the retrievePath logic in Finder (was in the plugin itself)
author Chris Cannam
date Fri, 31 Oct 2014 15:42:40 +0000
parents 9f60d097f0b2
children 1ff9ae1dcb50
rev   line source
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 {
Chris@19 128 return 2;
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@25 204 desc.identifier = "gradientlimit";
Chris@25 205 desc.name = "Gradient Limit";
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
Chris@25 214 desc.identifier = "zonewidth";
Chris@25 215 desc.name = "Search Zone Width";
Chris@25 216 desc.description = "Width of the search zone (error margin) either side of the ongoing match position, in seconds";
Chris@25 217 desc.minValue = 1;
Chris@25 218 desc.maxValue = 60;
Chris@25 219 desc.defaultValue = m_defaultParams.blockTime;
Chris@25 220 desc.isQuantized = true;
Chris@25 221 desc.quantizeStep = 1;
Chris@25 222 desc.unit = "s";
Chris@25 223 list.push_back(desc);
Chris@25 224
cannam@0 225 return list;
cannam@0 226 }
cannam@0 227
cannam@0 228 float
cannam@0 229 MatchVampPlugin::getParameter(std::string name) const
cannam@0 230 {
cannam@0 231 if (name == "serialise") {
cannam@0 232 return m_serialise ? 1.0 : 0.0;
Chris@18 233 } else if (name == "framenorm") {
Chris@18 234 return (int)m_params.frameNorm;
Chris@18 235 } else if (name == "distnorm") {
Chris@18 236 return (int)m_params.distanceNorm;
Chris@18 237 } else if (name == "usespecdiff") {
Chris@18 238 return m_params.useSpectralDifference ? 1.0 : 0.0;
Chris@18 239 } else if (name == "usechroma") {
Chris@18 240 return m_params.useChromaFrequencyMap ? 1.0 : 0.0;
Chris@25 241 } else if (name == "gradientlimit") {
Chris@18 242 return m_params.maxRunCount;
Chris@25 243 } else if (name == "zonewidth") {
Chris@25 244 return m_params.blockTime;
cannam@0 245 }
Chris@18 246
cannam@0 247 return 0.0;
cannam@0 248 }
cannam@0 249
cannam@0 250 void
cannam@0 251 MatchVampPlugin::setParameter(std::string name, float value)
cannam@0 252 {
cannam@0 253 if (name == "serialise") {
cannam@0 254 m_serialise = (value > 0.5);
Chris@18 255 } else if (name == "framenorm") {
Chris@18 256 m_params.frameNorm = (Matcher::FrameNormalisation)(int(value + 0.1));
Chris@18 257 } else if (name == "distnorm") {
Chris@26 258 m_params.distanceNorm = (DistanceMetric::DistanceNormalisation)(int(value + 0.1));
Chris@18 259 } else if (name == "usespecdiff") {
Chris@18 260 m_params.useSpectralDifference = (value > 0.5);
Chris@18 261 } else if (name == "usechroma") {
Chris@18 262 m_params.useChromaFrequencyMap = (value > 0.5);
Chris@25 263 } else if (name == "gradientlimit") {
Chris@18 264 m_params.maxRunCount = int(value + 0.1);
Chris@25 265 } else if (name == "zonewidth") {
Chris@25 266 m_params.blockTime = value;
cannam@0 267 }
cannam@0 268 }
cannam@0 269
cannam@0 270 size_t
cannam@0 271 MatchVampPlugin::getPreferredStepSize() const
cannam@0 272 {
Chris@15 273 return m_inputSampleRate * defaultStepTime;
cannam@0 274 }
cannam@0 275
cannam@0 276 size_t
cannam@0 277 MatchVampPlugin::getPreferredBlockSize() const
cannam@0 278 {
Chris@15 279 return 2048;
cannam@0 280 }
cannam@0 281
cannam@0 282 void
Chris@17 283 MatchVampPlugin::createMatchers()
cannam@0 284 {
Chris@17 285 m_params.hopTime = m_stepTime;
Chris@17 286 m_params.fftSize = m_blockSize;
Chris@17 287 pm1 = new Matcher(m_params, 0);
Chris@17 288 pm2 = new Matcher(m_params, pm1);
cannam@0 289 pm1->setOtherMatcher(pm2);
cannam@0 290 feeder = new MatchFeeder(pm1, pm2);
cannam@0 291 }
cannam@0 292
cannam@0 293 bool
cannam@0 294 MatchVampPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize)
cannam@0 295 {
Chris@10 296 if (m_inputSampleRate < sampleRateMin) {
Chris@10 297 std::cerr << "MatchVampPlugin::MatchVampPlugin: input sample rate "
Chris@10 298 << m_inputSampleRate << " < min supported rate "
Chris@10 299 << sampleRateMin << std::endl;
Chris@10 300 return false;
Chris@10 301 }
cannam@0 302 if (channels < getMinChannelCount() ||
cannam@0 303 channels > getMaxChannelCount()) return false;
cannam@1 304 if (stepSize > blockSize/2 ||
cannam@0 305 blockSize != getPreferredBlockSize()) return false;
Chris@15 306
cannam@6 307 m_stepSize = stepSize;
Chris@15 308 m_stepTime = float(stepSize) / m_inputSampleRate;
Chris@15 309 m_blockSize = blockSize;
Chris@15 310
Chris@15 311 createMatchers();
cannam@0 312 m_begin = true;
cannam@0 313 m_locked = false;
Chris@15 314
cannam@0 315 return true;
cannam@0 316 }
cannam@0 317
cannam@0 318 void
cannam@0 319 MatchVampPlugin::reset()
cannam@0 320 {
cannam@6 321 delete feeder;
cannam@6 322 delete pm1;
cannam@6 323 delete pm2;
cannam@6 324 feeder = 0;
cannam@6 325 pm1 = 0;
cannam@6 326 pm2 = 0;
cannam@6 327
cannam@6 328 createMatchers();
cannam@6 329 m_begin = true;
cannam@6 330 m_locked = false;
cannam@0 331 }
cannam@0 332
cannam@0 333 MatchVampPlugin::OutputList
cannam@0 334 MatchVampPlugin::getOutputDescriptors() const
cannam@0 335 {
cannam@0 336 OutputList list;
cannam@0 337
Chris@15 338 float outRate = 1.0 / m_stepTime;
cannam@0 339
cannam@0 340 OutputDescriptor desc;
cannam@0 341 desc.identifier = "path";
cannam@0 342 desc.name = "Path";
cannam@0 343 desc.description = "Alignment path";
cannam@0 344 desc.unit = "";
cannam@0 345 desc.hasFixedBinCount = true;
cannam@0 346 desc.binCount = 1;
cannam@0 347 desc.hasKnownExtents = false;
cannam@0 348 desc.isQuantized = true;
cannam@0 349 desc.quantizeStep = 1;
cannam@0 350 desc.sampleType = OutputDescriptor::VariableSampleRate;
cannam@0 351 desc.sampleRate = outRate;
Chris@16 352 m_pathOutNo = list.size();
cannam@0 353 list.push_back(desc);
cannam@0 354
cannam@0 355 desc.identifier = "a_b";
cannam@0 356 desc.name = "A-B Timeline";
cannam@0 357 desc.description = "Timing in performance B corresponding to moments in performance A";
cannam@0 358 desc.unit = "sec";
cannam@0 359 desc.hasFixedBinCount = true;
cannam@0 360 desc.binCount = 1;
cannam@0 361 desc.hasKnownExtents = false;
cannam@0 362 desc.isQuantized = false;
cannam@0 363 desc.sampleType = OutputDescriptor::VariableSampleRate;
cannam@0 364 desc.sampleRate = outRate;
Chris@16 365 m_abOutNo = list.size();
cannam@0 366 list.push_back(desc);
cannam@0 367
cannam@0 368 desc.identifier = "b_a";
cannam@0 369 desc.name = "B-A Timeline";
cannam@0 370 desc.description = "Timing in performance A corresponding to moments in performance B";
cannam@0 371 desc.unit = "sec";
cannam@0 372 desc.hasFixedBinCount = true;
cannam@0 373 desc.binCount = 1;
cannam@0 374 desc.hasKnownExtents = false;
cannam@0 375 desc.isQuantized = false;
cannam@0 376 desc.sampleType = OutputDescriptor::VariableSampleRate;
cannam@0 377 desc.sampleRate = outRate;
Chris@16 378 m_baOutNo = list.size();
cannam@0 379 list.push_back(desc);
cannam@0 380
cannam@0 381 desc.identifier = "a_b_divergence";
cannam@0 382 desc.name = "A-B Divergence";
cannam@0 383 desc.description = "Difference between timings in performances A and B";
cannam@0 384 desc.unit = "sec";
cannam@0 385 desc.hasFixedBinCount = true;
cannam@0 386 desc.binCount = 1;
cannam@0 387 desc.hasKnownExtents = false;
cannam@0 388 desc.isQuantized = false;
cannam@0 389 desc.sampleType = OutputDescriptor::VariableSampleRate;
cannam@0 390 desc.sampleRate = outRate;
Chris@16 391 m_abDivOutNo = list.size();
cannam@0 392 list.push_back(desc);
cannam@0 393
cannam@0 394 desc.identifier = "a_b_temporatio";
cannam@0 395 desc.name = "A-B Tempo Ratio";
cannam@0 396 desc.description = "Ratio of tempi between performances A and B";
cannam@0 397 desc.unit = "";
cannam@0 398 desc.hasFixedBinCount = true;
cannam@0 399 desc.binCount = 1;
cannam@0 400 desc.hasKnownExtents = false;
cannam@0 401 desc.isQuantized = false;
cannam@0 402 desc.sampleType = OutputDescriptor::VariableSampleRate;
cannam@0 403 desc.sampleRate = outRate;
Chris@16 404 m_abRatioOutNo = list.size();
cannam@0 405 list.push_back(desc);
cannam@0 406
Chris@15 407 desc.identifier = "a_features";
Chris@15 408 desc.name = "A Features";
Chris@15 409 desc.description = "Spectral features extracted from performance A";
Chris@15 410 desc.unit = "";
Chris@15 411 desc.hasFixedBinCount = true;
Chris@23 412 desc.binCount = Matcher::getFeatureSizeFor(m_params);
Chris@15 413 desc.hasKnownExtents = false;
Chris@15 414 desc.isQuantized = false;
Chris@16 415 desc.sampleType = OutputDescriptor::FixedSampleRate;
Chris@15 416 desc.sampleRate = outRate;
Chris@16 417 m_aFeaturesOutNo = list.size();
Chris@16 418 list.push_back(desc);
Chris@16 419
Chris@16 420 desc.identifier = "b_features";
Chris@16 421 desc.name = "B Features";
Chris@16 422 desc.description = "Spectral features extracted from performance B";
Chris@16 423 desc.unit = "";
Chris@16 424 desc.hasFixedBinCount = true;
Chris@23 425 desc.binCount = Matcher::getFeatureSizeFor(m_params);
Chris@16 426 desc.hasKnownExtents = false;
Chris@16 427 desc.isQuantized = false;
Chris@16 428 desc.sampleType = OutputDescriptor::FixedSampleRate;
Chris@16 429 desc.sampleRate = outRate;
Chris@16 430 m_bFeaturesOutNo = list.size();
Chris@15 431 list.push_back(desc);
Chris@15 432
cannam@0 433 return list;
cannam@0 434 }
cannam@0 435
cannam@0 436 MatchVampPlugin::FeatureSet
cannam@0 437 MatchVampPlugin::process(const float *const *inputBuffers,
cannam@0 438 Vamp::RealTime timestamp)
cannam@0 439 {
cannam@0 440 if (m_begin) {
cannam@0 441 if (!m_locked && m_serialise) {
cannam@0 442 m_locked = true;
cannam@0 443 #ifdef _WIN32
cannam@0 444 WaitForSingleObject(m_serialisingMutex, INFINITE);
cannam@0 445 #else
cannam@0 446 pthread_mutex_lock(&m_serialisingMutex);
cannam@0 447 #endif
cannam@0 448 }
Chris@10 449 m_startTime = timestamp;
cannam@0 450 m_begin = false;
cannam@0 451 }
cannam@0 452
cannam@0 453 // std::cerr << timestamp.toString();
cannam@0 454
Chris@16 455 MatchFeeder::Features ff = feeder->feedAndGetFeatures(inputBuffers);
Chris@16 456
Chris@16 457 FeatureSet returnFeatures;
Chris@16 458
Chris@16 459 Feature f;
Chris@16 460 f.hasTimestamp = false;
Chris@16 461
Chris@16 462 for (int i = 0; i < (int)ff.f1.size(); ++i) {
Chris@16 463 f.values.clear();
Chris@16 464 for (int j = 0; j < (int)ff.f1[i].size(); ++j) {
Chris@16 465 f.values.push_back(ff.f1[i][j]);
Chris@16 466 }
Chris@16 467 returnFeatures[m_aFeaturesOutNo].push_back(f);
Chris@16 468 }
Chris@16 469
Chris@16 470 for (int i = 0; i < (int)ff.f2.size(); ++i) {
Chris@16 471 f.values.clear();
Chris@16 472 for (int j = 0; j < (int)ff.f2[i].size(); ++j) {
Chris@16 473 f.values.push_back(ff.f2[i][j]);
Chris@16 474 }
Chris@16 475 returnFeatures[m_bFeaturesOutNo].push_back(f);
Chris@16 476 }
cannam@0 477
cannam@0 478 // std::cerr << ".";
cannam@0 479 // std::cerr << std::endl;
cannam@0 480
Chris@16 481 return returnFeatures;
cannam@0 482 }
cannam@0 483
cannam@0 484 MatchVampPlugin::FeatureSet
cannam@0 485 MatchVampPlugin::getRemainingFeatures()
cannam@0 486 {
cannam@0 487 Finder *finder = feeder->getFinder();
cannam@0 488 std::vector<int> pathx;
cannam@0 489 std::vector<int> pathy;
Chris@30 490 int len = finder->retrievePath(pathx, pathy);
Chris@30 491
cannam@0 492 FeatureSet returnFeatures;
cannam@0 493
cannam@0 494 int prevx = 0;
cannam@0 495 int prevy = 0;
cannam@0 496
Chris@30 497 for (int i = 0; i < len; ++i) {
cannam@0 498
cannam@0 499 int x = pathx[i];
cannam@0 500 int y = pathy[i];
cannam@0 501
cannam@0 502 Vamp::RealTime xt = Vamp::RealTime::frame2RealTime
Chris@15 503 (x * m_stepSize, lrintf(m_inputSampleRate));
cannam@0 504 Vamp::RealTime yt = Vamp::RealTime::frame2RealTime
Chris@15 505 (y * m_stepSize, lrintf(m_inputSampleRate));
cannam@0 506
cannam@0 507 Feature feature;
cannam@0 508 feature.hasTimestamp = true;
Chris@10 509 feature.timestamp = m_startTime + xt;
cannam@0 510 feature.values.clear();
cannam@0 511 feature.values.push_back(yt.sec + double(yt.nsec)/1.0e9);
Chris@16 512 returnFeatures[m_pathOutNo].push_back(feature);
cannam@0 513
cannam@0 514 if (x != prevx) {
cannam@0 515
cannam@0 516 feature.hasTimestamp = true;
Chris@10 517 feature.timestamp = m_startTime + xt;
cannam@0 518 feature.values.clear();
cannam@0 519 feature.values.push_back(yt.sec + yt.msec()/1000.0);
Chris@16 520 returnFeatures[m_abOutNo].push_back(feature);
cannam@0 521
cannam@0 522 Vamp::RealTime diff = yt - xt;
cannam@0 523 feature.values.clear();
cannam@0 524 feature.values.push_back(diff.sec + diff.msec()/1000.0);
Chris@16 525 returnFeatures[m_abDivOutNo].push_back(feature);
cannam@0 526
cannam@0 527 if (i > 0) {
cannam@0 528 int lookback = 100; //!!! arbitrary
cannam@0 529 if (lookback > i) lookback = i;
cannam@0 530 int xdiff = x - pathx[i-lookback];
cannam@0 531 int ydiff = y - pathy[i-lookback];
cannam@0 532 if (xdiff != 0 && ydiff != 0) {
cannam@0 533 float ratio = float(ydiff)/float(xdiff);
cannam@0 534 if (ratio < 8 && ratio > (1.0/8)) { //!!! just for now, since we aren't dealing properly with silence yet
cannam@0 535 feature.values.clear();
cannam@0 536 feature.values.push_back(ratio);
Chris@16 537 returnFeatures[m_abRatioOutNo].push_back(feature);
cannam@0 538 }
cannam@0 539 }
cannam@0 540 }
cannam@0 541 }
cannam@0 542
cannam@0 543 if (y != prevy) {
cannam@0 544 feature.hasTimestamp = true;
Chris@10 545 feature.timestamp = m_startTime + yt;
cannam@0 546 feature.values.clear();
cannam@0 547 feature.values.push_back(xt.sec + xt.msec()/1000.0);
Chris@16 548 returnFeatures[m_baOutNo].push_back(feature);
cannam@0 549 }
cannam@0 550
cannam@0 551 prevx = x;
cannam@0 552 prevy = y;
cannam@0 553 }
cannam@0 554
cannam@0 555 delete feeder;
cannam@0 556 delete pm1;
cannam@0 557 delete pm2;
cannam@0 558 feeder = 0;
cannam@0 559 pm1 = 0;
cannam@0 560 pm2 = 0;
cannam@0 561
cannam@0 562 if (m_locked) {
cannam@0 563 #ifdef _WIN32
cannam@0 564 ReleaseMutex(m_serialisingMutex);
cannam@0 565 #else
cannam@0 566 pthread_mutex_unlock(&m_serialisingMutex);
cannam@0 567 #endif
cannam@0 568 m_locked = false;
cannam@0 569 }
cannam@0 570
cannam@0 571 return returnFeatures;
cannam@0 572
cannam@0 573
cannam@0 574 /*
Chris@30 575 for (int i = 0; i < len; ++i) {
cannam@0 576 std::cerr << i << ": [" << pathx[i] << "," << pathy[i] << "]" << std::endl;
cannam@0 577 }
cannam@0 578
cannam@0 579 std::cerr << std::endl;
cannam@0 580 std::cerr << "File: A" << std::endl;
cannam@0 581 std::cerr << "Marks: -1" << std::endl;
cannam@0 582 std::cerr << "FixedPoints: true 0" << std::endl;
cannam@0 583 std::cerr << "0" << std::endl;
cannam@0 584 std::cerr << "0" << std::endl;
cannam@0 585 std::cerr << "0" << std::endl;
cannam@0 586 std::cerr << "0" << std::endl;
cannam@0 587 std::cerr << "File: B" << std::endl;
cannam@0 588 std::cerr << "Marks: 0" << std::endl;
cannam@0 589 std::cerr << "FixedPoints: true 0" << std::endl;
cannam@0 590 std::cerr << "0.02" << std::endl;
cannam@0 591 std::cerr << "0.02" << std::endl;
cannam@0 592
Chris@30 593 std::cerr << len << std::endl;
Chris@30 594 for (int i = 0; i < len; ++i) {
cannam@0 595 std::cerr << pathx[i] << std::endl;
cannam@0 596 }
cannam@0 597
Chris@30 598 std::cerr << len << std::endl;
Chris@30 599 for (int i = 0; i < len; ++i) {
cannam@0 600 std::cerr << pathy[i] << std::endl;
cannam@0 601 }
cannam@0 602 */
cannam@0 603 }
cannam@0 604
cannam@0 605 static Vamp::PluginAdapter<MatchVampPlugin> mvpAdapter;
cannam@0 606
cannam@0 607 const VampPluginDescriptor *vampGetPluginDescriptor(unsigned int version,
cannam@0 608 unsigned int index)
cannam@0 609 {
cannam@0 610 if (version < 1) return 0;
cannam@0 611
cannam@0 612 switch (index) {
cannam@0 613 case 0: return mvpAdapter.getDescriptor();
cannam@0 614 default: return 0;
cannam@0 615 }
cannam@0 616 }