changeset 479:7e52c034cf62

Untabify, indent, tidy
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 31 May 2019 10:35:08 +0100
parents c92718cc6ef1
children 175e51ae78eb
files dsp/tempotracking/DownBeat.cpp dsp/tempotracking/TempoTrack.cpp dsp/tempotracking/TempoTrack.h dsp/tempotracking/TempoTrackV2.cpp
diffstat 4 files changed, 464 insertions(+), 622 deletions(-) [+]
line wrap: on
line diff
--- a/dsp/tempotracking/DownBeat.cpp	Thu May 30 18:40:16 2019 +0100
+++ b/dsp/tempotracking/DownBeat.cpp	Fri May 31 10:35:08 2019 +0100
@@ -47,7 +47,6 @@
     if (m_beatframesize < 2) {
         m_beatframesize = 2;
     }
-//    std::cerr << "rate = " << m_rate << ", dec = " << decimationFactor << ", bfs = " << m_beatframesize << std::endl;
     m_beatframe = new double[m_beatframesize];
     m_fftRealOut = new double[m_beatframesize];
     m_fftImagOut = new double[m_beatframesize];
@@ -75,18 +74,14 @@
 void
 DownBeat::makeDecimators()
 {
-//    std::cerr << "m_factor = " << m_factor << std::endl;
     if (m_factor < 2) return;
     size_t highest = Decimator::getHighestSupportedFactor();
     if (m_factor <= highest) {
         m_decimator1 = new Decimator(m_increment, m_factor);
-//        std::cerr << "DownBeat: decimator 1 factor " << m_factor << ", size " << m_increment << std::endl;
         return;
     }
     m_decimator1 = new Decimator(m_increment, highest);
-//    std::cerr << "DownBeat: decimator 1 factor " << highest << ", size " << m_increment << std::endl;
     m_decimator2 = new Decimator(m_increment / highest, m_factor / highest);
-//    std::cerr << "DownBeat: decimator 2 factor " << m_factor / highest << ", size " << m_increment / highest << std::endl;
     m_decbuf = new float[m_increment / highest];
 }
 
@@ -99,15 +94,12 @@
         if (!m_buffer) {
             m_buffer = (float *)malloc(m_bufsiz * sizeof(float));
         } else {
-//            std::cerr << "DownBeat::pushAudioBlock: realloc m_buffer to " << m_bufsiz << std::endl;
             m_buffer = (float *)realloc(m_buffer, m_bufsiz * sizeof(float));
         }
     }
-    if (!m_decimator1 && m_factor > 1) makeDecimators();
-//    float rmsin = 0, rmsout = 0;
-//    for (int i = 0; i < m_increment; ++i) {
-//        rmsin += audio[i] * audio[i];
-//    }
+    if (!m_decimator1 && m_factor > 1) {
+        makeDecimators();
+    }
     if (m_decimator2) {
         m_decimator1->process(audio, m_decbuf);
         m_decimator2->process(m_decbuf, m_buffer + m_buffill);
@@ -119,10 +111,6 @@
             (m_buffer + m_buffill)[i] = audio[i];
         }
     }
-//    for (int i = 0; i < m_increment / m_factor; ++i) {
-//        rmsout += m_buffer[m_buffill + i] * m_buffer[m_buffill + i];
-//    }
-//    std::cerr << "pushAudioBlock: rms in " << sqrt(rmsin) << ", out " << sqrt(rmsout) << std::endl;
     m_buffill += m_increment / m_factor;
 }
     
@@ -136,7 +124,9 @@
 void
 DownBeat::resetAudioBuffer()
 {
-    if (m_buffer) free(m_buffer);
+    if (m_buffer) {
+        free(m_buffer);
+    }
     m_buffer = 0;
     m_buffill = 0;
     m_bufsiz = 0;
@@ -179,16 +169,10 @@
         // the size varies, it's easier to do this by hand than use
         // our Window abstraction.)
 
-//        std::cerr << "beatlen = " << beatlen << std::endl;
-
-//        float rms = 0;
         for (size_t j = 0; j < beatlen && j < m_beatframesize; ++j) {
             double mul = 0.5 * (1.0 - cos(TWO_PI * (double(j) / double(beatlen))));
             m_beatframe[j] = audio[beatstart + j] * mul;
-//            rms += m_beatframe[j] * m_beatframe[j];
         }
-//        rms = sqrt(rms);
-//        std::cerr << "beat " << i << ": audio rms " << rms << std::endl;
 
         for (size_t j = beatlen; j < m_beatframesize; ++j) {
             m_beatframe[j] = 0.0;
@@ -213,7 +197,6 @@
 
         if (i > 0) { // otherwise we have no previous frame
             m_beatsd.push_back(measureSpecDiff(oldspec, newspec));
-//            std::cerr << "specdiff: " << m_beatsd[m_beatsd.size()-1] << std::endl;
         }
 
         // Copy newspec across to old
@@ -242,8 +225,9 @@
            dbcand[beat] += (m_beatsd[example]) / timesig;
            ++count;
        }
-       if (count > 0) dbcand[beat] /= count;
-//        std::cerr << "dbcand[" << beat << "] = " << dbcand[beat] << std::endl;
+       if (count > 0) {
+           dbcand[beat] /= count;
+       }
    }
 
     // first downbeat is beat at index of maximum value of dbcand
@@ -270,8 +254,8 @@
     double sumnew = 0.;
     double sumold = 0.;
   
