# HG changeset patch # User Chris Cannam # Date 1417790997 0 # Node ID 96c2191a85cc5a6b084e20d1a10811338fcaf964 # Parent 69b16c0bc903de81e0982687f249a71e978d9918 Confidence inflection points diff -r 69b16c0bc903 -r 96c2191a85cc Makefile.linux --- a/Makefile.linux Fri Dec 05 13:40:23 2014 +0000 +++ b/Makefile.linux Fri Dec 05 14:49:57 2014 +0000 @@ -1,6 +1,6 @@ -CXXFLAGS += -fPIC -ffast-math -O3 -Wall -Werror -#CXXFLAGS += -fPIC -g -Wall -Werror -Wfloat-conversion -DPERFORM_ERROR_CHECKS=1 +#CXXFLAGS += -fPIC -ffast-math -O3 -Wall -Werror +CXXFLAGS += -fPIC -g -Wall -Werror -Wfloat-conversion -DPERFORM_ERROR_CHECKS=1 LDFLAGS += -shared -Wl,-Bstatic -lvamp-sdk -Wl,-Bdynamic -Wl,-Bsymbolic -Wl,-z,defs -lpthread -Wl,--version-script=vamp-plugin.map diff -r 69b16c0bc903 -r 96c2191a85cc src/FeatureConditioner.h --- a/src/FeatureConditioner.h Fri Dec 05 13:40:23 2014 +0000 +++ b/src/FeatureConditioner.h Fri Dec 05 14:49:57 2014 +0000 @@ -88,7 +88,10 @@ * state: use one FeatureConditioner per audio source, and construct * a new one for each new source. */ - FeatureConditioner(Parameters parameters) : m_params(parameters) { } + FeatureConditioner(Parameters parameters) : + m_params(parameters), + m_ltAverage(0.0) + { } /** * Process the given feature and return the conditioned feature. diff -r 69b16c0bc903 -r 96c2191a85cc src/Finder.cpp --- a/src/Finder.cpp Fri Dec 05 13:40:23 2014 +0000 +++ b/src/Finder.cpp Fri Dec 05 14:49:57 2014 +0000 @@ -342,7 +342,7 @@ distances.clear(); #ifdef PERFORM_ERROR_CHECKS - checkAndReport(); +// checkAndReport(); #endif int ex = m_m->getOtherFrameCount() - 1; diff -r 69b16c0bc903 -r 96c2191a85cc src/MatchVampPlugin.cpp --- a/src/MatchVampPlugin.cpp Fri Dec 05 13:40:23 2014 +0000 +++ b/src/MatchVampPlugin.cpp Fri Dec 05 14:49:57 2014 +0000 @@ -20,6 +20,7 @@ #include "MatchFeatureFeeder.h" #include "FeatureExtractor.h" #include "Path.h" +#include "MedianFilter.h" #include #include @@ -547,7 +548,7 @@ return list; } -static double +static float magOf(const vector &f) { double mag = 0.0; @@ -555,7 +556,7 @@ mag += f[j] * f[j]; } mag = sqrt(mag); - return mag; + return float(mag); } MatchVampPlugin::FeatureSet @@ -654,17 +655,13 @@ int x = pathx[i]; int y = pathy[i]; - double magSum = m_mag1[x] + m_mag2[y]; - double distance = distances[i]; + float magSum = m_mag1[x] + m_mag2[y]; + float distance = distances[i]; float c = magSum - distance * magSum; confidence.push_back(c); if (x != prevx) { Feature f; - f.values.push_back(c); - returnFeatures[m_confidenceOutNo].push_back(f); - - f.values.clear(); f.values.push_back(magSum); returnFeatures[m_magOutNo].push_back(f); @@ -676,31 +673,60 @@ prevx = x; prevy = y; } + + confidence = MedianFilter::filter(3, confidence); + vector filtered = MedianFilter::filter(50, confidence); + for (int i = 0; i < len; ++i) { + confidence[i] -= filtered[i]; + if (confidence[i] < 0.f) { + confidence[i] = 0.f; + } + } + vector deriv; + deriv.resize(len, 0.f); + for (int i = 1; i < len; ++i) { + deriv[i] = confidence[i] - confidence[i-1]; + } + vector inflections; + for (int i = 1; i < len; ++i) { + if (deriv[i-1] > 0 && deriv[i] < 0) { + inflections.push_back(i); + } + } - map pinpoints; - - vector csorted = confidence; - sort(csorted.begin(), csorted.end()); - float thresh = csorted[int(csorted.size() * 0.7)]; // 70th percentile - - for (int i = 1; i + 1 < len; ++i) { + for (int i = 0; i < len; ++i) { int x = pathx[i]; int y = pathy[i]; - if (confidence[i] > thresh && - confidence[i] > confidence[i-1] && - confidence[i] >= confidence[i+1]) { + if (x != prevx) { + Feature f; + float c = confidence[i]; + f.values.push_back(c); + returnFeatures[m_confidenceOutNo].push_back(f); + } - pinpoints[x] = y; + prevx = x; + prevy = y; + } + + map pinpoints; + + for (int ii = 0; ii < int(inflections.size()); ++ii) { + + int i = inflections[ii]; + + int x = pathx[i]; + int y = pathy[i]; + + pinpoints[x] = y; - Vamp::RealTime xt = Vamp::RealTime::frame2RealTime - (x * m_stepSize, lrintf(m_inputSampleRate)); - Feature feature; - feature.hasTimestamp = true; - feature.timestamp = m_startTime + xt; - returnFeatures[m_confPeakOutNo].push_back(feature); - } + Vamp::RealTime xt = Vamp::RealTime::frame2RealTime + (x * m_stepSize, lrintf(m_inputSampleRate)); + Feature feature; + feature.hasTimestamp = true; + feature.timestamp = m_startTime + xt; + returnFeatures[m_confPeakOutNo].push_back(feature); } finder->smoothWithPinPoints(pinpoints);