# HG changeset patch # User Chris Cannam # Date 1431608681 -3600 # Node ID f4ad0bfceeb7cc40ab00ecc97883ac02d123a6fd # Parent b8a788c9a6f1c02fe8b215b5eb057c94a31a0805 Handle case where plugin erroneously returns sample rate 0 for fixed-rate output diff -r b8a788c9a6f1 -r f4ad0bfceeb7 transform/FeatureExtractionModelTransformer.cpp --- a/transform/FeatureExtractionModelTransformer.cpp Tue May 12 16:19:45 2015 +0100 +++ b/transform/FeatureExtractionModelTransformer.cpp Thu May 14 14:04:41 2015 +0100 @@ -280,6 +280,9 @@ //!!! data with a higher resolution than the base model at all if (m_descriptors[n]->sampleRate > input->getSampleRate()) { modelResolution = 1; + } else if (m_descriptors[n]->sampleRate <= 0.0) { + cerr << "WARNING: Fixed sample-rate plugin reports invalid sample rate " << m_descriptors[n]->sampleRate << "; defaulting to input rate of " << input->getSampleRate() << endl; + modelResolution = 1; } else { modelResolution = int(round(modelRate / m_descriptors[n]->sampleRate)); } @@ -842,24 +845,30 @@ frame = RealTime::realTime2Frame(feature.timestamp, inputRate); } +// cerr << "variable sample rate: timestamp = " << feature.timestamp +// << " at input rate " << inputRate << " -> " << frame << endl; + } else if (m_descriptors[n]->sampleType == Vamp::Plugin::OutputDescriptor::FixedSampleRate) { + sv_samplerate_t rate = m_descriptors[n]->sampleRate; + if (rate <= 0.0) { + rate = inputRate; + } + if (!feature.hasTimestamp) { ++m_fixedRateFeatureNos[n]; } else { RealTime ts(feature.timestamp.sec, feature.timestamp.nsec); - m_fixedRateFeatureNos[n] = (int) - lrint(ts.toDouble() * m_descriptors[n]->sampleRate); + m_fixedRateFeatureNos[n] = (int)lrint(ts.toDouble() * rate); } -// cerr << "m_fixedRateFeatureNo = " << m_fixedRateFeatureNo -// << ", m_descriptor->sampleRate = " << m_descriptor->sampleRate +// cerr << "m_fixedRateFeatureNo = " << m_fixedRateFeatureNos[n] +// << ", m_descriptor->sampleRate = " << m_descriptors[n]->sampleRate // << ", inputRate = " << inputRate // << " giving frame = "; - frame = lrint((double(m_fixedRateFeatureNos[n]) - / m_descriptors[n]->sampleRate) - * inputRate); + frame = lrint((double(m_fixedRateFeatureNos[n]) / rate) * inputRate); +// cerr << frame << endl; } if (frame < 0) {