# HG changeset patch # User Chris Cannam # Date 1391075466 0 # Node ID 4f092806782b309ac5d4cdc76d1eb6bcd20306cb # Parent a2b3fd07d8627c4918e2a1d5fef8c19a171725aa Fix incorrect handling of decimation factor 1; documentation diff -r a2b3fd07d862 -r 4f092806782b dsp/rateconversion/Decimator.cpp --- 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++ ) diff -r a2b3fd07d862 -r 4f092806782b dsp/rateconversion/Decimator.h --- 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 );