changeset 13:9fa97de8692a track

Partial updates to new method (but this doesn't currently build)
author Chris Cannam
date Fri, 29 Jun 2012 10:09:19 +0100
parents cb88b9954eec
children 63dde216ea37
files CepstrumPitchTracker.cpp CepstrumPitchTracker.h
diffstat 2 files changed, 71 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/CepstrumPitchTracker.cpp	Thu Jun 28 12:17:18 2012 +0100
+++ b/CepstrumPitchTracker.cpp	Fri Jun 29 10:09:19 2012 +0100
@@ -32,10 +32,9 @@
 using std::string;
 using std::vector;
 
-CepstrumPitchTracker::Hypothesis::Hypothesis(Estimate s)
+CepstrumPitchTracker::Hypothesis::Hypothesis()
 {
-    m_state = Provisional;
-    m_pending.push_back(s);
+    m_state = New;
     m_age = 0;
 }
 
@@ -57,35 +56,57 @@
     return (m_pending.size() > 2);
 }
 
+void
+CepstrumPitchTracker::Hypothesis::advanceTime()
+{
+    ++m_age;
+}
+
 bool
 CepstrumPitchTracker::Hypothesis::test(Estimate s)
 {
-    if (m_state == Rejected || m_state == Expired) {
-        return false;
+    bool accept = false;
+
+    switch (m_state) {
+
+    case New:
+        m_state = Provisional;
+        accept = true;
+        break;
+
+    case Provisional:
+        if (m_age > 3) {
+            m_state = Rejected;
+        } else if (isWithinTolerance(s)) {
+            accept = true;
+        }
+        break;
+        
+    case Satisfied:
+        if (m_age > 3) {
+            m_state = Expired;
+        } else if (isWithinTolerance(s)) {
+            accept = true;
+        }
+        break;
+
+    case Rejected:
+        break;
+
+    case Expired:
+        break;
     }
 
-    if (++m_age > 3) {
-        if (m_state == Satisfied) {
-            m_state = Expired;
-        } else {
-            m_state = Rejected;
+    if (accept) {
+        m_pending.push_back(s);
+        m_age = 0;
+        if (m_state == Provisional && isSatisfied()) {
+            m_state = Satisfied;
         }
-        return false;
     }
 
-    if (isWithinTolerance(s)) {
-        m_pending.push_back(s);
-        if (m_state == Provisional) {
-            if (isSatisfied()) {
-                m_state == Satisfied;
-            }
-        }
-        m_age = 0;
-        return true;
-    }
-    
-    return false;
-}
+    return accept;
+}        
 
 CepstrumPitchTracker::Hypothesis::State
 CepstrumPitchTracker::Hypothesis::getState()
@@ -116,7 +137,6 @@
     m_binFrom(0),
     m_binTo(0),
     m_bins(0),
-    m_accepted(0),
     m_history(0),
     m_prevpeak(0),
     m_prevprop(0)
@@ -434,6 +454,25 @@
         }
     }
 
+    if (maxbin < 0) return fs;
+
+    double peakfreq = m_inputSampleRate / (maxbin + m_binFrom);
+    Hypothesis::Estimate e;
+    e.freq = peakfreq;
+    e.time = timestamp;
+
+    m_accepted.advanceTime();
+    for (int i = 0; i < m_possible.size(); ++i) {
+        m_possible[i].advanceTime();
+    }
+
+    if (m_accepted.test(e)) {
+        return fs;
+    }
+
+    //...
+
+/*
     bool accepted = false;
 
     if (maxbin >= 0) {
@@ -465,7 +504,7 @@
             m_prevprop = pp;
         }
     }
-            
+*/
 //    std::cerr << "peakProportion = " << peakProportion << std::endl;
 //    std::cerr << "peak = " << m_inputSampleRate / (maxbin + m_binFrom) << std::endl;
 //    std::cerr << "bins = " << m_bins << std::endl;
--- a/CepstrumPitchTracker.h	Thu Jun 28 12:17:18 2012 +0100
+++ b/CepstrumPitchTracker.h	Fri Jun 29 10:09:19 2012 +0100
@@ -84,10 +84,11 @@
         };
         typedef std::vector<Estimate> Estimates;
         
-        Hypothesis(Estimate s);
+        Hypothesis();
         ~Hypothesis();
 
         enum State {
+            New,
             Provisional,
             Satisfied,
             Rejected,
@@ -95,6 +96,9 @@
         };
 
         bool test(Estimate);
+
+        void advanceTime();
+
         State getState();
 
         Estimates getAcceptedEstimates();
@@ -110,7 +114,7 @@
 
     typedef std::vector<Hypothesis> Hypotheses;
     Hypotheses m_possible;
-    Hypothesis *m_accepted;
+    Hypothesis m_accepted;
 
     double **m_history;