xref: /titanic_44/usr/src/cmd/audio/include/Fir.h (revision bde3d612a7c090234c60e6e4578821237a5db135)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Finite Impulse Response (FIR) filter object
38  *
39  * For every input sample, the FIR filter generates an output sample:
40  * output =	coef[0] * input +
41  *		coef[1] * state[order - 1] +
42  *		coef[2] * state[order - 2] +
43  *		...
44  *		coef[order] * state[0]
45  *
46  * and the filter states are updated:
47  *	state[0] = state[1]
48  *	state[1] = state[2]
49  *	...
50  *	state[order - 2] = state[order - 1]
51  *	state[order - 1] = input
52  */
53 class Fir {
54 protected:
55 	int		order;		// filter order, # taps = order + 1
56 	double		*coef;		// (order + 1) filter coeffs.
57 	double		*state;		// "order" filter states
58 	int		delay;		// actual delay between output & input
59 
60 	virtual void	updateState(double *data, int size);
61 	virtual void	update_short(short *data, int size);
62 	virtual int	flush(short *out);
63 public:
64 	virtual void	resetState(void);	// reset states to zero
65 	Fir(void);
66 	Fir(int order_in);
67 	~Fir();
68 	virtual int	getOrder(void);		// get filter order value
69 	virtual int	getNumCoefs(void);	// get number of coefficients
70 	virtual void	putCoef(double *coef_in); // put coef_in in filter coef
71 	virtual void	getCoef(double *coef_out); // get filter coef
72 	// filter "size" input samples for "size" output samples
73 	virtual int	filter_noadjust(short *in, int size, short *out);
74 	/*
75 	 * filter "size" input samples. Output sample sequence is offset by
76 	 * group delay samples to align with the input sample sequence.
77 	 * the first call of this routine returns "size - group_delay"
78 	 * output samples. Call this routine with size = 0
79 	 * to fill the output buffer such that the total number of output
80 	 * samples is equal to the number of input samples.
81 	 */
82 	virtual int	getFlushSize(void); // size of out[] for the last call
83 	virtual int	filter(short *in, int size, short *out);
84 };
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif /* !_MULTIMEDIA_FIR_H */
91