Mercurial > hg > silvet
changeset 317:92293058368a livemode
Some small speed improvements for live mode (+ don't use async for it when there's only one template in the EM process: the overhead isn't worth it)
author | Chris Cannam |
---|---|
date | Tue, 28 Apr 2015 13:55:32 +0100 |
parents | f3e10617a60d |
children | ba02cdc839db |
files | .hgsubstate src/Silvet.cpp testdata/timing/run.sh testdata/timing/transform.ttl |
diffstat | 4 files changed, 60 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgsubstate Tue Apr 28 12:21:40 2015 +0100 +++ b/.hgsubstate Tue Apr 28 13:55:32 2015 +0100 @@ -1,3 +1,3 @@ 7a48704e9a0fac1486240f9f7b7e31436a588064 bqvec -4d109d855c671c514dbc4947b0dae7cada112d8c constant-q-cpp +0f612a26bf27b7bf713e060a22cc03b17e0f0f2b constant-q-cpp d25a2e91e9d84aaff25e5d746398232d182d127d flattendynamics
--- a/src/Silvet.cpp Tue Apr 28 12:21:40 2015 +0100 +++ b/src/Silvet.cpp Tue Apr 28 13:55:32 2015 +0100 @@ -505,6 +505,9 @@ params.q = (m_mode == HighQualityMode ? 0.95 : 0.8); params.atomHopFactor = (m_mode == HighQualityMode ? 0.3 : 1.0); params.threshold = 0.0005; + params.decimator = + (m_mode == LiveMode ? + CQParameters::FasterDecimator : CQParameters::BetterDecimator); params.window = CQParameters::Hann; m_cq = new CQSpectrogram(params, CQSpectrogram::InterpolateLinear); @@ -653,31 +656,41 @@ #define MAX_EM_THREADS 8 #endif + int emThreadCount = MAX_EM_THREADS; + if (m_mode == LiveMode && pack.templates.size() == 1) { + // The EM step is probably not slow enough to merit it + emThreadCount = 1; + } + #if (defined(MAX_EM_THREADS) && (MAX_EM_THREADS > 1)) - for (int i = 0; i < width; ) { - typedef future<pair<vector<double>, vector<int>>> EMFuture; - vector<EMFuture> results; - for (int j = 0; j < MAX_EM_THREADS && i + j < width; ++j) { - results.push_back - (async(std::launch::async, - [&](int index) { - return applyEM(pack, filtered.at(index), wantShifts); - }, i + j)); + if (emThreadCount > 1) { + for (int i = 0; i < width; ) { + typedef future<pair<vector<double>, vector<int>>> EMFuture; + vector<EMFuture> results; + for (int j = 0; j < emThreadCount && i + j < width; ++j) { + results.push_back + (async(std::launch::async, + [&](int index) { + return applyEM(pack, filtered.at(index), wantShifts); + }, i + j)); + } + for (int j = 0; j < emThreadCount && i + j < width; ++j) { + auto out = results[j].get(); + localPitches[i+j] = out.first; + if (wantShifts) localBestShifts[i+j] = out.second; + } + i += emThreadCount; } - for (int j = 0; j < MAX_EM_THREADS && i + j < width; ++j) { - auto out = results[j].get(); - localPitches[i+j] = out.first; - if (wantShifts) localBestShifts[i+j] = out.second; - } - i += MAX_EM_THREADS; - } -#else - for (int i = 0; i < width; ++i) { - auto out = applyEM(pack, filtered.at(i), wantShifts); - localPitches[i] = out.first; - if (wantShifts) localBestShifts[i] = out.second; } #endif + + if (emThreadCount == 1) { + for (int i = 0; i < width; ++i) { + auto out = applyEM(pack, filtered.at(i), wantShifts); + localPitches[i] = out.first; + if (wantShifts) localBestShifts[i] = out.second; + } + } for (int i = 0; i < width; ++i) {
--- a/testdata/timing/run.sh Tue Apr 28 12:21:40 2015 +0100 +++ b/testdata/timing/run.sh Tue Apr 28 13:55:32 2015 +0100 @@ -20,6 +20,8 @@ VAMP_PATH=../.. export VAMP_PATH +tfile=transform.ttl + outfile="/tmp/$$" tmpwav="/tmp/$$norm.wav" @@ -32,7 +34,7 @@ --writer csv \ --csv-one-file "$outfile" \ --csv-force \ - --default vamp:silvet:silvet:notes \ + --transform "$tfile" \ "$tmpwav" cat "$outfile" | \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testdata/timing/transform.ttl Tue Apr 28 13:55:32 2015 +0100 @@ -0,0 +1,22 @@ +@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . +@prefix vamp: <http://purl.org/ontology/vamp/> . +@prefix : <#> . + +:transform a vamp:Transform ; + vamp:plugin <http://vamp-plugins.org/rdf/plugins/silvet#silvet> ; + vamp:step_size "1024"^^xsd:int ; + vamp:block_size "1024"^^xsd:int ; + vamp:plugin_version """3""" ; + vamp:parameter_binding [ + vamp:parameter [ vamp:identifier "finetune" ] ; + vamp:value "0"^^xsd:float ; + ] ; + vamp:parameter_binding [ + vamp:parameter [ vamp:identifier "instrument" ] ; + vamp:value "0"^^xsd:float ; # general + ] ; + vamp:parameter_binding [ + vamp:parameter [ vamp:identifier "mode" ] ; + vamp:value "1"^^xsd:float ; # hq + ] ; + vamp:output <http://vamp-plugins.org/rdf/plugins/silvet#silvet_output_notes> .