[Sv1-commits] SF.net SVN: sv1:[1203] runner/trunk
Brought to you by:
cannam
From: <ca...@us...> - 2008-09-12 16:27:25
|
Revision: 1203 http://sv1.svn.sourceforge.net/sv1/?rev=1203&view=rev Author: cannam Date: 2008-09-12 16:27:22 +0000 (Fri, 12 Sep 2008) Log Message: ----------- * Initial support for summary segments Modified Paths: -------------- runner/trunk/FeatureExtractionManager.cpp runner/trunk/FeatureExtractionManager.h runner/trunk/main.cpp runner/trunk/tests/test-summaries.sh Modified: runner/trunk/FeatureExtractionManager.cpp =================================================================== --- runner/trunk/FeatureExtractionManager.cpp 2008-08-08 14:54:48 UTC (rev 1202) +++ runner/trunk/FeatureExtractionManager.cpp 2008-09-12 16:27:22 UTC (rev 1203) @@ -93,7 +93,8 @@ } bool FeatureExtractionManager::setSummaryTypes(const set<string> &names, - bool summariesOnly) + bool summariesOnly, + const PluginSummarisingAdapter::SegmentBoundaries &boundaries) { for (SummaryNameSet::const_iterator i = names.begin(); i != names.end(); ++i) { @@ -104,6 +105,7 @@ } m_summaries = names; m_summariesOnly = summariesOnly; + m_boundaries = boundaries; return true; } @@ -206,7 +208,10 @@ plugin = new PluginChannelAdapter(plugin); if (!m_summaries.empty()) { - plugin = new PluginSummarisingAdapter(plugin); + PluginSummarisingAdapter *adapter = + new PluginSummarisingAdapter(plugin); + adapter->setSummarySegmentBoundaries(m_boundaries); + plugin = adapter; } if (!plugin->initialise(m_channels, m_blockSize, m_blockSize)) { @@ -527,7 +532,8 @@ sni != m_summaries.end(); ++sni) { featureSet.clear(); featureSet = adapter->getSummaryForAllOutputs - (getSummaryType(*sni)); + (getSummaryType(*sni), + PluginSummarisingAdapter::ContinuousTimeAverage); writeFeatures(audioSource, plugin, featureSet, *sni); } } Modified: runner/trunk/FeatureExtractionManager.h =================================================================== --- runner/trunk/FeatureExtractionManager.h 2008-08-08 14:54:48 UTC (rev 1202) +++ runner/trunk/FeatureExtractionManager.h 2008-09-12 16:27:22 UTC (rev 1203) @@ -21,6 +21,7 @@ #include <string> #include <vamp-sdk/Plugin.h> +#include <vamp-sdk/hostext/PluginSummarisingAdapter.h> #include <transform/Transform.h> using std::vector; @@ -41,7 +42,8 @@ void setDefaultSampleRate(int sampleRate); bool setSummaryTypes(const set<string> &summaryTypes, - bool summariesOnly); + bool summariesOnly, + const Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries &boundaries); bool addFeatureExtractor(Transform transform, const vector<FeatureWriter*> &writers); @@ -86,6 +88,7 @@ typedef set<std::string> SummaryNameSet; SummaryNameSet m_summaries; bool m_summariesOnly; + Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries m_boundaries; void writeFeatures(QString audioSource, Vamp::Plugin *, Modified: runner/trunk/main.cpp =================================================================== --- runner/trunk/main.cpp 2008-08-08 14:54:48 UTC (rev 1202) +++ runner/trunk/main.cpp 2008-09-12 16:27:22 UTC (rev 1203) @@ -42,6 +42,8 @@ #include "FeatureWriter.h" #include "FeatureWriterFactory.h" +#include <vamp-sdk/hostext/PluginSummarisingAdapter.h> + // Desired options: // // * output preference: @@ -206,6 +208,10 @@ cerr << " --summary-only Write only summary features; do not write the regular" << endl; cerr << " result features." << endl; cerr << endl; + cerr << " --segments <A>,<B>[,...]" << endl; + cerr << " Summarise in segments, with segment boundaries" << endl; + cerr << " at A, B, ... seconds." << endl; + cerr << endl; cerr << " -m, --multiplex If multiple input audio files are given, use mono" << endl; cerr << " mixdowns of all files as the input channels for a single" << endl; cerr << " invocation of each transform, instead of running the" << endl; @@ -331,6 +337,7 @@ QString myname = args[0]; myname = QFileInfo(myname).baseName(); QStringList otherArgs; + Vamp::HostExt::PluginSummarisingAdapter::SegmentBoundaries boundaries; QString helpStr = myname + ": use -h or --help option for help"; @@ -404,6 +411,26 @@ } else if (arg == "--summary-only") { summaryOnly = true; continue; + } else if (arg == "--segments") { + if (last) { + cerr << myname.toStdString() << ": argument expected for \"" + << arg.toStdString() << "\" option" << endl; + cerr << helpStr.toStdString() << endl; + exit(2); + } else { + string segmentSpec = args[++i].toStdString(); + QStringList segmentStrs = QString(segmentSpec.c_str()).split(','); + for (int j = 0; j < segmentStrs.size(); ++j) { + bool good = false; + boundaries.insert(Vamp::RealTime::fromSeconds + (segmentStrs[j].toDouble(&good))); + if (!good) { + cerr << myname.toStdString() << ": segment boundaries must be numeric" << endl; + cerr << helpStr.toStdString() << endl; + exit(2); + } + } + } } else if (arg == "-m" || arg == "--multiplex") { multiplex = true; cerr << myname.toStdString() @@ -463,10 +490,22 @@ exit(2); } + if (!boundaries.empty()) { + if (requestedSummaryTypes.empty()) { + cerr << myname.toStdString() + << ": summary segment boundaries provided, but no summary type specified" + << endl; + cerr << helpStr.toStdString() << endl; + exit(2); + } + } + FeatureExtractionManager manager; if (!requestedSummaryTypes.empty()) { - if (!manager.setSummaryTypes(requestedSummaryTypes, summaryOnly)) { + if (!manager.setSummaryTypes(requestedSummaryTypes, + summaryOnly, + boundaries)) { cerr << myname.toStdString() << ": failed to set requested summary types" << endl; exit(1); Modified: runner/trunk/tests/test-summaries.sh =================================================================== --- runner/trunk/tests/test-summaries.sh 2008-08-08 14:54:48 UTC (rev 1202) +++ runner/trunk/tests/test-summaries.sh 2008-09-12 16:27:22 UTC (rev 1203) @@ -10,6 +10,16 @@ fail() { echo "Test failed: $1" + if [ -n "$2" -a -n "$3" ]; then + echo "Output follows:" + echo "--" + cat $2 + echo "--" + echo "Expected output follows:" + echo "--" + cat $3 + echo "--" + fi exit 1 } @@ -21,19 +31,19 @@ fail "Fails to run transform $transform" cmp -s $tmpfile ${expected}.csv || \ - fail "Output mismatch for transform $transform" + fail "Output mismatch for transform $transform" $tmpfile ${expected}.csv $r -t $transform -w csv --csv-stdout -S mean $infile > $tmpfile 2>/dev/null || \ fail "Fails to run transform $transform with summary type mean" cmp -s $tmpfile ${expected}-with-mean.csv || \ - fail "Output mismatch for transform $transform with summary type mean" + fail "Output mismatch for transform $transform with summary type mean" $tmpfile ${expected}-with-mean.csv $r -t $transform -w csv --csv-stdout -S min -S max -S mean -S median -S mode -S sum -S variance -S sd -S count --summary-only $infile > $tmpfile 2>/dev/null || \ fail "Fails to run transform $transform with all summary types and summary-only" cmp -s $tmpfile ${expected}-all-summaries-only.csv || \ - fail "Output mismatch for transform $transform with all summary types and summary-only" + fail "Output mismatch for transform $transform with all summary types and summary-only" $tmpfile ${expected}-all-summaries-only.csv exit 0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |