diff dsp/tempotracking/DownBeat.cpp @ 479:7e52c034cf62

Untabify, indent, tidy
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 31 May 2019 10:35:08 +0100
parents 00f66226db5b
children bb78ca3fe7de
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]);
+    }
 }