changeset 199:84c4bb209227

* A few tweaks to fixed-tempo estimator
author cannam
date Wed, 08 Oct 2008 19:48:21 +0000
parents e3e61b7e9661
children a86e777bf9a6
files examples/FixedTempoEstimator.cpp
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/examples/FixedTempoEstimator.cpp	Wed Oct 08 15:26:50 2008 +0000
+++ b/examples/FixedTempoEstimator.cpp	Wed Oct 08 19:48:21 2008 +0000
@@ -287,7 +287,8 @@
 }
 
 float
-FixedTempoEstimator::lag2tempo(int lag) {
+FixedTempoEstimator::lag2tempo(int lag)
+{
     return 60.f / ((lag * m_stepSize) / m_inputSampleRate);
 }
 
@@ -314,7 +315,6 @@
     for (int i = 0; i < n; ++i) {
         feature.timestamp = RealTime::frame2RealTime(i * m_stepSize,
                                                      m_inputSampleRate);
-        std::cerr << "step = " << m_stepSize << ", timestamp = " << feature.timestamp << std::endl;
         feature.values[0] = f[i];
         feature.label = "";
         fs[1].push_back(feature);
@@ -332,11 +332,11 @@
         r[i] /= n - i - 1;
     }
 
-    for (int i = 0; i < n/2; ++i) {
+    for (int i = 1; i < n/2; ++i) {
         feature.timestamp = RealTime::frame2RealTime(i * m_stepSize,
                                                      m_inputSampleRate);
         feature.values[0] = r[i];
-        sprintf(buffer, "%f bpm", lag2tempo(i));
+        sprintf(buffer, "%.1f bpm", lag2tempo(i));
         feature.label = buffer;
         fs[2].push_back(feature);
     }
@@ -388,10 +388,11 @@
 
         float filtered = 0.f;
         
-        for (int j = 1; j <= (n/2)/p1; ++j) {
-            std::cerr << "j = " << j << ", i = " << i << std::endl;
+        for (int j = 1; j <= (n/2 - 1)/i; ++j) {
+//            std::cerr << "j = " << j << ", i = " << i << std::endl;
             filtered += r[i * j];
         }
+        filtered /= (n/2 - 1)/i;
 
         if (i == p0 || filtered > maxp) {
             maxp = filtered;
@@ -401,7 +402,7 @@
         feature.timestamp = RealTime::frame2RealTime(i * m_stepSize,
                                                      m_inputSampleRate);
         feature.values[0] = filtered;
-        sprintf(buffer, "%f bpm", lag2tempo(i));
+        sprintf(buffer, "%.1f bpm", lag2tempo(i));
         feature.label = buffer;
         fs[3].push_back(feature);
     }
@@ -420,6 +421,9 @@
 
     feature.values[0] = tempo;
 
+    sprintf(buffer, "%.1f bpm", tempo);
+    feature.label = buffer;
+
     fs[0].push_back(feature);
 
     return fs;