Mercurial > hg > svcore
comparison transform/FeatureExtractionModelTransformer.cpp @ 1071:f4ad0bfceeb7
Handle case where plugin erroneously returns sample rate 0 for fixed-rate output
author | Chris Cannam |
---|---|
date | Thu, 14 May 2015 14:04:41 +0100 |
parents | a1cd5abcb38b |
children | f35c1f9bfaa2 |
comparison
equal
deleted
inserted
replaced
1070:b8a788c9a6f1 | 1071:f4ad0bfceeb7 |
---|---|
277 //!!! different underlying rates together -- so we always set | 277 //!!! different underlying rates together -- so we always set |
278 //!!! the model rate to be the input model's rate, and adjust | 278 //!!! the model rate to be the input model's rate, and adjust |
279 //!!! the resolution appropriately. We can't properly display | 279 //!!! the resolution appropriately. We can't properly display |
280 //!!! data with a higher resolution than the base model at all | 280 //!!! data with a higher resolution than the base model at all |
281 if (m_descriptors[n]->sampleRate > input->getSampleRate()) { | 281 if (m_descriptors[n]->sampleRate > input->getSampleRate()) { |
282 modelResolution = 1; | |
283 } else if (m_descriptors[n]->sampleRate <= 0.0) { | |
284 cerr << "WARNING: Fixed sample-rate plugin reports invalid sample rate " << m_descriptors[n]->sampleRate << "; defaulting to input rate of " << input->getSampleRate() << endl; | |
282 modelResolution = 1; | 285 modelResolution = 1; |
283 } else { | 286 } else { |
284 modelResolution = int(round(modelRate / m_descriptors[n]->sampleRate)); | 287 modelResolution = int(round(modelRate / m_descriptors[n]->sampleRate)); |
285 } | 288 } |
286 break; | 289 break; |
840 return; | 843 return; |
841 } else { | 844 } else { |
842 frame = RealTime::realTime2Frame(feature.timestamp, inputRate); | 845 frame = RealTime::realTime2Frame(feature.timestamp, inputRate); |
843 } | 846 } |
844 | 847 |
848 // cerr << "variable sample rate: timestamp = " << feature.timestamp | |
849 // << " at input rate " << inputRate << " -> " << frame << endl; | |
850 | |
845 } else if (m_descriptors[n]->sampleType == | 851 } else if (m_descriptors[n]->sampleType == |
846 Vamp::Plugin::OutputDescriptor::FixedSampleRate) { | 852 Vamp::Plugin::OutputDescriptor::FixedSampleRate) { |
847 | 853 |
854 sv_samplerate_t rate = m_descriptors[n]->sampleRate; | |
855 if (rate <= 0.0) { | |
856 rate = inputRate; | |
857 } | |
858 | |
848 if (!feature.hasTimestamp) { | 859 if (!feature.hasTimestamp) { |
849 ++m_fixedRateFeatureNos[n]; | 860 ++m_fixedRateFeatureNos[n]; |
850 } else { | 861 } else { |
851 RealTime ts(feature.timestamp.sec, feature.timestamp.nsec); | 862 RealTime ts(feature.timestamp.sec, feature.timestamp.nsec); |
852 m_fixedRateFeatureNos[n] = (int) | 863 m_fixedRateFeatureNos[n] = (int)lrint(ts.toDouble() * rate); |
853 lrint(ts.toDouble() * m_descriptors[n]->sampleRate); | 864 } |
854 } | 865 |
855 | 866 // cerr << "m_fixedRateFeatureNo = " << m_fixedRateFeatureNos[n] |
856 // cerr << "m_fixedRateFeatureNo = " << m_fixedRateFeatureNo | 867 // << ", m_descriptor->sampleRate = " << m_descriptors[n]->sampleRate |
857 // << ", m_descriptor->sampleRate = " << m_descriptor->sampleRate | |
858 // << ", inputRate = " << inputRate | 868 // << ", inputRate = " << inputRate |
859 // << " giving frame = "; | 869 // << " giving frame = "; |
860 frame = lrint((double(m_fixedRateFeatureNos[n]) | 870 frame = lrint((double(m_fixedRateFeatureNos[n]) / rate) * inputRate); |
861 / m_descriptors[n]->sampleRate) | 871 // cerr << frame << endl; |
862 * inputRate); | |
863 } | 872 } |
864 | 873 |
865 if (frame < 0) { | 874 if (frame < 0) { |
866 cerr | 875 cerr |
867 << "WARNING: FeatureExtractionModelTransformer::addFeature: " | 876 << "WARNING: FeatureExtractionModelTransformer::addFeature: " |