1 /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #ifndef BIQUAD_H_
7 #define BIQUAD_H_
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /* The biquad filter parameters. The transfer function H(z) is (b0 + b1 * z^(-1)
14  * + b2 * z^(-2)) / (1 + a1 * z^(-1) + a2 * z^(-2)).  The previous two inputs
15  * are stored in x1 and x2, and the previous two outputs are stored in y1 and
16  * y2.
17  *
18  * We use double during the coefficients calculation for better accurary, but
19  * float is used during the actual filtering for faster computation.
20  */
21 struct biquad {
22 	float b0, b1, b2;
23 	float a1, a2;
24 	float x1, x2;
25 	float y1, y2;
26 };
27 
28 /* The type of the biquad filters */
29 enum biquad_type {
30 	BQ_NONE,
31 	BQ_LOWPASS,
32 	BQ_HIGHPASS,
33 	BQ_BANDPASS,
34 	BQ_LOWSHELF,
35 	BQ_HIGHSHELF,
36 	BQ_PEAKING,
37 	BQ_NOTCH,
38 	BQ_ALLPASS
39 };
40 
41 /* Initialize a biquad filter parameters from its type and parameters.
42  * Args:
43  *    bq - The biquad filter we want to set.
44  *    type - The type of the biquad filter.
45  *    frequency - The value should be in the range [0, 1]. It is relative to
46  *        half of the sampling rate.
47  *    Q - Quality factor. See Web Audio API for details.
48  *    gain - The value is in dB. See Web Audio API for details.
49  */
50 void biquad_set(struct biquad *bq, enum biquad_type type, double freq, double Q,
51 		double gain);
52 
53 #ifdef __cplusplus
54 } /* extern "C" */
55 #endif
56 
57 #endif /* BIQUAD_H_ */
58