annotate src/MatchVampPlugin.cpp @ 38:8cce4e13ede3 refactors

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