changeset 163:4f092806782b

Fix incorrect handling of decimation factor 1; documentation
author Chris Cannam
date Thu, 30 Jan 2014 09:51:06 +0000
parents a2b3fd07d862
children 4a70fff27b8f
files dsp/rateconversion/Decimator.cpp dsp/rateconversion/Decimator.h
diffstat 2 files changed, 34 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/dsp/rateconversion/Decimator.cpp	Tue Dec 03 10:16:49 2013 +0000
+++ b/dsp/rateconversion/Decimator.cpp	Thu Jan 30 09:51:06 2014 +0000
@@ -199,10 +199,15 @@
 
 void Decimator::process(const double *src, double *dst)
 {
-    if( m_decFactor != 1 )
-    {
-	doAntiAlias( src, decBuffer, m_inputLength );
+    if (m_decFactor == 1) {
+        for( unsigned int i = 0; i < m_outputLength; i++ ) {
+            dst[i] = src[i];
+        }
+        return;
     }
+        
+    doAntiAlias( src, decBuffer, m_inputLength );
+
     unsigned idx = 0;
 
     for( unsigned int i = 0; i < m_outputLength; i++ )
@@ -213,10 +218,15 @@
 
 void Decimator::process(const float *src, float *dst)
 {
-    if( m_decFactor != 1 )
-    {
-	doAntiAlias( src, decBuffer, m_inputLength );
+    if (m_decFactor == 1) {
+        for( unsigned int i = 0; i < m_outputLength; i++ ) {
+            dst[i] = src[i];
+        }
+        return;
     }
+
+    doAntiAlias( src, decBuffer, m_inputLength );
+
     unsigned idx = 0;
 
     for( unsigned int i = 0; i < m_outputLength; i++ )
--- a/dsp/rateconversion/Decimator.h	Tue Dec 03 10:16:49 2013 +0000
+++ b/dsp/rateconversion/Decimator.h	Thu Jan 30 09:51:06 2014 +0000
@@ -24,9 +24,6 @@
 class Decimator  
 {
 public:
-    void process( const double* src, double* dst );
-    void process( const float* src, float* dst );
-
     /**
      * Construct a Decimator to operate on input blocks of length
      * inLength, with decimation factor decFactor.  inLength should be
@@ -40,11 +37,28 @@
     Decimator( unsigned int inLength, unsigned int decFactor );
     virtual ~Decimator();
 
+    /**
+     * Process inLength samples (as supplied to constructor) from src
+     * and write inLength / decFactor samples to dst.  Note that src
+     * and dst may be the same or overlap (an intermediate buffer is
+     * used).
+     */
+    void process( const double* src, double* dst );
+
+    /**
+     * Process inLength samples (as supplied to constructor) from src
+     * and write inLength / decFactor samples to dst.  Note that src
+     * and dst may be the same or overlap (an intermediate buffer is
+     * used).
+     */
+    void process( const float* src, float* dst );
+
     int getFactor() const { return m_decFactor; }
     static int getHighestSupportedFactor() { return 8; }
 
+    void resetFilter();
+
 private:
-    void resetFilter();
     void deInitialise();
     void initialise( unsigned int inLength, unsigned int decFactor );
     void doAntiAlias( const double* src, double* dst, unsigned int length );