Mercurial > hg > svcore
diff transform/FeatureExtractionModelTransformer.cpp @ 1039:b14064bd1f97 cxx11
This code now compiles. Main problem: sample rate types
author | Chris Cannam |
---|---|
date | Tue, 03 Mar 2015 17:09:19 +0000 |
parents | d9e0e59a1581 |
children | a1cd5abcb38b |
line wrap: on
line diff
--- a/transform/FeatureExtractionModelTransformer.cpp Tue Mar 03 15:18:24 2015 +0000 +++ b/transform/FeatureExtractionModelTransformer.cpp Tue Mar 03 17:09:19 2015 +0000 @@ -100,7 +100,7 @@ return false; } - m_plugin = factory->instantiatePlugin(pluginId, input->getSampleRate()); + m_plugin = factory->instantiatePlugin(pluginId, float(input->getSampleRate())); if (!m_plugin) { m_message = tr("Failed to instantiate plugin \"%1\"").arg(pluginId); return false; @@ -235,7 +235,7 @@ bool haveBinCount = m_descriptors[n]->hasFixedBinCount; if (haveBinCount) { - binCount = m_descriptors[n]->binCount; + binCount = (int)m_descriptors[n]->binCount; } m_needAdditionalModels[n] = false; @@ -264,7 +264,8 @@ case Vamp::Plugin::OutputDescriptor::VariableSampleRate: if (m_descriptors[n]->sampleRate != 0.0) { - modelResolution = int(modelRate / m_descriptors[n]->sampleRate + 0.001); + modelResolution = int(round(float(modelRate) / + m_descriptors[n]->sampleRate)); } break; @@ -281,8 +282,8 @@ if (m_descriptors[n]->sampleRate > input->getSampleRate()) { modelResolution = 1; } else { - modelResolution = int(round(input->getSampleRate() / - m_descriptors[n]->sampleRate)); + modelResolution = int(round(float(modelRate) / + m_descriptors[n]->sampleRate)); } break; } @@ -639,7 +640,7 @@ contextDuration = endFrame - contextStart; } - long blockFrame = contextStart; + sv_frame_t blockFrame = contextStart; long prevCompletion = 0; @@ -670,15 +671,15 @@ // << blockFrame << ", endFrame " << endFrame << ", blockSize " // << blockSize << endl; - long completion = - (((blockFrame - contextStart) / stepSize) * 99) / - (contextDuration / stepSize + 1); + int completion = int + ((((blockFrame - contextStart) / stepSize) * 99) / + (contextDuration / stepSize + 1)); // channelCount is either m_input.getModel()->channelCount or 1 if (frequencyDomain) { for (int ch = 0; ch < channelCount; ++ch) { - int column = (blockFrame - startFrame) / stepSize; + int column = int((blockFrame - startFrame) / stepSize); if (fftModels[ch]->getValuesAt(column, reals, imaginaries)) { for (int i = 0; i <= blockSize/2; ++i) { buffers[ch][i*2] = reals[i]; @@ -756,14 +757,15 @@ void FeatureExtractionModelTransformer::getFrames(int channelCount, - long startFrame, long size, + sv_frame_t startFrame, + sv_frame_t size, float **buffers) { - long offset = 0; + sv_frame_t offset = 0; if (startFrame < 0) { for (int c = 0; c < channelCount; ++c) { - for (int i = 0; i < size && startFrame + i < 0; ++i) { + for (sv_frame_t i = 0; i < size && startFrame + i < 0; ++i) { buffers[c][i] = 0.0f; } } @@ -776,7 +778,7 @@ DenseTimeValueModel *input = getConformingInput(); if (!input) return; - long got = 0; + sv_frame_t got = 0; if (channelCount == 1) { @@ -786,7 +788,7 @@ if (m_input.getChannel() == -1 && input->getChannelCount() > 1) { // use mean instead of sum, as plugin input float cc = float(input->getChannelCount()); - for (long i = 0; i < size; ++i) { + for (sv_frame_t i = 0; i < size; ++i) { buffers[0][i + offset] /= cc; } } @@ -816,7 +818,7 @@ void FeatureExtractionModelTransformer::addFeature(int n, - int blockFrame, + sv_frame_t blockFrame, const Vamp::Plugin::Feature &feature) { int inputRate = m_input.getModel()->getSampleRate(); @@ -827,7 +829,7 @@ // << feature.hasDuration << ", duration = " << feature.duration // << endl; - int frame = blockFrame; + sv_frame_t frame = blockFrame; if (m_descriptors[n]->sampleType == Vamp::Plugin::OutputDescriptor::VariableSampleRate) { @@ -849,7 +851,7 @@ ++m_fixedRateFeatureNos[n]; } else { RealTime ts(feature.timestamp.sec, feature.timestamp.nsec); - m_fixedRateFeatureNos[n] = + m_fixedRateFeatureNos[n] = (int) lrint(ts.toDouble() * m_descriptors[n]->sampleRate); } @@ -857,8 +859,9 @@ // << ", m_descriptor->sampleRate = " << m_descriptor->sampleRate // << ", inputRate = " << inputRate // << " giving frame = "; - frame = lrintf((m_fixedRateFeatureNos[n] / m_descriptors[n]->sampleRate) - * int(inputRate)); + frame = lrint((double(m_fixedRateFeatureNos[n]) + / m_descriptors[n]->sampleRate) + * inputRate); } if (frame < 0) { @@ -922,12 +925,12 @@ value = feature.values[index++]; } - float duration = 1; + sv_frame_t duration = 1; if (feature.hasDuration) { duration = Vamp::RealTime::realTime2Frame(feature.duration, inputRate); } else { - if ((int)feature.values.size() > index) { - duration = feature.values[index++]; + if (in_range_for(feature.values, index)) { + duration = lrintf(feature.values[index++]); } } @@ -942,10 +945,11 @@ FlexiNoteModel *model = getConformingOutput<FlexiNoteModel>(n); if (!model) return; - model->addPoint(FlexiNoteModel::Point(frame, value, // value is pitch - lrintf(duration), - velocity / 127.f, - feature.label.c_str())); + model->addPoint(FlexiNoteModel::Point(frame, + value, // value is pitch + duration, + velocity / 127.f, + feature.label.c_str())); // GF: end -- added for flexi note model } else if (isOutput<NoteModel>(n)) { @@ -959,7 +963,7 @@ NoteModel *model = getConformingOutput<NoteModel>(n); if (!model) return; model->addPoint(NoteModel::Point(frame, value, // value is pitch - lrintf(duration), + duration, velocity / 127.f, feature.label.c_str())); } else { @@ -978,14 +982,16 @@ label = QString("[%1] %2").arg(i+1).arg(label); } - model->addPoint(RegionModel::Point(frame, value, - lrintf(duration), + model->addPoint(RegionModel::Point(frame, + value, + duration, label)); } } else { - model->addPoint(RegionModel::Point(frame, value, - lrintf(duration), + model->addPoint(RegionModel::Point(frame, + value, + duration, feature.label.c_str())); } } @@ -1005,7 +1011,7 @@ if (!feature.hasTimestamp && m_fixedRateFeatureNos[n] >= 0) { model->setColumn(m_fixedRateFeatureNos[n], values); } else { - model->setColumn(frame / model->getResolution(), values); + model->setColumn(int(frame / model->getResolution()), values); } } else {