changeset 502:162673c8f9de

Style fixes: avoid unsigned, fix formatting
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 05 Jun 2019 11:05:58 +0100
parents 12b5a9244bb0
children b1f72e469ec8
files dsp/signalconditioning/Framer.cpp dsp/signalconditioning/Framer.h dsp/tempotracking/TempoTrack.h dsp/tempotracking/TempoTrackV2.cpp
diffstat 4 files changed, 60 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/dsp/signalconditioning/Framer.cpp	Wed Jun 05 10:21:48 2019 +0100
+++ b/dsp/signalconditioning/Framer.cpp	Wed Jun 05 11:05:58 2019 +0100
@@ -14,74 +14,65 @@
 */
 
 #include "Framer.h"
-#include <cmath>
-#include <cstddef>
 
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
+#include <limits.h>
 
-Framer::Framer()
+Framer::Framer() :
+    m_sampleLen(0),
+    m_framesRead(0),
+    m_srcBuffer(0),
+    m_dataFrame(0),
+    m_strideFrame(0),
+    m_frameLength(0),
+    m_stepSize(0),
+    m_maxFrames(0),
+    m_srcIndex(0)
 {
-    m_dataFrame = NULL;
-    m_strideFrame = NULL;
 }
 
 Framer::~Framer()
 {
-    if( m_dataFrame != NULL ) {
-        delete [] m_dataFrame;
-    }
-
-    if( m_strideFrame != NULL ) {
-        delete [] m_strideFrame;
-    }
+    delete[] m_dataFrame;
+    delete[] m_strideFrame;
 }
 
