diff Matcher.cpp @ 23:64c4c0cf80c9

Add alternate Matcher API calls to provide external feature data
author Chris Cannam
date Fri, 10 Oct 2014 16:27:45 +0100
parents b15106b0abcd
children 9f60d097f0b2
line wrap: on
line diff
--- a/Matcher.cpp	Fri Oct 10 16:27:29 2014 +0100
+++ b/Matcher.cpp	Fri Oct 10 16:27:45 2014 +0100
@@ -37,6 +37,40 @@
     ltAverage = 0;
     frameCount = 0;
     runCount = 0;
+    freqMapSize = 0;
+    externalFeatureSize = 0;
+    featureSize = 0;
+    blockSize = 0;
+    scale = 90;
+
+    blockSize = lrint(params.blockTime / params.hopTime);
+#ifdef DEBUG_MATCHER
+    cerr << "Matcher: blockSize = " << blockSize << endl;
+#endif
+
+    distance = 0;
+    bestPathCost = 0;
+    distYSizes = 0;
+    distXSize = 0;
+
+    initialised = false;
+}
+
+Matcher::Matcher(Parameters parameters, Matcher *p, int featureSize) :
+    params(parameters),
+    externalFeatureSize(featureSize)
+{
+#ifdef DEBUG_MATCHER
+    cerr << "Matcher::Matcher(" << params.sampleRate << ", " << p << ", " << featureSize << ")" << endl;
+#endif
+
+    otherMatcher = p;	// the first matcher will need this to be set later
+    firstPM = (!p);
+    ltAverage = 0;
+    frameCount = 0;
+    runCount = 0;
+    freqMapSize = 0;
+    featureSize = 0;
     blockSize = 0;
     scale = 90;
 
@@ -52,7 +86,7 @@
 
     initialised = false;
 
-} // default constructor
+} 
 
 Matcher::~Matcher()
 {
@@ -85,13 +119,17 @@
 
     initialised = true;
 
-    freqMapSize = getFeatureSize(params);
+    if (externalFeatureSize == 0) {
+        freqMapSize = getFeatureSizeFor(params);
+        featureSize = freqMapSize;
+        makeFreqMap();
+    } else {
+        featureSize = externalFeatureSize;
+    }
 
-    makeFreqMap();
-
-    initVector<double>(prevFrame, freqMapSize);
-    initVector<double>(newFrame, freqMapSize);
-    initMatrix<double>(frames, blockSize, freqMapSize);
+    initVector<double>(prevFrame, featureSize);
+    initVector<double>(newFrame, featureSize);
+    initMatrix<double>(frames, blockSize, featureSize);
     initVector<double>(totalEnergies, blockSize);
 
     int distSize = (params.maxRunCount + 1) * blockSize;
@@ -124,6 +162,7 @@
 Matcher::makeFreqMap()
 {
     initVector<int>(freqMap, params.fftSize/2 + 1);
+
     if (params.useChromaFrequencyMap) {
 #ifdef DEBUG_MATCHER
         cerr << "makeFreqMap: calling makeChromaFrequencyMap" << endl;
@@ -138,7 +177,7 @@
 } // makeFreqMap()
 
 int
-Matcher::getFeatureSize(Parameters params)
+Matcher::getFeatureSizeFor(Parameters params)
 {
     if (params.useChromaFrequencyMap) {
         return 13;
@@ -205,13 +244,16 @@
 
     calcAdvance();
 
-    if ((frameCount % 100) == 0) {
-        if (!silent) {
-            cerr << "Progress:" << frameCount << " " << ltAverage << endl;
-        }
-    }
+    return processedFrame;
+}
 
-    return processedFrame;
+void
+Matcher::consumeFeatureVector(std::vector<double> feature)
+{
+    if (!initialised) init();
+    int frameIndex = frameCount % blockSize; 
+    frames[frameIndex] = feature;
+    calcAdvance();
 }
 
 vector<double> 
@@ -275,6 +317,12 @@
 
     frames[frameIndex] = processedFrame;
 
+    if ((frameCount % 100) == 0) {
+        if (!silent) {
+            cerr << "Progress:" << frameCount << " " << ltAverage << endl;
+        }
+    }
+
     return processedFrame;
 }
 
@@ -417,7 +465,7 @@
 {
     double d = 0;
     double sum = 0;
-    for (int i = 0; i < freqMapSize; i++) {
+    for (int i = 0; i < featureSize; i++) {
         d += fabs(f1[i] - f2[i]);
         sum += f1[i] + f2[i];
     }