1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 1992-2001 by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 #ifndef _MULTIMEDIA_FIR_H 28 #define _MULTIMEDIA_FIR_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 /* 35 * Finite Impulse Response (FIR) filter object 36 * 37 * For every input sample, the FIR filter generates an output sample: 38 * output = coef[0] * input + 39 * coef[1] * state[order - 1] + 40 * coef[2] * state[order - 2] + 41 * ... 42 * coef[order] * state[0] 43 * 44 * and the filter states are updated: 45 * state[0] = state[1] 46 * state[1] = state[2] 47 * ... 48 * state[order - 2] = state[order - 1] 49 * state[order - 1] = input 50 */ 51 class Fir { 52 protected: 53 int order; // filter order, # taps = order + 1 54 double *coef; // (order + 1) filter coeffs. 55 double *state; // "order" filter states 56 int delay; // actual delay between output & input 57 58 virtual void updateState(double *data, int size); 59 virtual void update_short(short *data, int size); 60 virtual int flush(short *out); 61 public: 62 virtual void resetState(void); // reset states to zero 63 Fir(void); 64 Fir(int order_in); 65 ~Fir(); 66 virtual int getOrder(void); // get filter order value 67 virtual int getNumCoefs(void); // get number of coefficients 68 virtual void putCoef(double *coef_in); // put coef_in in filter coef 69 virtual void getCoef(double *coef_out); // get filter coef 70 // filter "size" input samples for "size" output samples 71 virtual int filter_noadjust(short *in, int size, short *out); 72 /* 73 * filter "size" input samples. Output sample sequence is offset by 74 * group delay samples to align with the input sample sequence. 75 * the first call of this routine returns "size - group_delay" 76 * output samples. Call this routine with size = 0 77 * to fill the output buffer such that the total number of output 78 * samples is equal to the number of input samples. 79 */ 80 virtual int getFlushSize(void); // size of out[] for the last call 81 virtual int filter(short *in, int size, short *out); 82 }; 83 84 #ifdef __cplusplus 85 } 86 #endif 87 88 #endif /* !_MULTIMEDIA_FIR_H */ 89