comparison src/Silvet.cpp @ 272:e5f897b2d5e8

Handle resampler latency, impose limits on input sample rate
author Chris Cannam
date Mon, 28 Jul 2014 14:40:44 +0100
parents 10d8bd634a77
children 8aff275f16b5
comparison
equal deleted inserted replaced
271:10d8bd634a77 272:e5f897b2d5e8
32 using std::endl; 32 using std::endl;
33 using Vamp::RealTime; 33 using Vamp::RealTime;
34 34
35 static int processingSampleRate = 44100; 35 static int processingSampleRate = 44100;
36 static int processingBPO = 60; 36 static int processingBPO = 60;
37
38 static int minInputSampleRate = 100;
39 static int maxInputSampleRate = 192000;
37 40
38 Silvet::Silvet(float inputSampleRate) : 41 Silvet::Silvet(float inputSampleRate) :
39 Plugin(inputSampleRate), 42 Plugin(inputSampleRate),
40 m_instruments(InstrumentPack::listInstrumentPacks()), 43 m_instruments(InstrumentPack::listInstrumentPacks()),
41 m_resampler(0), 44 m_resampler(0),
327 } 330 }
328 331
329 bool 332 bool
330 Silvet::initialise(size_t channels, size_t stepSize, size_t blockSize) 333 Silvet::initialise(size_t channels, size_t stepSize, size_t blockSize)
331 { 334 {
335 if (m_inputSampleRate < minInputSampleRate ||
336 m_inputSampleRate > maxInputSampleRate) {
337 cerr << "Silvet::initialise: Unsupported input sample rate "
338 << m_inputSampleRate << " (supported min " << minInputSampleRate
339 << ", max " << maxInputSampleRate << ")" << endl;
340 return false;
341 }
342
332 if (channels < getMinChannelCount() || 343 if (channels < getMinChannelCount() ||
333 channels > getMaxChannelCount()) return false; 344 channels > getMaxChannelCount()) {
345 cerr << "Silvet::initialise: Unsupported channel count " << channels
346 << " (supported min " << getMinChannelCount() << ", max "
347 << getMaxChannelCount() << ")" << endl;
348 return false;
349 }
334 350
335 if (stepSize != blockSize) { 351 if (stepSize != blockSize) {
336 cerr << "Silvet::initialise: Step size must be the same as block size (" 352 cerr << "Silvet::initialise: Step size must be the same as block size ("
337 << stepSize << " != " << blockSize << ")" << endl; 353 << stepSize << " != " << blockSize << ")" << endl;
338 return false; 354 return false;
395 m_postFilter.push_back(new MedianFilter<double>(3)); 411 m_postFilter.push_back(new MedianFilter<double>(3));
396 } 412 }
397 m_pianoRoll.clear(); 413 m_pianoRoll.clear();
398 m_inputGains.clear(); 414 m_inputGains.clear();
399 m_columnCount = 0; 415 m_columnCount = 0;
416 m_resampledCount = 0;
400 m_startTime = RealTime::zeroTime; 417 m_startTime = RealTime::zeroTime;
401 } 418 }
402 419
403 Silvet::FeatureSet 420 Silvet::FeatureSet
404 Silvet::process(const float *const *inputBuffers, Vamp::RealTime timestamp) 421 Silvet::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
424 double d = flattened[i]; 441 double d = flattened[i];
425 data.push_back(d); 442 data.push_back(d);
426 } 443 }
427 444
428 if (m_resampler) { 445 if (m_resampler) {
446
429 data = m_resampler->process(data.data(), data.size()); 447 data = m_resampler->process(data.data(), data.size());
430 } 448
431 449 int hadCount = m_resampledCount;
450 m_resampledCount += data.size();
451
452 int resamplerLatency = m_resampler->getLatency();
453
454 if (hadCount < resamplerLatency) {
455 int stillToDrop = resamplerLatency - hadCount;
456 if (stillToDrop >= int(data.size())) {
457 return FeatureSet();
458 } else {
459 data = vector<double>(data.begin() + stillToDrop, data.end());
460 }
461 }
462 }
463
432 Grid cqout = m_cq->process(data); 464 Grid cqout = m_cq->process(data);
433 FeatureSet fs = transcribe(cqout); 465 FeatureSet fs = transcribe(cqout);
434 return fs; 466 return fs;
435 } 467 }
436 468
463 495
464 int width = filtered.size(); 496 int width = filtered.size();
465 497
466 int iterations = m_hqMode ? 20 : 10; 498 int iterations = m_hqMode ? 20 : 10;
467 499
468 //!!! pitches or notes? [terminology]
469 Grid localPitches(width, vector<double>(pack.templateNoteCount, 0.0)); 500 Grid localPitches(width, vector<double>(pack.templateNoteCount, 0.0));
470 501
471 bool wantShifts = m_hqMode && m_fineTuning; 502 bool wantShifts = m_hqMode && m_fineTuning;
472 int shiftCount = 1; 503 int shiftCount = 1;
473 if (wantShifts) { 504 if (wantShifts) {