Home | History | Annotate | Download | only in include
      1 /*---------------------------------------------------------------------------*
      2  *  filter.h  *
      3  *                                                                           *
      4  *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
      5  *                                                                           *
      6  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
      7  *  you may not use this file except in compliance with the License.         *
      8  *                                                                           *
      9  *  You may obtain a copy of the License at                                  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0                           *
     11  *                                                                           *
     12  *  Unless required by applicable law or agreed to in writing, software      *
     13  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
     14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
     15  *  See the License for the specific language governing permissions and      *
     16  *  limitations under the License.                                           *
     17  *                                                                           *
     18  *---------------------------------------------------------------------------*/
     19 
     20 #ifndef __FILTER_H__
     21 #define __FILTER_H__
     22 
     23 // Define new data types
     24 
     25 typedef short typeSample;  // for input and output samples
     26 typedef short typeCoeff;   // FIR filter coefficients
     27 typedef long  typeAccum;   // FIR filter accumulator
     28 
     29 #define FACTOR_UP                       1     // upsampling factor
     30 #define FACTOR_DOWN                     4     // downsampling factor
     31 
     32 #define u16ScaleFilterCoeff_up1_down4  15
     33 
     34 typedef struct fir_struct
     35 {
     36    int              state;   // state of FIR delay line (index of next slot to fill)
     37    typeSample      *z;       // pointer to delay line
     38 
     39    unsigned int     factor_up;
     40    unsigned int     factor_down;
     41 
     42    unsigned int     nTaps;   // length of FIR filter
     43    unsigned int     scale;   // fixed-point filter scale factor
     44    const typeCoeff *h;       // pointer to FIR filter coefficients
     45    typeAccum        round;   // used for roundoff
     46 } FIR_struct;
     47 
     48 extern const typeCoeff ps16FilterCoeff_up1_down4[];
     49 
     50 extern unsigned int filter_length;
     51 
     52 extern  void FIR_downsample(unsigned int nInput, typeSample *pInput,
     53 			   typeSample *pOutput, FIR_struct *pFIR);
     54 
     55 extern  FIR_struct* FIR_construct(unsigned int nTaps, const typeCoeff *pCoeffs, int scale, int factor_up, int factor_down);
     56 
     57 extern  int FIR_deconstruct(FIR_struct *pFIR);
     58 
     59 extern  void FIR_reset(FIR_struct *pFIR);
     60 
     61 #endif
     62