• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 };
25 
26 /* The type of the biquad filters */
27 enum biquad_type {
28 	BQ_LOWPASS,
29 	BQ_HIGHPASS,
30 };
31 
32 /* Initialize a biquad filter parameters from its type and parameters.
33  * Args:
34  *    bq - The biquad filter we want to set.
35  *    type - The type of the biquad filter.
36  *    frequency - The value should be in the range [0, 1]. It is relative to
37  *        half of the sampling rate.
38  */
39 void biquad_set(struct biquad *bq, enum biquad_type type, double freq);
40 
41 #ifdef __cplusplus
42 } /* extern "C" */
43 #endif
44 
45 #endif /* BIQUAD_H_ */
46