-void Framer::configure( unsigned int frameLength, unsigned int hop )
+void Framer::configure(int frameLength, int hop)
 {
     m_frameLength = frameLength;
     m_stepSize = hop;
 
     resetCounters();
 
-    if( m_dataFrame != NULL ) {
-        delete [] m_dataFrame;  
-        m_dataFrame = NULL;
-    }
+    delete[] m_dataFrame;  
     m_dataFrame = new double[ m_frameLength ];
 
-    if( m_strideFrame != NULL ) {
-        delete [] m_strideFrame;        
-        m_strideFrame = NULL;
-    }
+    delete [] m_strideFrame;        
     m_strideFrame = new double[ m_stepSize ];
 }
 
 void Framer::getFrame(double *dst)
 {
+    if ((m_srcIndex + int64_t(m_frameLength)) < m_sampleLen) {
 
-    if( (m_ulSrcIndex + ( m_frameLength) ) < m_ulSampleLen ) {
+        for (int i = 0; i < m_frameLength; i++) {
+            dst[i] = m_srcBuffer[m_srcIndex++]; 
+        }
+        m_srcIndex -= (m_frameLength - m_stepSize);
 
-        for( unsigned int u = 0; u < m_frameLength; u++) {
-            dst[ u ] = m_srcBuffer[ m_ulSrcIndex++ ]; 
-        }       
-        m_ulSrcIndex -= ( m_frameLength - m_stepSize );
+    } else { // m_srcIndex is within m_frameLength of m_sampleLen
 
-    } else {
+        int rem = int(m_sampleLen - m_srcIndex);
+        int zero = m_frameLength - rem;
 
-        unsigned int rem = (m_ulSampleLen - m_ulSrcIndex );
-        unsigned int zero = m_frameLength - rem;
-
-        for( unsigned int u = 0; u < rem; u++ ) {
-            dst[ u ] = m_srcBuffer[ m_ulSrcIndex++ ];
+        for (int i = 0; i < rem; i++) {
+            dst[i] = m_srcBuffer[m_srcIndex++];
         }
                 
-        for( unsigned int u = 0; u < zero; u++ ) {
-            dst[ rem + u ] = 0;
+        for (int i = 0; i < zero; i++ ) {
+            dst[rem + i] = 0.0;
         }
 
-        m_ulSrcIndex -= (( rem - m_stepSize ) );
+        m_srcIndex -= (rem - m_stepSize);
     }
 
     m_framesRead++;
@@ -90,18 +81,23 @@
 void Framer::resetCounters()
 {
     m_framesRead = 0;
-    m_ulSrcIndex = 0;
+    m_srcIndex = 0;
 }
 
-unsigned int Framer::getMaxNoFrames()
+int Framer::getMaxNoFrames()
 {
     return m_maxFrames;
 }
 
-void Framer::setSource(double *src, unsigned int length)
+void Framer::setSource(double *src, int64_t length)
 {
     m_srcBuffer = src;
-    m_ulSampleLen = length;
+    m_sampleLen = length;
 
-    m_maxFrames = (unsigned int)ceil( (double)m_ulSampleLen/(double)m_stepSize ) ;
+    int64_t maxFrames = length / int64_t(m_stepSize);
+    if (maxFrames * int64_t(m_stepSize) < length) {
+        ++maxFrames;
+    }
+    if (maxFrames > INT_MAX) maxFrames = INT_MAX;
+    m_maxFrames = maxFrames;
 }
--- a/dsp/signalconditioning/Framer.h	Wed Jun 05 10:21:48 2019 +0100
+++ b/dsp/signalconditioning/Framer.h	Wed Jun 05 11:05:58 2019 +0100
@@ -16,31 +16,35 @@
 #ifndef QM_DSP_FRAMER_H
 #define QM_DSP_FRAMER_H
 
+#include <stdint.h>
+
 class Framer  
 {
 public:
-    void setSource( double* src, unsigned int length );
-    unsigned int getMaxNoFrames();
-    void getFrame( double* dst );
-    void configure( unsigned int frameLength, unsigned int hop );
     Framer();
     virtual ~Framer();
 
+    void setSource(double* src, int64_t length);
+    void configure(int frameLength, int hop);
+    
+    int getMaxNoFrames();
+    void getFrame(double* dst);
+
     void resetCounters();
 
 private:
-    unsigned long       m_ulSampleLen;          // DataLength (samples)
-    unsigned int        m_framesRead;           // Read Frames Index
+    int64_t m_sampleLen;          // DataLength (samples)
+    int m_framesRead;             // Read Frames Index
+ 
+    double* m_srcBuffer;
+    double* m_dataFrame;          // Analysis Frame Buffer
+    double* m_strideFrame;        // Stride Frame Buffer
+    int m_frameLength;            // Analysis Frame Length
+    int m_stepSize;               // Analysis Frame Stride
 
-    double*             m_srcBuffer;
-    double*             m_dataFrame;            // Analysis Frame Buffer
-    double*             m_strideFrame;          // Stride Frame Buffer
-    unsigned int        m_frameLength;          // Analysis Frame Length
-    unsigned int        m_stepSize;             // Analysis Frame Stride
+    int m_maxFrames;
 
-    unsigned int        m_maxFrames;
-
-    unsigned long       m_ulSrcIndex;
+    int64_t m_srcIndex;
 };
 
 #endif
--- a/dsp/tempotracking/TempoTrack.h	Wed Jun 05 10:21:48 2019 +0100
+++ b/dsp/tempotracking/TempoTrack.h	Wed Jun 05 11:05:58 2019 +0100
@@ -96,7 +96,7 @@
     // 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;
--- a/dsp/tempotracking/TempoTrackV2.cpp	Wed Jun 05 10:21:48 2019 +0100
+++ b/dsp/tempotracking/TempoTrackV2.cpp	Wed Jun 05 11:05:58 2019 +0100
@@ -269,11 +269,11 @@
         }
     }
 
-    int T = delta.size();
+    int T = int(delta.size());
 
     if (T < 2) return; // can't do anything at all meaningful
 
-    int Q = delta[0].size();
+    int Q = int(delta[0].size());
 
     // initialize first column of delta
     for (int j = 0; j < Q; j++) {