Mercurial > hg > sonic-annotator
diff runner/FeatureExtractionManager.cpp @ 99:526feaad5820 start-duration
Start time and duration now working
author | Chris Cannam |
---|---|
date | Wed, 01 Oct 2014 14:06:40 +0100 |
parents | 03b1d83fca29 |
children | 010fbf2a3fba |
line wrap: on
line diff
--- a/runner/FeatureExtractionManager.cpp Wed Oct 01 09:27:21 2014 +0100 +++ b/runner/FeatureExtractionManager.cpp Wed Oct 01 14:06:40 2014 +0100 @@ -373,25 +373,37 @@ bool FeatureExtractionManager::addFeatureExtractorFromFile (QString transformXmlFile, const vector<FeatureWriter*> &writers) { - RDFTransformFactory factory - (QUrl::fromLocalFile(QFileInfo(transformXmlFile).absoluteFilePath()) - .toString()); - ProgressPrinter printer("Parsing transforms RDF file"); - std::vector<Transform> transforms = factory.getTransforms(&printer); - if (!factory.isOK()) { - cerr << "WARNING: FeatureExtractionManager::addFeatureExtractorFromFile: Failed to parse transforms file: " << factory.getErrorString().toStdString() << endl; - if (factory.isRDF()) { - return false; // no point trying it as XML - } + bool tryRdf = true; + + if (transformXmlFile.endsWith(".xml") || transformXmlFile.endsWith(".XML")) { + // We don't support RDF-XML (and nor does the underlying + // parser library) so skip the RDF parse if the filename + // suggests XML, to avoid puking out a load of errors from + // feeding XML to a Turtle parser + tryRdf = false; } - if (!transforms.empty()) { - bool success = true; - for (int i = 0; i < (int)transforms.size(); ++i) { - if (!addFeatureExtractor(transforms[i], writers)) { - success = false; + + if (tryRdf) { + RDFTransformFactory factory + (QUrl::fromLocalFile(QFileInfo(transformXmlFile).absoluteFilePath()) + .toString()); + ProgressPrinter printer("Parsing transforms RDF file"); + std::vector<Transform> transforms = factory.getTransforms(&printer); + if (!factory.isOK()) { + cerr << "WARNING: FeatureExtractionManager::addFeatureExtractorFromFile: Failed to parse transforms file: " << factory.getErrorString().toStdString() << endl; + if (factory.isRDF()) { + return false; // no point trying it as XML } } - return success; + if (!transforms.empty()) { + bool success = true; + for (int i = 0; i < (int)transforms.size(); ++i) { + if (!addFeatureExtractor(transforms[i], writers)) { + success = false; + } + } + return success; + } } QFile file(transformXmlFile); @@ -592,6 +604,10 @@ // cerr << "file has " << frameCount << " frames" << endl; + int earliestStartFrame = 0; + int latestEndFrame = frameCount; + bool haveExtents = false; + for (PluginMap::iterator pi = m_plugins.begin(); pi != m_plugins.end(); ++pi) { @@ -605,12 +621,22 @@ const Transform &transform = ti->first; - //!!! we may want to set the start and duration times for extraction - // in the transform record (defaults of zero indicate extraction - // from the whole file) -// transform.setStartTime(RealTime::zeroTime); -// transform.setDuration -// (RealTime::frame2RealTime(reader->getFrameCount(), m_sampleRate)); + int startFrame = RealTime::realTime2Frame + (transform.getStartTime(), m_sampleRate); + int duration = RealTime::realTime2Frame + (transform.getDuration(), m_sampleRate); + if (duration == 0) { + duration = frameCount - startFrame; + } + + if (!haveExtents || startFrame < earliestStartFrame) { + earliestStartFrame = startFrame; + } + if (!haveExtents || startFrame + duration > latestEndFrame) { + latestEndFrame = startFrame + duration; + } + + haveExtents = true; string outputId = transform.getOutput().toStdString(); if (m_pluginOutputs[plugin].find(outputId) == @@ -638,33 +664,8 @@ } } - long startFrame = 0; - long endFrame = frameCount; - -/*!!! No -- there is no single transform to pull this stuff from -- - * the transforms may have various start and end times, need to be far - * cleverer about this if we're going to support them - - RealTime trStartRT = transform.getStartTime(); - RealTime trDurationRT = transform.getDuration(); - - long trStart = RealTime::realTime2Frame(trStartRT, m_sampleRate); - long trDuration = RealTime::realTime2Frame(trDurationRT, m_sampleRate); - - if (trStart == 0 || trStart < startFrame) { - trStart = startFrame; - } - - if (trDuration == 0) { - trDuration = endFrame - trStart; - } - if (trStart + trDuration > endFrame) { - trDuration = endFrame - trStart; - } - - startFrame = trStart; - endFrame = trStart + trDuration; -*/ + int startFrame = earliestStartFrame; + int endFrame = latestEndFrame; for (PluginMap::iterator pi = m_plugins.begin(); pi != m_plugins.end(); ++pi) { @@ -688,10 +689,10 @@ ProgressPrinter extractionProgress("Extracting and writing features..."); int progress = 0; - for (long i = startFrame; i < endFrame; i += m_blockSize) { + for (int i = startFrame; i < endFrame; i += m_blockSize) { //!!! inefficient, although much of the inefficiency may be - // susceptible to optimisation + // susceptible to compiler optimisation SampleBlock frames; reader->getInterleavedFrames(i, m_blockSize, frames);