# HG changeset patch # User Chris Cannam # Date 1406554844 -3600 # Node ID e5f897b2d5e882487d19d228787a76b416891a20 # Parent 10d8bd634a7715a40cc790d2eef5d838d1231a58 Handle resampler latency, impose limits on input sample rate diff -r 10d8bd634a77 -r e5f897b2d5e8 src/Silvet.cpp --- a/src/Silvet.cpp Sat Jul 26 10:18:01 2014 +0100 +++ b/src/Silvet.cpp Mon Jul 28 14:40:44 2014 +0100 @@ -35,6 +35,9 @@ static int processingSampleRate = 44100; static int processingBPO = 60; +static int minInputSampleRate = 100; +static int maxInputSampleRate = 192000; + Silvet::Silvet(float inputSampleRate) : Plugin(inputSampleRate), m_instruments(InstrumentPack::listInstrumentPacks()), @@ -329,8 +332,21 @@ bool Silvet::initialise(size_t channels, size_t stepSize, size_t blockSize) { + if (m_inputSampleRate < minInputSampleRate || + m_inputSampleRate > maxInputSampleRate) { + cerr << "Silvet::initialise: Unsupported input sample rate " + << m_inputSampleRate << " (supported min " << minInputSampleRate + << ", max " << maxInputSampleRate << ")" << endl; + return false; + } + if (channels < getMinChannelCount() || - channels > getMaxChannelCount()) return false; + channels > getMaxChannelCount()) { + cerr << "Silvet::initialise: Unsupported channel count " << channels + << " (supported min " << getMinChannelCount() << ", max " + << getMaxChannelCount() << ")" << endl; + return false; + } if (stepSize != blockSize) { cerr << "Silvet::initialise: Step size must be the same as block size (" @@ -397,6 +413,7 @@ m_pianoRoll.clear(); m_inputGains.clear(); m_columnCount = 0; + m_resampledCount = 0; m_startTime = RealTime::zeroTime; } @@ -426,9 +443,24 @@ } if (m_resampler) { + data = m_resampler->process(data.data(), data.size()); + + int hadCount = m_resampledCount; + m_resampledCount += data.size(); + + int resamplerLatency = m_resampler->getLatency(); + + if (hadCount < resamplerLatency) { + int stillToDrop = resamplerLatency - hadCount; + if (stillToDrop >= int(data.size())) { + return FeatureSet(); + } else { + data = vector(data.begin() + stillToDrop, data.end()); + } + } } - + Grid cqout = m_cq->process(data); FeatureSet fs = transcribe(cqout); return fs; @@ -465,7 +497,6 @@ int iterations = m_hqMode ? 20 : 10; - //!!! pitches or notes? [terminology] Grid localPitches(width, vector(pack.templateNoteCount, 0.0)); bool wantShifts = m_hqMode && m_fineTuning; diff -r 10d8bd634a77 -r e5f897b2d5e8 src/Silvet.h --- a/src/Silvet.h Sat Jul 26 10:18:01 2014 +0100 +++ b/src/Silvet.h Mon Jul 28 14:40:44 2014 +0100 @@ -113,6 +113,7 @@ int m_blockSize; int m_columnCount; + int m_resampledCount; Vamp::RealTime m_startTime; mutable int m_notesOutputNo;