comparison MatchVampPlugin.cpp @ 10:6ea008aa8817

Fixes to problems reported by plugin tester
author Chris Cannam
date Wed, 06 Aug 2014 12:38:00 +0100
parents 80fae79c9472
children a82276091bbd
comparison
equal deleted inserted replaced
9:fec395fcdc7c 10:6ea008aa8817
38 #endif 38 #endif
39 39
40 bool 40 bool
41 MatchVampPlugin::m_serialisingMutexInitialised = false; 41 MatchVampPlugin::m_serialisingMutexInitialised = false;
42 42
43 // We want to ensure our freq map / crossover bin in Matcher.cpp are
44 // always valid with a fixed FFT length in seconds, so must reject low
45 // sample rates
46 static float sampleRateMin = 5000.f;
47
43 MatchVampPlugin::MatchVampPlugin(float inputSampleRate) : 48 MatchVampPlugin::MatchVampPlugin(float inputSampleRate) :
44 Plugin(inputSampleRate), 49 Plugin(inputSampleRate),
45 m_stepSize(0), 50 m_stepSize(0),
46 m_serialise(false), 51 m_serialise(false),
47 m_begin(true), 52 m_begin(true),
48 m_locked(false) 53 m_locked(false)
49 { 54 {
55 if (inputSampleRate < sampleRateMin) {
56 std::cerr << "MatchVampPlugin::MatchVampPlugin: input sample rate "
57 << inputSampleRate << " < min supported rate "
58 << sampleRateMin << ", plugin will refuse to initialise"
59 << std::endl;
60 }
61
50 if (!m_serialisingMutexInitialised) { 62 if (!m_serialisingMutexInitialised) {
51 m_serialisingMutexInitialised = true; 63 m_serialisingMutexInitialised = true;
52 #ifdef _WIN32 64 #ifdef _WIN32
53 m_serialisingMutex = CreateMutex(NULL, FALSE, NULL); 65 m_serialisingMutex = CreateMutex(NULL, FALSE, NULL);
54 #else 66 #else
147 void 159 void
148 MatchVampPlugin::setParameter(std::string name, float value) 160 MatchVampPlugin::setParameter(std::string name, float value)
149 { 161 {
150 if (name == "serialise") { 162 if (name == "serialise") {
151 m_serialise = (value > 0.5); 163 m_serialise = (value > 0.5);
152 std::cerr << "MatchVampPlugin::setParameter: set serialise to " << m_serialise << std::endl; 164 // std::cerr << "MatchVampPlugin::setParameter: set serialise to " << m_serialise << std::endl;
153 } 165 }
154 } 166 }
155 167
156 size_t 168 size_t
157 MatchVampPlugin::getPreferredStepSize() const 169 MatchVampPlugin::getPreferredStepSize() const
177 } 189 }
178 190
179 bool 191 bool
180 MatchVampPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize) 192 MatchVampPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize)
181 { 193 {
194 if (m_inputSampleRate < sampleRateMin) {
195 std::cerr << "MatchVampPlugin::MatchVampPlugin: input sample rate "
196 << m_inputSampleRate << " < min supported rate "
197 << sampleRateMin << std::endl;
198 return false;
199 }
182 if (!pm1) createMatchers(); 200 if (!pm1) createMatchers();
183 if (channels < getMinChannelCount() || 201 if (channels < getMinChannelCount() ||
184 channels > getMaxChannelCount()) return false; 202 channels > getMaxChannelCount()) return false;
185 if (stepSize > blockSize/2 || 203 if (stepSize > blockSize/2 ||
186 blockSize != getPreferredBlockSize()) return false; 204 blockSize != getPreferredBlockSize()) return false;
292 WaitForSingleObject(m_serialisingMutex, INFINITE); 310 WaitForSingleObject(m_serialisingMutex, INFINITE);
293 #else 311 #else
294 pthread_mutex_lock(&m_serialisingMutex); 312 pthread_mutex_lock(&m_serialisingMutex);
295 #endif 313 #endif
296 } 314 }
315 m_startTime = timestamp;
297 m_begin = false; 316 m_begin = false;
298 } 317 }
299 318
300 // std::cerr << timestamp.toString(); 319 // std::cerr << timestamp.toString();
301 320
357 Vamp::RealTime yt = Vamp::RealTime::frame2RealTime 376 Vamp::RealTime yt = Vamp::RealTime::frame2RealTime
358 (y * pm2->getHopSize(), lrintf(m_inputSampleRate)); 377 (y * pm2->getHopSize(), lrintf(m_inputSampleRate));
359 378
360 Feature feature; 379 Feature feature;
361 feature.hasTimestamp = true; 380 feature.hasTimestamp = true;
362 feature.timestamp = xt; 381 feature.timestamp = m_startTime + xt;
363 feature.values.clear(); 382 feature.values.clear();
364 feature.values.push_back(yt.sec + double(yt.nsec)/1.0e9); 383 feature.values.push_back(yt.sec + double(yt.nsec)/1.0e9);
365 returnFeatures[0].push_back(feature); 384 returnFeatures[0].push_back(feature);
366 385
367 if (x != prevx) { 386 if (x != prevx) {
368 387
369 feature.hasTimestamp = true; 388 feature.hasTimestamp = true;
370 feature.timestamp = xt; 389 feature.timestamp = m_startTime + xt;
371 feature.values.clear(); 390 feature.values.clear();
372 feature.values.push_back(yt.sec + yt.msec()/1000.0); 391 feature.values.push_back(yt.sec + yt.msec()/1000.0);
373 returnFeatures[1].push_back(feature); 392 returnFeatures[1].push_back(feature);
374 393
375 Vamp::RealTime diff = yt - xt; 394 Vamp::RealTime diff = yt - xt;
393 } 412 }
394 } 413 }
395 414
396 if (y != prevy) { 415 if (y != prevy) {
397 feature.hasTimestamp = true; 416 feature.hasTimestamp = true;
398 feature.timestamp = yt; 417 feature.timestamp = m_startTime + yt;
399 feature.values.clear(); 418 feature.values.clear();
400 feature.values.push_back(xt.sec + xt.msec()/1000.0); 419 feature.values.push_back(xt.sec + xt.msec()/1000.0);
401 returnFeatures[2].push_back(feature); 420 returnFeatures[2].push_back(feature);
402 } 421 }
403 422