Mercurial > hg > match-vamp
changeset 60:faa523be20f9 refactors_no_float
Update both Feeders so as to recognise the end of one input before the other has ended. MatchFeeder does this by detecting trailing silence (as both its inputs are technically the same length since the shorter is zero-padded) and reporting that to Finder. MatchFeatureFeeder simply recognises missing features at the end and won't queue them.
author | Chris Cannam |
---|---|
date | Fri, 14 Nov 2014 13:53:58 +0000 |
parents | 47f7649ab9d5 |
children | 19a93b15fcc3 ad417dd05e0b a540137d393b |
files | src/Finder.cpp src/Finder.h src/MatchFeatureFeeder.cpp src/MatchFeatureFeeder.h src/MatchFeeder.cpp src/MatchFeeder.h |
diffstat | 6 files changed, 80 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Finder.cpp Fri Nov 14 10:25:57 2014 +0000 +++ b/src/Finder.cpp Fri Nov 14 13:53:58 2014 +0000 @@ -31,6 +31,8 @@ index2 = 0; rowRange = new int[2]; colRange = new int[2]; + duration1 = -1; + duration2 = -1; } // constructor Finder::~Finder() @@ -39,6 +41,13 @@ delete[] colRange; } +void +Finder::setDurations(int d1, int d2) +{ + duration1 = d1; + duration2 = d2; +} + bool Finder::find(int i1, int i2) { @@ -252,6 +261,13 @@ int x = pm2->getFrameCount() - 1; int y = pm1->getFrameCount() - 1; + if (duration2 > 0 && duration2 < pm2->getFrameCount()) { + x = duration2 - 1; + } + if (duration1 > 0 && duration1 < pm1->getFrameCount()) { + y = duration1 - 1; + } + recalculatePathCostMatrix(0, 0, y, x); pathx.clear();
--- a/src/Finder.h Fri Nov 14 10:25:57 2014 +0000 +++ b/src/Finder.h Fri Nov 14 13:53:58 2014 +0000 @@ -34,12 +34,22 @@ int index1, index2, bestRow, bestCol; int *rowRange; int *colRange; + int duration1, duration2; public: Finder(Matcher *p1, Matcher *p2); ~Finder(); + /** + * Tell the finder that one or both files ends sooner than it + * thought, i.e. that some of the trailing features are silence or + * otherwise to be ignored. d1 and d2 are feature frame counts for + * matchers 1 and 2 respectively. If this is not called, the full + * duration of each input will be considered. + */ + void setDurations(int d1, int d2); + /** Sets up the instance variables to point to the given * coordinate in the distance matrix. *
--- a/src/MatchFeatureFeeder.cpp Fri Nov 14 10:25:57 2014 +0000 +++ b/src/MatchFeatureFeeder.cpp Fri Nov 14 13:53:58 2014 +0000 @@ -38,10 +38,15 @@ // processing up to one feature per matcher, until a queue is // empty. Then it returns, to be called again with more data. - q1.push(f1); - q2.push(f2); + if (!f1.empty()) { + q1.push(f1); + } + + if (!f2.empty()) { + q2.push(f2); + } - while (!q1.empty() && !q2.empty()) { + while (!q1.empty() || !q2.empty()) { feedBlock(); } } @@ -49,11 +54,14 @@ void MatchFeatureFeeder::feedBlock() { - if (pm1->m_frameCount < pm1->m_blockSize) { // fill initial block + if (q1.empty()) { // ended + feed2(); + } else if (q2.empty()) { // ended + feed1(); + } else if (pm1->m_frameCount < pm1->m_blockSize) { // fill initial block feed1(); feed2(); - } - else if (pm1->m_runCount >= pm1->m_params.maxRunCount) { // slope constraints + } else if (pm1->m_runCount >= pm1->m_params.maxRunCount) { // slope constraints feed2(); } else if (pm2->m_runCount >= pm2->m_params.maxRunCount) { feed1();
--- a/src/MatchFeatureFeeder.h Fri Nov 14 10:25:57 2014 +0000 +++ b/src/MatchFeatureFeeder.h Fri Nov 14 13:53:58 2014 +0000 @@ -33,6 +33,13 @@ * respectively (depending on their advance status). Matchers must * have been constructed using the external featureSize * constructor. + * + * f1 and f2 are normally expected to have the same number of + * values, and that number should be the featureSize passed to the + * constructors for both Matchers. The exception is when one input + * ends before the other one: subsequent calls should pass a + * feature vector as normal for the input that is still going on, + * and an empty vector for the one that has ended. */ void feed(std::vector<double> f1, std::vector<double> f2);
--- a/src/MatchFeeder.cpp Fri Nov 14 10:25:57 2014 +0000 +++ b/src/MatchFeeder.cpp Fri Nov 14 13:53:58 2014 +0000 @@ -19,7 +19,7 @@ using std::vector; MatchFeeder::MatchFeeder(Matcher *m1, Matcher *m2) : - pm1(m1), pm2(m2) + pm1(m1), pm2(m2), n(0), lastIn1(0), lastIn2(0) { fftSize = m1->m_params.fftSize; finder = new Finder(m1, m2); @@ -53,7 +53,7 @@ prepare(input); - while (!q1.empty() && !q2.empty()) { + while (!q1.empty() || !q2.empty()) { // std::cerr << "MatchFeeder::feed: q1 " << q1.size() << " q2 " << q2.size() << std::endl; (void)feedBlock(); } @@ -66,7 +66,7 @@ Features all; - while (!q1.empty() && !q2.empty()) { + while (!q1.empty() || !q2.empty()) { Features ff = feedBlock(); all.f1.insert(all.f1.end(), ff.f1.begin(), ff.f1.end()); all.f2.insert(all.f2.end(), ff.f2.begin(), ff.f2.end()); @@ -78,17 +78,36 @@ void MatchFeeder::prepare(const float *const *input) { + float threshold = 1e-5; + float *block = new float[fftSize+2]; + float rms = 0; + for (size_t i = 0; i < fftSize+2; ++i) { block[i] = input[0][i]; + rms += block[i] * block[i]; + } + rms = sqrtf(rms / (fftSize+2)); + if (rms > threshold) { + lastIn1 = n; } q1.push(block); block = new float[fftSize+2]; + rms = 0; + for (size_t i = 0; i < fftSize+2; ++i) { block[i] = input[1][i]; + rms += block[i] * block[i]; + } + rms = sqrtf(rms / (fftSize+2)); + if (rms > threshold) { + lastIn2 = n; } q2.push(block); + + ++n; + finder->setDurations(lastIn1, lastIn2); } MatchFeeder::Features @@ -97,16 +116,15 @@ Features ff; vector<double> f1, f2; - if (pm1->m_frameCount < pm1->m_blockSize) { // fill initial block + if (q1.empty()) { + feed2(); + } else if (q2.empty()) { + feed1(); + } else if (pm1->m_frameCount < pm1->m_blockSize) { // fill initial block // std::cerr << "feeding initial block" << std::endl; f1 = feed1(); f2 = feed2(); - } -//!!! } else if (pm1->atEnd) { -// feed2(); -//!!! } else if (pm2->atEnd) -// feed1(); - else if (pm1->m_runCount >= pm1->m_params.maxRunCount) { // slope constraints + } else if (pm1->m_runCount >= pm1->m_params.maxRunCount) { // slope constraints // std::cerr << "pm1 too slopey" << std::endl; f2 = feed2(); } else if (pm2->m_runCount >= pm2->m_params.maxRunCount) {
--- a/src/MatchFeeder.h Fri Nov 14 10:25:57 2014 +0000 +++ b/src/MatchFeeder.h Fri Nov 14 13:53:58 2014 +0000 @@ -47,7 +47,7 @@ * calculated by the two feeders. */ Features feedAndGetFeatures(const float *const *input); - + Finder *getFinder() { return finder; } protected: @@ -66,6 +66,10 @@ std::queue<float *> q1; std::queue<float *> q2; + + int n; + int lastIn1; + int lastIn2; }; #endif