-    for (unsigned int i = 0;i < SPECSIZE;i++)
-    {
+    for (unsigned int i = 0;i < SPECSIZE;i++) {
+        
         newspec[i] +=EPS;
         oldspec[i] +=EPS;
         
@@ -279,25 +263,25 @@
         sumold+=oldspec[i];
     } 
     
-    for (unsigned int i = 0;i < SPECSIZE;i++)
-    {
+    for (unsigned int i = 0;i < SPECSIZE;i++) {
+        
         newspec[i] /= (sumnew);
         oldspec[i] /= (sumold);
         
         // IF ANY SPECTRAL VALUES ARE 0 (SHOULDN'T BE ANY!) SET THEM TO 1
-        if (newspec[i] == 0)
-        {
+        if (newspec[i] == 0) {
             newspec[i] = 1.;
         }
         
-        if (oldspec[i] == 0)
-        {
+        if (oldspec[i] == 0) {
             oldspec[i] = 1.;
         }
         
         // JENSEN-SHANNON CALCULATION
-        sd1 = 0.5*oldspec[i] + 0.5*newspec[i];	
-        SD = SD + (-sd1*log(sd1)) + (0.5*(oldspec[i]*log(oldspec[i]))) + (0.5*(newspec[i]*log(newspec[i])));
+        sd1 = 0.5*oldspec[i] + 0.5*newspec[i];  
+        SD = SD + (-sd1*log(sd1)) +
+            (0.5*(oldspec[i]*log(oldspec[i]))) +
+            (0.5*(newspec[i]*log(newspec[i])));
     }
     
     return SD;
@@ -306,6 +290,8 @@
 void
 DownBeat::getBeatSD(vector<double> &beatsd) const
 {
-    for (int i = 0; i < (int)m_beatsd.size(); ++i) beatsd.push_back(m_beatsd[i]);
+    for (int i = 0; i < (int)m_beatsd.size(); ++i) {
+        beatsd.push_back(m_beatsd[i]);
+    }
 }
 
--- a/dsp/tempotracking/TempoTrack.cpp	Thu May 30 18:40:16 2019 +0100
+++ b/dsp/tempotracking/TempoTrack.cpp	Fri May 31 10:35:08 2019 +0100
@@ -24,9 +24,6 @@
 
 //#define DEBUG_TEMPO_TRACK 1
 
-
-#define RAY43VAL
-
 //////////////////////////////////////////////////////////////////////
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
@@ -37,7 +34,7 @@
     m_rawDFFrame = NULL;
     m_smoothDFFrame = NULL;
     m_frameACF = NULL;
-	m_smoothRCF = NULL;
+    m_smoothRCF = NULL;
 
     m_dataLength = 0;
     m_winLength = 0;
@@ -56,11 +53,11 @@
 }
 
 void TempoTrack::initialise( TTParams Params )
-{	
+{       
     m_winLength = Params.winLength;
     m_lagLength = Params.lagLength;
 
-    m_rayparam	 = 43.0;
+    m_rayparam   = 43.0;
     m_sigma = sqrt(3.9017);
     m_DFWVNnorm = exp( ( log( 2.0 ) / m_rayparam ) * ( m_winLength + 2 ) );
 
@@ -68,10 +65,10 @@
     m_smoothDFFrame = new double[ m_winLength ];
     m_frameACF = new double[ m_winLength ];
     m_tempoScratch = new double[ m_lagLength ];
-	m_smoothRCF = new double[ m_lagLength ];
+    m_smoothRCF = new double[ m_lagLength ];
 
     m_DFFramer.configure( m_winLength, m_lagLength );
-	
+        
     m_DFPParams.length = m_winLength;
     m_DFPParams.AlphaNormParam = Params.alpha;
     m_DFPParams.LPOrd = Params.LPOrd;
@@ -80,11 +77,10 @@
     m_DFPParams.winPre = Params.WinT.pre;
     m_DFPParams.winPost = Params.WinT.post;
     m_DFPParams.isMedianPositive = true;
-	
+        
     m_DFConditioning = new DFProcess( m_DFPParams );
 
-
-	// these are parameters for smoothing m_tempoScratch
+    // these are parameters for smoothing m_tempoScratch
     m_RCFPParams.length = m_lagLength;
     m_RCFPParams.AlphaNormParam = Params.alpha;
     m_RCFPParams.LPOrd = Params.LPOrd;
@@ -95,52 +91,42 @@
     m_RCFPParams.isMedianPositive = true;
 
     m_RCFConditioning = new DFProcess( m_RCFPParams );
-
 }
 
 void TempoTrack::deInitialise()
-{	
+{       
     delete [] m_rawDFFrame;
-	
     delete [] m_smoothDFFrame;
-
-	delete [] m_smoothRCF;	
-	
+    delete [] m_smoothRCF;  
     delete [] m_frameACF;
-
     delete [] m_tempoScratch;
-
     delete m_DFConditioning;
-	
-	delete m_RCFConditioning;
-
+    delete m_RCFConditioning;
 }
 
 void TempoTrack::createCombFilter(double* Filter, int winLength, int /* TSig */, double beatLag)
 {
     int i;
 
-    if( beatLag == 0 )
-    {
-	for( i = 0; i < winLength; i++ )
-	{    
-	    Filter[ i ] = ( ( i + 1 ) / pow( m_rayparam, 2.0) ) * exp( ( -pow(( i + 1 ),2.0 ) / ( 2.0 * pow( m_rayparam, 2.0))));
-	}
-    }
-    else
-    {	
-	m_sigma = beatLag/4;
-	for( i = 0; i < winLength; i++ )
-	{
-	    double dlag = (double)(i+1) - beatLag;
-	    Filter[ i ] =  exp(-0.5 * pow(( dlag / m_sigma), 2.0) ) / (sqrt( 2 * PI) * m_sigma);
-	}
+    if( beatLag == 0 ) {
+        for( i = 0; i < winLength; i++ ) {    
+            Filter[ i ] =
+                ( ( i + 1 ) / pow( m_rayparam, 2.0) ) *
+                exp( ( -pow(( i + 1 ),2.0 ) /
+                       ( 2.0 * pow( m_rayparam, 2.0))));
+        }
+    } else {   
+        m_sigma = beatLag/4;
+        for( i = 0; i < winLength; i++ ) {
+            double dlag = (double)(i+1) - beatLag;
+            Filter[ i ] =  exp(-0.5 * pow(( dlag / m_sigma), 2.0) ) /
+                (sqrt( 2 * PI) * m_sigma);
+        }
     }
 }
 
 double TempoTrack::tempoMM(double* ACF, double* weight, int tsig)
 {
-
     double period = 0;
     double maxValRCF = 0.0;
     int maxIndexRCF = 0;
@@ -150,166 +136,141 @@
     int maxIndexTemp;
     double maxValTemp;
     int count; 
-	
+        
     int numelem,i,j;
     int a, b;
 
-    for( i = 0; i < m_lagLength; i++ )
-	m_tempoScratch[ i ] = 0.0;
+    for( i = 0; i < m_lagLength; i++ ) {
+        m_tempoScratch[ i ] = 0.0;
+    }
 
-    if( tsig == 0 ) 
-    {
-	//if time sig is unknown, use metrically unbiased version of Filterbank
-	numelem = 4;
-    }
-    else
-    {
-	numelem = tsig;
+    if( tsig == 0 ) {
+        //if time sig is unknown, use metrically unbiased version of Filterbank
+        numelem = 4;
+    } else {
+        numelem = tsig;
     }
 
 #ifdef DEBUG_TEMPO_TRACK
     std::cerr << "tempoMM: m_winLength = " << m_winLength << ", m_lagLength = " << m_lagLength << ", numelem = " << numelem << std::endl;
 #endif
 
-    for(i=1;i<m_lagLength-1;i++)
-    {
-	//first and last output values are left intentionally as zero
-	for (a=1;a<=numelem;a++)
-	{
-	    for(b=(1-a);b<a;b++)
-	    {
-		if( tsig == 0 )
-		{					
-		    m_tempoScratch[i] += ACF[a*(i+1)+b-1] * (1.0 / (2.0 * (double)a-1)) * weight[i];
-		}
-		else
-		{
-		    m_tempoScratch[i] += ACF[a*(i+1)+b-1] * 1 * weight[i];
-		}
-	    }
-	}
+    for(i=1;i<m_lagLength-1;i++) {
+        //first and last output values are left intentionally as zero
+        for (a=1;a<=numelem;a++) {
+            for(b=(1-a);b<a;b++) {
+                if( tsig == 0 ) {                                       
+                    m_tempoScratch[i] += ACF[a*(i+1)+b-1] * (1.0 / (2.0 * (double)a-1)) * weight[i];
+                } else {
+                    m_tempoScratch[i] += ACF[a*(i+1)+b-1] * 1 * weight[i];
+                }
+            }
+        }
     }
 
 
-	//////////////////////////////////////////////////
-	// MODIFIED BEAT PERIOD EXTRACTION //////////////
-	/////////////////////////////////////////////////
+    //////////////////////////////////////////////////
+    // MODIFIED BEAT PERIOD EXTRACTION //////////////
+    /////////////////////////////////////////////////
 
-	// find smoothed version of RCF ( as applied to Detection Function)
-	m_RCFConditioning->process( m_tempoScratch, m_smoothRCF);
+    // find smoothed version of RCF ( as applied to Detection Function)
+    m_RCFConditioning->process( m_tempoScratch, m_smoothRCF);
 
-	if (tsig != 0) // i.e. in context dependent state
-	{	
+    if (tsig != 0) { // i.e. in context dependent state
+
 //     NOW FIND MAX INDEX OF ACFOUT
-            for( i = 0; i < m_lagLength; i++)
-            {
-                if( m_tempoScratch[ i ] > maxValRCF)
-                {
-                    maxValRCF = m_tempoScratch[ i ];
-                    maxIndexRCF = i;
+        for( i = 0; i < m_lagLength; i++) {
+            if( m_tempoScratch[ i ] > maxValRCF) {
+                maxValRCF = m_tempoScratch[ i ];
+                maxIndexRCF = i;
+            }
+        }
+
+    } else { // using rayleigh weighting
+
+        vector <vector<double> > rcfMat;
+        
+        double sumRcf = 0.;
+        
+        double maxVal = 0.;
+        // now find the two values which minimise rcfMat
+        double minVal = 0.;
+        int p_i = 1; // periodicity for row i;
+        int p_j = 1; //periodicity for column j;
+        
+        for ( i=0; i<m_lagLength; i++) {
+            m_tempoScratch[i] =m_smoothRCF[i];
+        }       
+
+        // normalise m_tempoScratch so that it sums to zero.
+        for ( i=0; i<m_lagLength; i++) {
+            sumRcf += m_tempoScratch[i];
+        }       
+        
+        for( i=0; i<m_lagLength; i++) {
+            m_tempoScratch[i] /= sumRcf;
+        }       
+        
+        // create a matrix to store m_tempoScratchValues modified by log2 ratio
+        for ( i=0; i<m_lagLength; i++) {
+            rcfMat.push_back  ( vector<double>() ); // adds a new row...
+        }
+        
+        for (i=0; i<m_lagLength; i++) {
+            for (j=0; j<m_lagLength; j++) {
+                rcfMat[i].push_back (0.);
+            }
+        }
+        
+        // the 'i' and 'j' indices deliberately start from '1' and not '0'
+        for ( i=1; i<m_lagLength; i++) {
+            for (j=1; j<m_lagLength; j++) {
+                double log2PeriodRatio = log( static_cast<double>(i)/
+                                              static_cast<double>(j) ) /
+                    log(2.0);
+                rcfMat[i][j] = ( abs(1.0-abs(log2PeriodRatio)) );
+                rcfMat[i][j] += ( 0.01*( 1./(m_tempoScratch[i]+m_tempoScratch[j]) ) );
+            }
+        }
+                
+        // set diagonal equal to maximum value in rcfMat 
+        // we don't want to pick one strong middle peak - we need a combination of two peaks.
+        
+        for ( i=1; i<m_lagLength; i++) {
+            for (j=1; j<m_lagLength; j++) {
+                if (rcfMat[i][j] > maxVal) {       
+                    maxVal = rcfMat[i][j];
                 }
             }
-	}
-	else // using rayleigh weighting
-	{
-		vector <vector<double> > rcfMat;
-	
-		double sumRcf = 0.;
-	
-		double maxVal = 0.;
-		// now find the two values which minimise rcfMat
-		double minVal = 0.;
-		int p_i = 1; // periodicity for row i;
-		int p_j = 1; //periodicity for column j;
-	
-	
-		for ( i=0; i<m_lagLength; i++)
-		{
-			m_tempoScratch[i] =m_smoothRCF[i];
-		}	
-
-		// normalise m_tempoScratch so that it sums to zero.
-		for ( i=0; i<m_lagLength; i++)
-		{
-			sumRcf += m_tempoScratch[i];
-		}	
-	
-		for( i=0; i<m_lagLength; i++)
-		{
-			m_tempoScratch[i] /= sumRcf;
-		}	
-	
-		// create a matrix to store m_tempoScratchValues modified by log2 ratio
-		for ( i=0; i<m_lagLength; i++)
-		{
-			rcfMat.push_back  ( vector<double>() ); // adds a new row...
-		}
-	
-		for (i=0; i<m_lagLength; i++)
-		{
-			for (j=0; j<m_lagLength; j++)
-			{
-				rcfMat[i].push_back (0.);
-			}
-		}
-	
-		// the 'i' and 'j' indices deliberately start from '1' and not '0'
-		for ( i=1; i<m_lagLength; i++)
-		{
-			for (j=1; j<m_lagLength; j++)
-			{
-				double log2PeriodRatio = log( static_cast<double>(i)/static_cast<double>(j) ) / log(2.0);
-				rcfMat[i][j] = ( abs(1.0-abs(log2PeriodRatio)) );
-				rcfMat[i][j] += ( 0.01*( 1./(m_tempoScratch[i]+m_tempoScratch[j]) ) );
-			}
-		}
-		
-		// set diagonal equal to maximum value in rcfMat 
-		// we don't want to pick one strong middle peak - we need a combination of two peaks.
-	
-		for ( i=1; i<m_lagLength; i++)
-		{
-			for (j=1; j<m_lagLength; j++)
-			{
-				if (rcfMat[i][j] > maxVal)
-				{	
-					maxVal = rcfMat[i][j];
-				}
-			}
-		}
-	
-		for ( i=1; i<m_lagLength; i++)
-		{
-			rcfMat[i][i] = maxVal;
-		}
-	
-		// now find the row and column number which minimise rcfMat
-		minVal = maxVal;
-		
-		for ( i=1; i<m_lagLength; i++)
-		{
-			for ( j=1; j<m_lagLength; j++)
-			{
-				if (rcfMat[i][j] < minVal)
-				{	
-					minVal = rcfMat[i][j];
-					p_i = i;
-					p_j = j;
-				}
-			}
-		}
-	
-	
-		// initially choose p_j (arbitrary) - saves on an else statement
-		int beatPeriod = p_j;
-		if (m_tempoScratch[p_i] > m_tempoScratch[p_j])
-		{
-			beatPeriod = p_i;
-		}
-		
-		// now write the output
-		maxIndexRCF = static_cast<int>(beatPeriod);
-	}
+        }
+        
+        for ( i=1; i<m_lagLength; i++) {
+            rcfMat[i][i] = maxVal;
+        }
+        
+        // now find the row and column number which minimise rcfMat
+        minVal = maxVal;
+                
+        for ( i=1; i<m_lagLength; i++) {
+            for ( j=1; j<m_lagLength; j++) {
+                if (rcfMat[i][j] < minVal) {       
+                    minVal = rcfMat[i][j];
+                    p_i = i;
+                    p_j = j;
+                }
+            }
+        }
+        
+        
+        // initially choose p_j (arbitrary) - saves on an else statement
+        int beatPeriod = p_j;
+        if (m_tempoScratch[p_i] > m_tempoScratch[p_j]) {
+            beatPeriod = p_i;
+        }
+                
+        // now write the output
+        maxIndexRCF = static_cast<int>(beatPeriod);
+    }
 
 
     double locked = 5168.f / maxIndexRCF;
@@ -321,116 +282,109 @@
     std::cerr << "tempoMM: locked tempo = " << m_lockedTempo << std::endl;
 #endif
 
-    if( tsig == 0 )
-	tsig = 4;
-
+    if( tsig == 0 ) {
+        tsig = 4;
+    }
 
 #ifdef DEBUG_TEMPO_TRACK
-std::cerr << "tempoMM: maxIndexRCF = " << maxIndexRCF << std::endl;
+    std::cerr << "tempoMM: maxIndexRCF = " << maxIndexRCF << std::endl;
 #endif
-	
-    if( tsig == 4 )
-    {
+        
+    if( tsig == 4 ) {
+        
 #ifdef DEBUG_TEMPO_TRACK
         std::cerr << "tsig == 4" << std::endl;
 #endif
 
-	pdPeaks = new double[ 4 ];
-	for( i = 0; i < 4; i++ ){ pdPeaks[ i ] = 0.0;}
+        pdPeaks = new double[ 4 ];
+        for( i = 0; i < 4; i++ ){ pdPeaks[ i ] = 0.0;}
 
-	pdPeaks[ 0 ] = ( double )maxIndexRCF + 1;
+        pdPeaks[ 0 ] = ( double )maxIndexRCF + 1;
 
-	maxIndexTemp = 0;
-	maxValTemp = 0.0;
-	count = 0;
+        maxIndexTemp = 0;
+        maxValTemp = 0.0;
+        count = 0;
 
-	for( i = (2 * maxIndexRCF + 1) - 1; i < (2 * maxIndexRCF + 1) + 2; i++ )
-	{
-	    if( ACF[ i ] > maxValTemp )
-	    {
-		maxValTemp = ACF[ i ];
-		maxIndexTemp = count;
-	    }
-	    count++;
-	}
-	pdPeaks[ 1 ] = (double)( maxIndexTemp + 1 + ( (2 * maxIndexRCF + 1 ) - 2 ) + 1 )/2;
+        for( i = (2 * maxIndexRCF + 1) - 1; i < (2 * maxIndexRCF + 1) + 2; i++ ) {
+            if( ACF[ i ] > maxValTemp ) {
+                maxValTemp = ACF[ i ];
+                maxIndexTemp = count;
+            }
+            count++;
+        }
+        pdPeaks[ 1 ] = (double)( maxIndexTemp + 1 + ( (2 * maxIndexRCF + 1 ) - 2 ) + 1 )/2;
 
-	maxIndexTemp = 0;
-	maxValTemp = 0.0;
-	count = 0;
+        maxIndexTemp = 0;
+        maxValTemp = 0.0;
+        count = 0;
 
-	for( i = (3 * maxIndexRCF + 2 ) - 2; i < (3 * maxIndexRCF + 2 ) + 3; i++ )
-	{
-	    if( ACF[ i ] > maxValTemp )
-	    {
-		maxValTemp = ACF[ i ];
-		maxIndexTemp = count;
-	    }
-	    count++;
-	}
-	pdPeaks[ 2 ] = (double)( maxIndexTemp + 1 + ( (3 * maxIndexRCF + 2) - 4 ) + 1 )/3;
+        for( i = (3 * maxIndexRCF + 2 ) - 2; i < (3 * maxIndexRCF + 2 ) + 3; i++ ) {
+            if( ACF[ i ] > maxValTemp ) {
+                maxValTemp = ACF[ i ];
+                maxIndexTemp = count;
+            }
+            count++;
+        }
+        pdPeaks[ 2 ] = (double)( maxIndexTemp + 1 + ( (3 * maxIndexRCF + 2) - 4 ) + 1 )/3;
 
-	maxIndexTemp = 0;
-	maxValTemp = 0.0;
-	count = 0;
+        maxIndexTemp = 0;
+        maxValTemp = 0.0;
+        count = 0;
 
-	for( i = ( 4 * maxIndexRCF + 3) - 3; i < ( 4 * maxIndexRCF + 3) + 4; i++ )
-	{
-	    if( ACF[ i ] > maxValTemp )
-	    {
-		maxValTemp = ACF[ i ];
-		maxIndexTemp = count;
-	    }
-	    count++;
-	}
-	pdPeaks[ 3 ] = (double)( maxIndexTemp + 1 + ( (4 * maxIndexRCF + 3) - 9 ) + 1 )/4 ;
+        for( i = ( 4 * maxIndexRCF + 3) - 3; i < ( 4 * maxIndexRCF + 3) + 4; i++ ) {
+            if( ACF[ i ] > maxValTemp ) {
+                maxValTemp = ACF[ i ];
+                maxIndexTemp = count;
+            }
+            count++;
+        }
 
+        pdPeaks[ 3 ] = (double)( maxIndexTemp + 1 + ( (4 * maxIndexRCF + 3) - 9 ) + 1 )/4 ;
 
-	period = MathUtilities::mean( pdPeaks, 4 );
-    }
-    else
-    { 
+
+        period = MathUtilities::mean( pdPeaks, 4 );
+
+    } else {
+        
 #ifdef DEBUG_TEMPO_TRACK
-       std::cerr << "tsig != 4" << std::endl;
+        std::cerr << "tsig != 4" << std::endl;
 #endif
 
-	pdPeaks = new double[ 3 ];
-	for( i = 0; i < 3; i++ ){ pdPeaks[ i ] = 0.0;}
+        pdPeaks = new double[ 3 ];
+        for( i = 0; i < 3; i++ ) {
+            pdPeaks[ i ] = 0.0;
+        }
 
-	pdPeaks[ 0 ] = ( double )maxIndexRCF + 1;
+        pdPeaks[ 0 ] = ( double )maxIndexRCF + 1;
 
-	maxIndexTemp = 0;
-	maxValTemp = 0.0;
-	count = 0;
+        maxIndexTemp = 0;
+        maxValTemp = 0.0;
+        count = 0;
 
-	for( i = (2 * maxIndexRCF + 1) - 1; i < (2 * maxIndexRCF + 1) + 2; i++ )
-	{
-	    if( ACF[ i ] > maxValTemp )
-	    {
-		maxValTemp = ACF[ i ];
-		maxIndexTemp = count;
-	    }
-	    count++;
-	}
-	pdPeaks[ 1 ] = (double)( maxIndexTemp + 1 + ( (2 * maxIndexRCF + 1 ) - 2 ) + 1 )/2;
+        for( i = (2 * maxIndexRCF + 1) - 1; i < (2 * maxIndexRCF + 1) + 2; i++ ) {
+            if( ACF[ i ] > maxValTemp ) {
+                maxValTemp = ACF[ i ];
+                maxIndexTemp = count;
+            }
+            count++;
+        }
+        pdPeaks[ 1 ] = (double)( maxIndexTemp + 1 + ( (2 * maxIndexRCF + 1 ) - 2 ) + 1 )/2;
 
-	maxIndexTemp = 0;
-	maxValTemp = 0.0;
-	count = 0;
+        maxIndexTemp = 0;
+        maxValTemp = 0.0;
+        count = 0;
 
-	for( i = (3 * maxIndexRCF + 2 ) - 2; i < (3 * maxIndexRCF + 2 ) + 3; i++ )
-	{
-	    if( ACF[ i ] > maxValTemp )
-	    {
-		maxValTemp = ACF[ i ];
-		maxIndexTemp = count;
-	    }
-	    count++;
-	}
-	pdPeaks[ 2 ] = (double)( maxIndexTemp + 1 + ( (3 * maxIndexRCF + 2) - 4 ) + 1 )/3;
+        for( i = (3 * maxIndexRCF + 2 ) - 2; i < (3 * maxIndexRCF + 2 ) + 3; i++ ) {
+            if( ACF[ i ] > maxValTemp ) {
+                maxValTemp = ACF[ i ];
+                maxIndexTemp = count;
+            }
+            count++;
+        }
+        pdPeaks[ 2 ] = (double)( maxIndexTemp + 1 + ( (3 * maxIndexRCF + 2) - 4 ) + 1 )/3;
 
 
-	period = MathUtilities::mean( pdPeaks, 3 );
+        period = MathUtilities::mean( pdPeaks, 3 );
     }
 
     delete [] pdPeaks;
@@ -442,19 +396,14 @@
 {
     double stepthresh = 1 * 3.9017;
 
-    if( *flag )
-    {
-	if(abs(periodG[ currentIdx ] - periodP[ currentIdx ]) > stepthresh)
-	{
-	    // do nuffin'
-	}
-    }
-    else
-    {
-	if(fabs(periodG[ currentIdx ]-periodP[ currentIdx ]) > stepthresh)
-	{
-	    *flag = 3;
-	}
+    if( *flag ) {
+        if(abs(periodG[ currentIdx ] - periodP[ currentIdx ]) > stepthresh) {
+            // do nuffin'
+        }
+    } else {
+        if(fabs(periodG[ currentIdx ]-periodP[ currentIdx ]) > stepthresh) {
+            *flag = 3;
+        }
     }
 }
 
@@ -462,13 +411,10 @@
 {
     double constthresh = 2 * 3.9017;
 
-    if( fabs( 2 * periodP[ currentIdx ] - periodP[ currentIdx - 1] - periodP[ currentIdx - 2] ) < constthresh)
-    {
-	*flag = 1;
-    }
-    else
-    {
-	*flag = 0;
+    if( fabs( 2 * periodP[ currentIdx ] - periodP[ currentIdx - 1] - periodP[ currentIdx - 2] ) < constthresh) {
+        *flag = 1;
+    } else {
+        *flag = 0;
     }
 }
 
@@ -489,63 +435,53 @@
     double* dbf = new double[ len ]; int t = 0;
     for( int u = 0; u < len; u++ ){ dbf[ u ] = 0.0; }
 
-    if( (double)len < 6 * p + 2 )
-    {
-	for( i = ( 3 * p - 2 ); i < ( 3 * p + 2 ) + 1; i++ )
-	{
-	    temp3A += ACF[ i ];
-	    dbf[ t++ ] = ACF[ i ];
-	}
-	
-	for( i = ( 4 * p - 2 ); i < ( 4 * p + 2 ) + 1; i++ )
-	{
-	    temp4A += ACF[ i ];
-	}
+    if( (double)len < 6 * p + 2 ) {
+        
+        for( i = ( 3 * p - 2 ); i < ( 3 * p + 2 ) + 1; i++ ) {
+            temp3A += ACF[ i ];
+            dbf[ t++ ] = ACF[ i ];
+        }
+        
+        for( i = ( 4 * p - 2 ); i < ( 4 * p + 2 ) + 1; i++ ) {
+            temp4A += ACF[ i ];
+        }
 
-	Energy_3 = temp3A;
-	Energy_4 = temp4A;
-    }
-    else
-    {
-	for( i = ( 3 * p - 2 ); i < ( 3 * p + 2 ) + 1; i++ )
-	{
-	    temp3A += ACF[ i ];
-	}
-	
-	for( i = ( 4 * p - 2 ); i < ( 4 * p + 2 ) + 1; i++ )
-	{
-	    temp4A += ACF[ i ];
-	}
+        Energy_3 = temp3A;
+        Energy_4 = temp4A;
 
-	for( i = ( 6 * p - 2 ); i < ( 6 * p + 2 ) + 1; i++ )
-	{
-	    temp3B += ACF[ i ];
-	}
-	
-	for( i = ( 2 * p - 2 ); i < ( 2 * p + 2 ) + 1; i++ )
-	{
-	    temp4B += ACF[ i ];
-	}
+    } else {
+        
+        for( i = ( 3 * p - 2 ); i < ( 3 * p + 2 ) + 1; i++ ) {
+            temp3A += ACF[ i ];
+        }
+        
+        for( i = ( 4 * p - 2 ); i < ( 4 * p + 2 ) + 1; i++ ) {
+            temp4A += ACF[ i ];
+        }
 
-	Energy_3 = temp3A + temp3B;
-	Energy_4 = temp4A + temp4B;
+        for( i = ( 6 * p - 2 ); i < ( 6 * p + 2 ) + 1; i++ ) {
+            temp3B += ACF[ i ];
+        }
+        
+        for( i = ( 2 * p - 2 ); i < ( 2 * p + 2 ) + 1; i++ ) {
+            temp4B += ACF[ i ];
+        }
+
+        Energy_3 = temp3A + temp3B;
+        Energy_4 = temp4A + temp4B;
     }
 
-    if (Energy_3 > Energy_4)
-    {
-	tsig = 3;
+    if (Energy_3 > Energy_4) {
+        tsig = 3;
+    } else {
+        tsig = 4;
     }
-    else
-    {
-	tsig = 4;
-    }
-
 
     return tsig;
 }
 
 void TempoTrack::createPhaseExtractor(double *Filter, int /* winLength */, double period, int fsp, int lastBeat)
-{	
+{       
     int p = (int)MathUtilities::round( period );
     int predictedOffset = 0;
 
@@ -561,62 +497,55 @@
     double* phaseScratch = new double[ p*2 + 2 ];
     for (int i = 0; i < p*2 + 2; ++i) phaseScratch[i] = 0.0;
 
-	
-    if( lastBeat != 0 )
-    {
-	lastBeat = (int)MathUtilities::round((double)lastBeat );///(double)winLength);
+        
+    if ( lastBeat != 0 ) {
+        
+        lastBeat = (int)MathUtilities::round((double)lastBeat );///(double)winLength);
 
         predictedOffset = lastBeat + p - fsp;
 
-        if (predictedOffset < 0) 
-        {
+        if (predictedOffset < 0) {
             lastBeat = 0;
         }
     }
 
-    if( lastBeat != 0 )
-    {
-	int mu = p;
-	double sigma = (double)p/8;
-	double PhaseMin = 0.0;
-	double PhaseMax = 0.0;
-	int scratchLength = p*2;
-	double temp = 0.0;
+    if ( lastBeat != 0 ) {
+        
+        int mu = p;
+        double sigma = (double)p/8;
+        double PhaseMin = 0.0;
+        double PhaseMax = 0.0;
+        int scratchLength = p*2;
+        double temp = 0.0;
 
-	for(  int i = 0; i < scratchLength; i++ )
-	{
-	    phaseScratch[ i ] = exp( -0.5 * pow( ( i - mu ) / sigma, 2 ) ) / ( sqrt( 2*PI ) *sigma );
-	}
+        for(  int i = 0; i < scratchLength; i++ ) {
+            phaseScratch[ i ] = exp( -0.5 * pow( ( i - mu ) / sigma, 2 ) ) / ( sqrt( 2*PI ) *sigma );
+        }
 
-	MathUtilities::getFrameMinMax( phaseScratch, scratchLength, &PhaseMin, &PhaseMax );
-			
-	for(int i = 0; i < scratchLength; i ++)
-	{
-	    temp = phaseScratch[ i ];
-	    phaseScratch[ i ] = (temp - PhaseMin)/PhaseMax;
-	}
+        MathUtilities::getFrameMinMax( phaseScratch, scratchLength, &PhaseMin, &PhaseMax );
+                        
+        for(int i = 0; i < scratchLength; i ++) {
+            temp = phaseScratch[ i ];
+            phaseScratch[ i ] = (temp - PhaseMin)/PhaseMax;
+        }
 
 #ifdef DEBUG_TEMPO_TRACK
         std::cerr << "predictedOffset = " << predictedOffset << std::endl;
 #endif
 
-	int index = 0;
-	for (int i = p - ( predictedOffset - 1); i < p + ( p - predictedOffset) + 1; i++)
-	{
+        int index = 0;
+        for (int i = p - ( predictedOffset - 1); i < p + ( p - predictedOffset) + 1; i++) {
 #ifdef DEBUG_TEMPO_TRACK
             std::cerr << "assigning to filter index " << index << " (size = " << p*2 << ")" << " value " << phaseScratch[i] << " from scratch index " << i << std::endl;
 #endif
-	    Filter[ index++ ] = phaseScratch[ i ];
-	}
+            Filter[ index++ ] = phaseScratch[ i ];
+        }
+    } else {
+        for( int i = 0; i < p; i ++) {
+            Filter[ i ] = 1;
+        }
     }
-    else
-    {
-	for( int i = 0; i < p; i ++)
-	{
-	    Filter[ i ] = 1;
-	}
-    }
-	
+        
     delete [] phaseScratch;
 }
 
@@ -630,31 +559,26 @@
     double* y = new double[ winLength ];
     double* align = new double[ p ];
 
-    for( int i = 0; i < winLength; i++ )
-    {	
-	y[ i ] = (double)( -i + winLength  )/(double)winLength;
-	y[ i ] = pow(y [i ],2.0); // raise to power 2.
+    for( int i = 0; i < winLength; i++ ) {   
+        y[ i ] = (double)( -i + winLength  )/(double)winLength;
+        y[ i ] = pow(y [i ],2.0); // raise to power 2.
     }
 
-    for( int o = 0; o < p; o++ )
-    { 
-	temp = 0.0;
-	for(int i = 1 + (o - 1); i< winLength; i += (p + 1))
-	{
-	    temp = temp + DF[ i ] * y[ i ]; 
-	}
-	align[ o ] = temp * weighting[ o ];       
+    for( int o = 0; o < p; o++ ) { 
+        temp = 0.0;
+        for (int i = 1 + (o - 1); i < winLength; i += (p + 1)) {
+            temp = temp + DF[ i ] * y[ i ]; 
+        }
+        align[ o ] = temp * weighting[ o ];       
     }
 
 
     double valTemp = 0.0;
-    for(int i = 0; i < p; i++)
-    {
-	if( align[ i ] > valTemp )
-	{
-	    valTemp = align[ i ];
-	    alignment = i;
-	}
+    for(int i = 0; i < p; i++) {
+        if( align[ i ] > valTemp ) {
+            valTemp = align[ i ];
+            alignment = i;
+        }
     }
 
     delete [] y;
@@ -677,11 +601,9 @@
 
     m_beats.push_back( beat );
 
-    while( beat + p < FEP )
-    {
-	beat += p;
-		
-	m_beats.push_back( beat );
+    while( beat + p < FEP ) {
+        beat += p;
+        m_beats.push_back( beat );
     }
 
     return beat;
@@ -693,10 +615,10 @@
                                  vector <double> *tempoReturn )
 {
     m_dataLength = DF.size();
-	
+        
     m_lockedTempo = 0.0;
 
-    double	period = 0.0;
+    double period = 0.0;
     int stepFlag = 0;
     int constFlag = 0;
     int FSP = 0;
@@ -709,13 +631,12 @@
 
     //Prepare Causal Extension DFData
 //    int DFCLength = m_dataLength + m_winLength;
-	
-    for( int j = 0; j < m_winLength; j++ )
-    {
-	causalDF.push_back( 0 );
+        
+    for( int j = 0; j < m_winLength; j++ ) {
+        causalDF.push_back( 0 );
     }
-	
-	
+        
+        
     double* RW = new double[ m_lagLength ];
     for (int clear = 0; clear < m_lagLength; clear++){ RW[ clear ] = 0.0;}
 
@@ -732,13 +653,13 @@
 #ifdef DEBUG_TEMPO_TRACK
     std::cerr << "TTFrames = " << TTFrames << std::endl;
 #endif
-	
+        
     double* periodP = new double[ TTFrames ];
     for(int clear = 0; clear < TTFrames; clear++){ periodP[ clear ] = 0.0;}
-	
+        
     double* periodG = new double[ TTFrames ];
     for(int clear = 0; clear < TTFrames; clear++){ periodG[ clear ] = 0.0;}
-	
+        
     double* alignment = new double[ TTFrames ];
     for(int clear = 0; clear < TTFrames; clear++){ alignment[ clear ] = 0.0;}
 
@@ -748,66 +669,57 @@
 
     int TTLoopIndex = 0;
 
-    for( int i = 0; i < TTFrames; i++ )
-    {
-	m_DFFramer.getFrame( m_rawDFFrame );
+    for( int i = 0; i < TTFrames; i++ ) {
+        
+        m_DFFramer.getFrame( m_rawDFFrame );
 
-	m_DFConditioning->process( m_rawDFFrame, m_smoothDFFrame );
+        m_DFConditioning->process( m_rawDFFrame, m_smoothDFFrame );
 
-	m_correlator.doAutoUnBiased( m_smoothDFFrame, m_frameACF, m_winLength );
-		
-	periodP[ TTLoopIndex ] = tempoMM( m_frameACF, RW, 0 );
+        m_correlator.doAutoUnBiased( m_smoothDFFrame, m_frameACF, m_winLength );
+                
+        periodP[ TTLoopIndex ] = tempoMM( m_frameACF, RW, 0 );
 
-	if( GW[ 0 ] != 0 )
-	{
-	    periodG[ TTLoopIndex ] = tempoMM( m_frameACF, GW, tsig );
-	}
-	else
-	{
-	    periodG[ TTLoopIndex ] = 0.0;
-	}
+        if( GW[ 0 ] != 0 ) {
+            periodG[ TTLoopIndex ] = tempoMM( m_frameACF, GW, tsig );
+        } else {
+            periodG[ TTLoopIndex ] = 0.0;
+        }
 
-	stepDetect( periodP, periodG, TTLoopIndex, &stepFlag );
+        stepDetect( periodP, periodG, TTLoopIndex, &stepFlag );
 
-	if( stepFlag == 1)
-	{
-	    constDetect( periodP, TTLoopIndex, &constFlag );
-	    stepFlag = 0;
-	}
-	else
-	{
-	    stepFlag -= 1;
-	}
+        if( stepFlag == 1) {
+            constDetect( periodP, TTLoopIndex, &constFlag );
+            stepFlag = 0;
+        } else {
+            stepFlag -= 1;
+        }
 
-	if( stepFlag < 0 )
-	{
-	    stepFlag = 0;
-	}
+        if( stepFlag < 0 ) {
+            stepFlag = 0;
+        }
 
-	if( constFlag != 0)
-	{
-	    tsig = findMeter( m_frameACF, m_winLength, periodP[ TTLoopIndex ] );
-	
-	    createCombFilter( GW, m_lagLength, tsig, periodP[ TTLoopIndex ] );
-			
-	    periodG[ TTLoopIndex ] = tempoMM( m_frameACF, GW, tsig ); 
+        if( constFlag != 0) {
+            
+            tsig = findMeter( m_frameACF, m_winLength, periodP[ TTLoopIndex ] );
+        
+            createCombFilter( GW, m_lagLength, tsig, periodP[ TTLoopIndex ] );
+                        
+            periodG[ TTLoopIndex ] = tempoMM( m_frameACF, GW, tsig ); 
 
-	    period = periodG[ TTLoopIndex ];
+            period = periodG[ TTLoopIndex ];
 
 #ifdef DEBUG_TEMPO_TRACK
             std::cerr << "TempoTrack::process: constFlag == " << constFlag << ", TTLoopIndex = " << TTLoopIndex << ", period from periodG = " << period << std::endl;
 #endif
 
-	    createPhaseExtractor( PW, m_winLength, period, FSP, 0 ); 
+            createPhaseExtractor( PW, m_winLength, period, FSP, 0 ); 
 
-	    constFlag = 0;
+            constFlag = 0;
 
-	}
-	else
-	{
-	    if( GW[ 0 ] != 0 )
-	    {
-		period = periodG[ TTLoopIndex ];
+        } else {
+            
+            if( GW[ 0 ] != 0 ) {
+                period = periodG[ TTLoopIndex ];
 
 #ifdef DEBUG_TEMPO_TRACK
                 std::cerr << "TempoTrack::process: GW[0] == " << GW[0] << ", TTLoopIndex = " << TTLoopIndex << ", period from periodG = " << period << std::endl;
@@ -826,30 +738,30 @@
                     period = 5168 / 120;
                 }
 
-		createPhaseExtractor( PW, m_winLength, period, FSP, lastBeat ); 
+                createPhaseExtractor( PW, m_winLength, period, FSP, lastBeat ); 
 
-	    }
-	    else
-	    {
-		period = periodP[ TTLoopIndex ];
+            }
+            else
+            {
+                period = periodP[ TTLoopIndex ];
 
 #ifdef DEBUG_TEMPO_TRACK
                 std::cerr << "TempoTrack::process: GW[0] == " << GW[0] << ", TTLoopIndex = " << TTLoopIndex << ", period from periodP = " << period << std::endl;
 #endif
 
-		createPhaseExtractor( PW, m_winLength, period, FSP, 0 ); 
-	    }
-	}
+                createPhaseExtractor( PW, m_winLength, period, FSP, 0 ); 
+            }
+        }
 
-	alignment[ TTLoopIndex ] = phaseMM( m_rawDFFrame, PW, m_winLength, period ); 
+        alignment[ TTLoopIndex ] = phaseMM( m_rawDFFrame, PW, m_winLength, period ); 
 
-	lastBeat = beatPredict(FSP, alignment[ TTLoopIndex ], period, m_lagLength );
+        lastBeat = beatPredict(FSP, alignment[ TTLoopIndex ], period, m_lagLength );
 
-	FSP += (m_lagLength);
+        FSP += (m_lagLength);
 
         if (tempoReturn) tempoReturn->push_back(m_lockedTempo);
 
-	TTLoopIndex++;
+        TTLoopIndex++;
     }
 
 
--- a/dsp/tempotracking/TempoTrack.h	Thu May 30 18:40:16 2019 +0100
+++ b/dsp/tempotracking/TempoTrack.h	Fri May 31 10:35:08 2019 +0100
@@ -54,7 +54,7 @@
 
     vector<int> process( vector <double> DF, vector <double> *tempoReturn = 0);
 
-	
+        
 private:
     void initialise( TTParams Params );
     void deInitialise();
@@ -67,7 +67,7 @@
     void stepDetect( double* periodP, double* periodG, int currentIdx, int* flag );
     void createCombFilter( double* Filter, int winLength, int TSig, double beatLag );
     double tempoMM( double* ACF, double* weight, int sig );
-	
+        
     int m_dataLength;
     int m_winLength;
     int m_lagLength;
@@ -76,13 +76,13 @@
     double m_sigma;
     double m_DFWVNnorm;
 
-    vector<int>	 m_beats; // Vector of detected beats
+    vector<int>  m_beats; // Vector of detected beats
 
     double m_lockedTempo;
 
     double* m_tempoScratch;
     double* m_smoothRCF; // Smoothed Output of Comb Filterbank (m_tempoScratch)
-	
+        
     // Processing Buffers 
     double* m_rawDFFrame; // Original Detection Function Analysis Frame
     double* m_smoothDFFrame; // Smoothed Detection Function Analysis Frame
@@ -91,7 +91,7 @@
     //Low Pass Coefficients for DF Smoothing
     double* m_ACoeffs;
     double* m_BCoeffs;
-	
+        
     // Objetcs/operators declaration
     Framer m_DFFramer;
     DFProcess* m_DFConditioning;
@@ -99,13 +99,10 @@
     // Config structure for DFProcess
     DFProcConfig m_DFPParams;
 
-	// also want to smooth m_tempoScratch 
+        // also want to smooth m_tempoScratch 
     DFProcess* m_RCFConditioning;
     // Config structure for RCFProcess
     DFProcConfig m_RCFPParams;
-
-
-
 };
 
 #endif
--- a/dsp/tempotracking/TempoTrackV2.cpp	Thu May 30 18:40:16 2019 +0100
+++ b/dsp/tempotracking/TempoTrackV2.cpp	Fri May 31 10:35:08 2019 +0100
@@ -25,6 +25,7 @@
 
 TempoTrackV2::TempoTrackV2(float rate, size_t increment) :
     m_rate(rate), m_increment(increment) { }
+
 TempoTrackV2::~TempoTrackV2() { }
 
 void
@@ -32,7 +33,7 @@
 {
     d_vec_t a(3);
     d_vec_t b(3);
-    d_vec_t	lp_df(df.size());
+    d_vec_t lp_df(df.size());
 
     //equivalent in matlab to [b,a] = butter(2,0.4);
     a[0] = 1.0000;
@@ -49,8 +50,7 @@
 
 
     // forwards filtering
-    for (unsigned int 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;
         inp1 = df[i];
@@ -60,22 +60,19 @@
 
     // copy forwards filtering to df...
     // but, time-reversed, ready for backwards filtering
-    for (unsigned int i = 0;i < df.size();i++)
-    {
+    for (unsigned int i = 0;i < df.size();i++) {
         df[i] = lp_df[df.size()-i-1];
     }
 
-    for (unsigned int i = 0;i < df.size();i++)
-    {
+    for (unsigned int i = 0;i < df.size();i++) {
         lp_df[i] = 0.;
     }
 
     inp1 = 0.; inp2 = 0.;
     out1 = 0.; out2 = 0.;
 
-  // backwards filetering on time-reversed df
-    for (unsigned int i = 0;i < df.size();i++)
-    {
+    // backwards filetering on time-reversed df
+    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;
         inp1 = df[i];
@@ -83,9 +80,8 @@
         out1 = lp_df[i];
     }
 
-  // write the re-reversed (i.e. forward) version back to df
-    for (unsigned int i = 0;i < df.size();i++)
-    {
+    // write the re-reversed (i.e. forward) version back to df
+    for (unsigned int i = 0;i < df.size();i++) {
         df[i] = lp_df[df.size()-i-1];
     }
 }
@@ -119,29 +115,19 @@
     // this might (will?) break if a user specifies a different frame rate for the onset detection function
     double rayparam = (60*44100/512)/inputtempo;
 
-    // these debug statements can be removed.
-//    std::cerr << "inputtempo" << inputtempo << std::endl;
-//    std::cerr << "rayparam" << rayparam << std::endl;
-//    std::cerr << "constraintempo" << constraintempo << std::endl;
-
     // make rayleigh weighting curve
     d_vec_t wv(wv_len);
 
     // check whether or not to use rayleigh weighting (if constraintempo is false)
     // or use gaussian weighting it (constraintempo is true)
-    if (constraintempo)
-    {
-        for (unsigned int i=0; i<wv.size(); i++)
-        {
+    if (constraintempo) {
+        for (unsigned int i=0; i<wv.size(); i++) {
             // MEPD 28/11/12
             // do a gaussian weighting instead of rayleigh
             wv[i] = exp( (-1.*pow((static_cast<double> (i)-rayparam),2.)) / (2.*pow(rayparam/4.,2.)) );
         }
-    }
-    else
-    {
-        for (unsigned int i=0; i<wv.size(); i++)
-        {
+    } else {
+        for (unsigned int i=0; i<wv.size(); i++) {
             // MEPD 28/11/12
             // standard rayleigh weighting over periodicities
             wv[i] = (static_cast<double> (i) / pow(rayparam,2.)) * exp((-1.*pow(-static_cast<double> (i),2.)) / (2.*pow(rayparam,2.)));
@@ -157,12 +143,11 @@
     int col_counter = -1;
 
     // main loop for beat period calculation
-    for (unsigned int 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 (unsigned int k=0; k<winlen; k++)
-        {
+        for (unsigned int k=0; k<winlen; k++) {
             dfframe[k] = df[i+k];
         }
         // get rcf vector for current frame
@@ -171,8 +156,7 @@
 
         rcfmat.push_back( d_vec_t() ); // adds a new column
         col_counter++;
-        for (unsigned int j=0; j<rcf.size(); j++)
-        {
+        for (unsigned int j=0; j<rcf.size(); j++) {
             rcfmat[col_counter].push_back( rcf[j] );
         }
     }
@@ -197,14 +181,11 @@
 
     d_vec_t acf(dfframe.size());
 
-
-    for (unsigned int lag=0; lag<dfframe.size(); lag++)
-    {
+    for (unsigned int lag=0; lag<dfframe.size(); lag++) {
         double sum = 0.;
         double tmp = 0.;
 
-        for (unsigned int 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;
         }
@@ -214,13 +195,10 @@
     // now apply comb filtering
     int numelem = 4;
 
-    for (unsigned int i = 2;i < rcf.size();i++) // max beat period
-    {
-        for (int a = 1;a <= numelem;a++) // number of comb elements
-        {
-            for (int b = 1-a;b <= a-1;b++) // general state using normalisation of comb elements
-            {
-                rcf[i-1] += ( acf[(a*i+b)-1]*wv[i-1] ) / (2.*a-1.);	// calculate value for comb filter row
+    for (unsigned int i = 2;i < rcf.size();i++) { // max beat period
+        for (int a = 1;a <= numelem;a++) { // number of comb elements
+            for (int b = 1-a;b <= a-1;b++) { // general state using normalisation of comb elements
+                rcf[i-1] += ( acf[(a*i+b)-1]*wv[i-1] ) / (2.*a-1.);     // calculate value for comb filter row
             }
         }
     }
@@ -229,15 +207,13 @@
     MathUtilities::adaptiveThreshold(rcf);
 
     double rcfsum =0.;
-    for (unsigned int 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 (unsigned int i=0; i<rcf.size(); i++)
-    {
+    for (unsigned int i=0; i<rcf.size(); i++) {
         rcf[i] /= (rcfsum + EPS);
     }
 }
@@ -250,11 +226,9 @@
 
     // make transition matrix
     d_mat_t tmat;
-    for (unsigned int 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 (unsigned int j=0; j<wv.size(); j++)
-        {
+        for (unsigned int j=0; j<wv.size(); j++) {
             tmat[i].push_back(0.); // fill with zeros initially
         }
     }
@@ -263,10 +237,8 @@
     // formed of Gaussians on diagonal - implies slow tempo change
     double sigma = 8.;
     // don't want really short beat periods, or really long ones
-    for (unsigned int i=20;i <wv.size()-20; i++)
-    {
-        for (unsigned int j=20; j<wv.size()-20; j++)
-        {
+    for (unsigned int i=20;i <wv.size()-20; i++) {
+        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.)) );
         }
@@ -277,18 +249,15 @@
 
     d_mat_t delta;
     i_mat_t psi;
-    for (unsigned int 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 (unsigned int 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
         }
     }
 
-
     unsigned int T = delta.size();
 
     if (T < 2) return; // can't do anything at all meaningful
@@ -296,31 +265,25 @@
     unsigned int Q = delta[0].size();
 
     // initialize first column of delta
-    for (unsigned int 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 (unsigned int i=0; i<Q; i++)
-    {
+    for (unsigned int i=0; i<Q; i++) {
         deltasum += delta[0][i];
     }
-    for (unsigned int i=0; i<Q; i++)
-    {
+    for (unsigned int i=0; i<Q; i++) {
         delta[0][i] /= (deltasum + EPS);
     }
 
-
     for (unsigned int t=1; t<T; t++)
     {
         d_vec_t tmp_vec(Q);
 
-        for (unsigned int j=0; j<Q; j++)
-        {
-            for (unsigned int i=0; i<Q; i++)
-            {
+        for (unsigned int j=0; j<Q; j++) {
+            for (unsigned int i=0; i<Q; i++) {
                 tmp_vec[i] = delta[t-1][i] * tmat[j][i];
             }
 
@@ -333,20 +296,17 @@
 
         // normalise current delta column
         double deltasum = 0.;
-        for (unsigned int i=0; i<Q; i++)
-        {
+        for (unsigned int i=0; i<Q; i++) {
             deltasum += delta[t][i];
         }
-        for (unsigned int i=0; i<Q; i++)
-        {
+        for (unsigned int i=0; i<Q; i++) {
             delta[t][i] /= (deltasum + EPS);
         }
     }
 
     i_vec_t bestpath(T);
     d_vec_t tmp_vec(Q);
-    for (unsigned int i=0; i<Q; i++)
-    {
+    for (unsigned int i=0; i<Q; i++) {
         tmp_vec[i] = delta[T-1][i];
     }
 
@@ -354,8 +314,7 @@
     bestpath[T-1] = get_max_ind(tmp_vec);
 
     // backtrace through index of maximum values in psi
-    for (unsigned int t=T-2; t>0 ;t--)
-    {
+    for (unsigned int t=T-2; t>0 ;t--) {
         bestpath[t] = psi[t+1][bestpath[t+1]];
     }
 
@@ -363,11 +322,9 @@
     bestpath[0] = psi[1][bestpath[1]];
 
     unsigned int lastind = 0;
-    for (unsigned int i=0; i<T; i++)
-    {
+    for (unsigned int i=0; i<T; i++) {
         unsigned int step = 128;
-        for (unsigned int j=0; j<step; j++)
-        {
+        for (unsigned int j=0; j<step; j++) {
             lastind = i*step+j;
             beat_period[lastind] = bestpath[i];
         }
@@ -375,13 +332,11 @@
     }
 
     //fill in the last values...
-    for (unsigned int i=lastind; i<beat_period.size(); i++)
-    {
+    for (unsigned int i=lastind; i<beat_period.size(); i++) {
         beat_period[i] = beat_period[lastind];
     }
 
-    for (unsigned int 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]);
     }
 }
@@ -390,10 +345,8 @@
 TempoTrackV2::get_max_val(const d_vec_t &df)
 {
     double maxval = 0.;
-    for (unsigned int i=0; i<df.size(); i++)
-    {
-        if (maxval < df[i])
-        {
+    for (unsigned int i=0; i<df.size(); i++) {
+        if (maxval < df[i]) {
             maxval = df[i];
         }
     }
@@ -406,10 +359,8 @@
 {
     double maxval = 0.;
     int ind = 0;
-    for (unsigned int i=0; i<df.size(); i++)
-    {
-        if (maxval < df[i])
-        {
+    for (unsigned int i=0; i<df.size(); i++) {
+        if (maxval < df[i]) {
             maxval = df[i];
             ind = i;
         }
@@ -422,13 +373,11 @@
 TempoTrackV2::normalise_vec(d_vec_t &df)
 {
     double sum = 0.;
-    for (unsigned int i=0; i<df.size(); i++)
-    {
+    for (unsigned int i=0; i<df.size(); i++) {
         sum += df[i];
     }
 
-    for (unsigned int i=0; i<df.size(); i++)
-    {
+    for (unsigned int i=0; i<df.size(); i++) {
         df[i]/= (sum + EPS);
     }
 }
@@ -448,8 +397,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 (unsigned int i=0; i<df.size(); i++)
-    {
+    for (unsigned int i=0; i<df.size(); i++) {
         localscore[i] = df[i];
         backlink[i] = -1;
     }
@@ -462,8 +410,8 @@
 //    std::cerr << "tightness" << tightness << std::endl;
 
     // main loop
-    for (unsigned int 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]);
 
@@ -471,8 +419,8 @@
         d_vec_t txwt (prange_max - prange_min + 1);
         d_vec_t scorecands (txwt.size());
 
-        for (unsigned int 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));
 
@@ -480,8 +428,7 @@
             // ELSE LEAVE AT DEFAULT VALUE FROM INITIALISATION:  D_VEC_T SCORECANDS (TXWT.SIZE());
 
             int cscore_ind = i+prange_min+j;
-            if (cscore_ind >= 0)
-            {
+            if (cscore_ind >= 0) {
                 scorecands[j] = txwt[j] * cumscore[cscore_ind];
             }
         }
@@ -498,23 +445,24 @@
 
     // STARTING POINT, I.E. LAST BEAT.. PICK A STRONG POINT IN cumscore VECTOR
     d_vec_t tmp_vec;
-    for (unsigned int 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]);
     }
 
-    int startpoint = get_max_ind(tmp_vec) + cumscore.size() - beat_period[beat_period.size()-1] ;
+    int startpoint = get_max_ind(tmp_vec) +
+        cumscore.size() - beat_period[beat_period.size()-1] ;
 
     // can happen if no results obtained earlier (e.g. input too short)
-    if (startpoint >= (int)backlink.size()) startpoint = backlink.size()-1;
+    if (startpoint >= (int)backlink.size()) {
+        startpoint = backlink.size()-1;
+    }
 
     // USE BACKLINK TO GET EACH NEW BEAT (TOWARDS THE BEGINNING OF THE FILE)
     //  BACKTRACKING FROM THE END TO THE BEGINNING.. MAKING SURE NOT TO GO BEFORE SAMPLE 0
     i_vec_t ibeats;
     ibeats.push_back(startpoint);
 //    std::cerr << "startpoint = " << startpoint << std::endl;
-    while (backlink[ibeats.back()] > 0)
-    {
+    while (backlink[ibeats.back()] > 0) {
 //        std::cerr << "backlink[" << ibeats.back() << "] = " << backlink[ibeats.back()] << std::endl;
         int b = ibeats.back();
         if (backlink[b] == b) break; // shouldn't happen... haha
@@ -522,8 +470,7 @@
     }
 
     // REVERSE SEQUENCE OF IBEATS AND STORE AS BEATS
-    for (unsigned int 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]) );
     }
 }