diff dsp/tempotracking/TempoTrackV2.cpp @ 70:c3cdb404f807

* build fixes for win32-x-g++
author cannam
date Tue, 02 Jun 2009 09:53:01 +0000
parents d241e7701c0c
children 054c384d860d
line wrap: on
line diff
--- a/dsp/tempotracking/TempoTrackV2.cpp	Thu May 21 16:39:35 2009 +0000
+++ b/dsp/tempotracking/TempoTrackV2.cpp	Tue Jun 02 09:53:01 2009 +0000
@@ -44,7 +44,7 @@
 
 
     // forwards filtering
-    for (uint i = 0;i < df.size();i++)
+    for (unsigned int i = 0;i < df.size();i++)
     {
         lp_df[i] =  b[0]*df[i] + b[1]*inp1 + b[2]*inp2 - a[1]*out1 - a[2]*out2;
         inp2 = inp1;
@@ -55,12 +55,12 @@
 
     // copy forwards filtering to df...
     // but, time-reversed, ready for backwards filtering
-    for (uint i = 0;i < df.size();i++)
+    for (unsigned int i = 0;i < df.size();i++)
     {
         df[i] = lp_df[df.size()-i-1];
     }
 
-    for (uint i = 0;i < df.size();i++)
+    for (unsigned int i = 0;i < df.size();i++)
     {
         lp_df[i] = 0.;    
     }
@@ -69,7 +69,7 @@
     out1 = 0.; out2 = 0.;
 
   // backwards filetering on time-reversed df
-    for (uint i = 0;i < df.size();i++)
+    for (unsigned int i = 0;i < df.size();i++)
     {
         lp_df[i] =  b[0]*df[i] + b[1]*inp1 + b[2]*inp2 - a[1]*out1 - a[2]*out2;
         inp2 = inp1;
@@ -79,7 +79,7 @@
     }
 
   // write the re-reversed (i.e. forward) version back to df
-    for (uint i = 0;i < df.size();i++)
+    for (unsigned int i = 0;i < df.size();i++)
     {
         df[i] = lp_df[df.size()-i-1];
     }
@@ -96,30 +96,30 @@
     // then call viterbi decoding with weight vector and transition matrix
     // and get best path
 
-    uint wv_len = 128;
+    unsigned int wv_len = 128;
     double rayparam = 43.;
 
     // make rayleigh weighting curve
     d_vec_t wv(wv_len);
-    for (uint i=0; i<wv.size(); i++)
+    for (unsigned int i=0; i<wv.size(); i++)
     {
         wv[i] = (static_cast<double> (i) / pow(rayparam,2.)) * exp((-1.*pow(-static_cast<double> (i),2.)) / (2.*pow(rayparam,2.)));
     }
 
     // beat tracking frame size (roughly 6 seconds) and hop (1.5 seconds)
-    uint winlen = 512;
-    uint step = 128;
+    unsigned int winlen = 512;
+    unsigned int step = 128;
 
     // matrix to store output of comb filter bank, increment column of matrix at each frame
     d_mat_t rcfmat;
     int col_counter = -1;
 
     // main loop for beat period calculation
-    for (uint i=0; i+winlen<df.size(); i+=step)
+    for (unsigned int i=0; i+winlen<df.size(); i+=step)
     {
         // get dfframe
         d_vec_t dfframe(winlen);
-        for (uint k=0; k<winlen; k++)
+        for (unsigned int k=0; k<winlen; k++)
         {
             dfframe[k] = df[i+k];
         }
@@ -129,7 +129,7 @@
   
         rcfmat.push_back( d_vec_t() ); // adds a new column
         col_counter++;
-        for (uint j=0; j<rcf.size(); j++)
+        for (unsigned int j=0; j<rcf.size(); j++)
         {
             rcfmat[col_counter].push_back( rcf[j] );
         }
@@ -156,12 +156,12 @@
     d_vec_t acf(dfframe.size());
 
     
-    for (uint lag=0; lag<dfframe.size(); lag++)
+    for (unsigned int lag=0; lag<dfframe.size(); lag++)
     {
         double sum = 0.;
         double tmp = 0.;
 
-        for (uint n=0; n<(dfframe.size()-lag); n++)
+        for (unsigned int n=0; n<(dfframe.size()-lag); n++)
         {
             tmp = dfframe[n] * dfframe[n+lag];    
             sum += tmp;
@@ -172,7 +172,7 @@
     // now apply comb filtering
     int numelem = 4;
 	
-    for (uint i = 2;i < rcf.size();i++) // max beat period
+    for (unsigned int i = 2;i < rcf.size();i++) // max beat period
     {
         for (int a = 1;a <= numelem;a++) // number of comb elements
         {
@@ -187,14 +187,14 @@
     MathUtilities::adaptiveThreshold(rcf);
   
     double rcfsum =0.;
-    for (uint i=0; i<rcf.size(); i++)
+    for (unsigned int i=0; i<rcf.size(); i++)
     {
         rcf[i] += EPS ;
         rcfsum += rcf[i];
     }
 
     // normalise rcf to sum to unity
-    for (uint i=0; i<rcf.size(); i++)
+    for (unsigned int i=0; i<rcf.size(); i++)
     {
         rcf[i] /= (rcfsum + EPS);
     }
@@ -208,10 +208,10 @@
 
     // make transition matrix
     d_mat_t tmat;
-    for (uint i=0;i<wv.size();i++)
+    for (unsigned int i=0;i<wv.size();i++)
     {
         tmat.push_back ( d_vec_t() ); // adds a new column
-        for (uint j=0; j<wv.size(); j++)
+        for (unsigned int j=0; j<wv.size(); j++)
         {	
             tmat[i].push_back(0.); // fill with zeros initially
         }
@@ -221,9 +221,9 @@
     // formed of Gaussians on diagonal - implies slow tempo change
     double sigma = 8.;
     // don't want really short beat periods, or really long ones
-    for (uint i=20;i <wv.size()-20; i++)
+    for (unsigned int i=20;i <wv.size()-20; i++)
     {
-        for (uint j=20; j<wv.size()-20; j++)
+        for (unsigned int j=20; j<wv.size()-20; j++)
         {	
             double mu = static_cast<double>(i);
             tmat[i][j] = exp( (-1.*pow((j-mu),2.)) / (2.*pow(sigma,2.)) );
@@ -235,11 +235,11 @@
 
     d_mat_t delta;
     i_mat_t psi;
-    for (uint i=0;i <rcfmat.size(); i++)
+    for (unsigned int i=0;i <rcfmat.size(); i++)
     {
         delta.push_back( d_vec_t());
         psi.push_back( i_vec_t());
-        for (uint j=0; j<rcfmat[i].size(); j++)
+        for (unsigned int j=0; j<rcfmat[i].size(); j++)
         {	
             delta[i].push_back(0.); // fill with zeros initially
             psi[i].push_back(0); // fill with zeros initially
@@ -247,37 +247,37 @@
     }
 
 
-    uint T = delta.size();
+    unsigned int T = delta.size();
 
     if (T < 2) return; // can't do anything at all meaningful
 
-    uint Q = delta[0].size();
+    unsigned int Q = delta[0].size();
 
     // initialize first column of delta
-    for (uint j=0; j<Q; j++)
+    for (unsigned int j=0; j<Q; j++)
     {
         delta[0][j] = wv[j] * rcfmat[0][j];
         psi[0][j] = 0;
     }
     
     double deltasum = 0.;
-    for (uint i=0; i<Q; i++)
+    for (unsigned int i=0; i<Q; i++)
     {
         deltasum += delta[0][i];
     }      
-    for (uint i=0; i<Q; i++)
+    for (unsigned int i=0; i<Q; i++)
     {
         delta[0][i] /= (deltasum + EPS);
     }      
 
 
-    for (uint t=1; t<T; t++)
+    for (unsigned int t=1; t<T; t++)
     {
         d_vec_t tmp_vec(Q);
 
-        for (uint j=0; j<Q; j++)
+        for (unsigned int j=0; j<Q; j++)
         {
-            for (uint i=0; i<Q; i++)
+            for (unsigned int i=0; i<Q; i++)
             {
                 tmp_vec[i] = delta[t-1][i] * tmat[j][i];
             }      
@@ -291,11 +291,11 @@
 
         // normalise current delta column
         double deltasum = 0.;
-        for (uint i=0; i<Q; i++)
+        for (unsigned int i=0; i<Q; i++)
         {
             deltasum += delta[t][i];
         }      
-        for (uint i=0; i<Q; i++)
+        for (unsigned int i=0; i<Q; i++)
         {
             delta[t][i] /= (deltasum + EPS);
         }      
@@ -303,7 +303,7 @@
 
     i_vec_t bestpath(T);
     d_vec_t tmp_vec(Q);
-    for (uint i=0; i<Q; i++)
+    for (unsigned int i=0; i<Q; i++)
     {  
         tmp_vec[i] = delta[T-1][i];
     }
@@ -312,7 +312,7 @@
     bestpath[T-1] = get_max_ind(tmp_vec);
  
     // backtrace through index of maximum values in psi
-    for (uint t=T-2; t>0 ;t--)
+    for (unsigned int t=T-2; t>0 ;t--)
     {
         bestpath[t] = psi[t+1][bestpath[t+1]];
     }
@@ -320,11 +320,11 @@
     // weird but necessary hack -- couldn't get above loop to terminate at t >= 0
     bestpath[0] = psi[1][bestpath[1]];
 
-    uint lastind = 0;
-    for (uint i=0; i<T; i++)
+    unsigned int lastind = 0;
+    for (unsigned int i=0; i<T; i++)
     {  
-        uint step = 128;
-        for (uint j=0; j<step; j++)
+        unsigned int step = 128;
+        for (unsigned int j=0; j<step; j++)
         {
             lastind = i*step+j;
             beat_period[lastind] = bestpath[i];
@@ -333,12 +333,12 @@
     }
 
     //fill in the last values...
-    for (uint i=lastind; i<beat_period.size(); i++)
+    for (unsigned int i=lastind; i<beat_period.size(); i++)
     {
         beat_period[i] = beat_period[lastind];
     }
 
-    for (uint i = 0; i < beat_period.size(); i++)
+    for (unsigned int i = 0; i < beat_period.size(); i++)
     {
         tempi.push_back((60. * m_rate / m_increment)/beat_period[i]);
     }
@@ -348,7 +348,7 @@
 TempoTrackV2::get_max_val(const d_vec_t &df)
 {
     double maxval = 0.;
-    for (uint i=0; i<df.size(); i++)
+    for (unsigned int i=0; i<df.size(); i++)
     {
         if (maxval < df[i])
         {
@@ -364,7 +364,7 @@
 {
     double maxval = 0.;
     int ind = 0;
-    for (uint i=0; i<df.size(); i++)
+    for (unsigned int i=0; i<df.size(); i++)
     {
         if (maxval < df[i])
         {
@@ -380,12 +380,12 @@
 TempoTrackV2::normalise_vec(d_vec_t &df)
 {
     double sum = 0.;
-    for (uint i=0; i<df.size(); i++)
+    for (unsigned int i=0; i<df.size(); i++)
     {
         sum += df[i];
     }
     
-    for (uint i=0; i<df.size(); i++)
+    for (unsigned int i=0; i<df.size(); i++)
     {
         df[i]/= (sum + EPS);
     }
@@ -401,7 +401,7 @@
     i_vec_t backlink(df.size()); // backlink (stores best beat locations at each time instant)
     d_vec_t localscore(df.size()); // localscore, for now this is the same as the detection function
 
-    for (uint i=0; i<df.size(); i++)
+    for (unsigned int i=0; i<df.size(); i++)
     {
         localscore[i] = df[i];
         backlink[i] = -1;
@@ -411,7 +411,7 @@
     double alpha = 0.9;
 
     // main loop
-    for (uint i=0; i<localscore.size(); i++)
+    for (unsigned int i=0; i<localscore.size(); i++)
     {
         int prange_min = -2*beat_period[i];
         int prange_max = round(-0.5*beat_period[i]);
@@ -420,7 +420,7 @@
         d_vec_t txwt (prange_max - prange_min + 1);
         d_vec_t scorecands (txwt.size());
 
-        for (uint j=0;j<txwt.size();j++)
+        for (unsigned int j=0;j<txwt.size();j++)
         {
             double mu = static_cast<double> (beat_period[i]);
             txwt[j] = exp( -0.5*pow(tightness * log((round(2*mu)-j)/mu),2));
@@ -447,7 +447,7 @@
 
     // STARTING POINT, I.E. LAST BEAT.. PICK A STRONG POINT IN cumscore VECTOR
     d_vec_t tmp_vec;
-    for (uint i=cumscore.size() - beat_period[beat_period.size()-1] ; i<cumscore.size(); i++)
+    for (unsigned int i=cumscore.size() - beat_period[beat_period.size()-1] ; i<cumscore.size(); i++)
     {
         tmp_vec.push_back(cumscore[i]);
     }  
@@ -471,7 +471,7 @@
     }
   
     // REVERSE SEQUENCE OF IBEATS AND STORE AS BEATS
-    for (uint i=0; i<ibeats.size(); i++)
+    for (unsigned int i=0; i<ibeats.size(); i++)
     { 
         beats.push_back( static_cast<double>(ibeats[ibeats.size()-i-1]) );
     }