qm-dsp  1.8
Filter.cpp
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     QM DSP Library
00005 
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file 2005-2006 Christian Landone.
00008 
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #include "Filter.h"
00017 
00019 // Construction/Destruction
00021 
00022 Filter::Filter( FilterConfig Config )
00023 {
00024     m_ord = 0;
00025     m_outBuffer = NULL;
00026     m_inBuffer = NULL;
00027 
00028     initialise( Config );
00029 }
00030 
00031 Filter::~Filter()
00032 {
00033     deInitialise();
00034 }
00035 
00036 void Filter::initialise( FilterConfig Config )
00037 {
00038     m_ord = Config.ord;
00039     m_ACoeffs = Config.ACoeffs;
00040     m_BCoeffs = Config.BCoeffs;
00041 
00042     m_inBuffer = new double[ m_ord + 1 ];
00043     m_outBuffer = new double[ m_ord + 1 ];
00044 
00045     reset();
00046 }
00047 
00048 void Filter::deInitialise()
00049 {
00050     delete[] m_inBuffer;
00051     delete[] m_outBuffer;
00052 }
00053 
00054 void Filter::reset()
00055 {
00056     for( unsigned int i = 0; i < m_ord+1; i++ ){ m_inBuffer[ i ] = 0.0; }
00057     for(unsigned int  i = 0; i < m_ord+1; i++ ){ m_outBuffer[ i ] = 0.0; }
00058 }
00059 
00060 void Filter::process( double *src, double *dst, unsigned int length )
00061 {
00062     unsigned int SP,i,j;
00063 
00064     double xin,xout;
00065 
00066     for (SP=0;SP<length;SP++)
00067     {
00068         xin=src[SP];
00069         /* move buffer */
00070         for ( i = 0; i < m_ord; i++) {m_inBuffer[ m_ord - i ]=m_inBuffer[ m_ord - i - 1 ];}
00071         m_inBuffer[0]=xin;
00072 
00073         xout=0.0;
00074         for (j=0;j< m_ord + 1; j++)
00075             xout = xout + m_BCoeffs[ j ] * m_inBuffer[ j ];
00076         for (j = 0; j < m_ord; j++)
00077             xout= xout - m_ACoeffs[ j + 1 ] * m_outBuffer[ j ];
00078 
00079         dst[ SP ] = xout;
00080         for ( i = 0; i < m_ord - 1; i++ ) { m_outBuffer[ m_ord - i - 1 ] = m_outBuffer[ m_ord - i - 2 ];}
00081         m_outBuffer[0]=xout;
00082 
00083     } /* end of SP loop */
00084 }
00085 
00086 
00087