Mercurial > hg > silvet
changeset 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 | 4e19c60241cb 537205426492 |
files | src/Silvet.cpp src/Silvet.h |
diffstat | 2 files changed, 35 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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<double>(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<double>(pack.templateNoteCount, 0.0)); bool wantShifts = m_hqMode && m_fineTuning;