BEAST/BSE - Better Audio System and Sound Engine  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bsefilter.hh
Go to the documentation of this file.
1  // CC0 Public Domain: http://creativecommons.org/publicdomain/zero/1.0/
2 #ifndef BSE_FILTER_H__
3 #define BSE_FILTER_H__
4 #include <bse/bsemath.hh>
5 
6 extern "C" {
7 
8 typedef enum /*< skip >*/
9 {
10  BSE_IIR_FILTER_BUTTERWORTH = 1,
11  BSE_IIR_FILTER_BESSEL = 2,
12  BSE_IIR_FILTER_CHEBYSHEV1 = 3,
13  BSE_IIR_FILTER_CHEBYSHEV2 = 4,
14  BSE_IIR_FILTER_ELLIPTIC = 5,
15 } BseIIRFilterKind;
16 
17 typedef enum /*< skip >*/
18 {
19  BSE_IIR_FILTER_LOW_PASS = 1,
20  BSE_IIR_FILTER_BAND_PASS = 2,
21  BSE_IIR_FILTER_HIGH_PASS = 3,
22  BSE_IIR_FILTER_BAND_STOP = 4,
23 } BseIIRFilterType;
24 
25 typedef struct {
26  BseIIRFilterKind kind;
27  BseIIRFilterType type;
28  uint order; /* >= 1 */
29  double sampling_frequency; /* Hz, > 0.0 && == 2 * nyquist_frequency */
30  double passband_ripple_db; /* dB, > 0.0, Chebyshev1 or elliptic */
31  double passband_edge; /* Hz, > 0.0 && < nyquist_frequency */
32  double passband_edge2; /* Hz, > 0.0 && < nyquist_frequency, for BAND filters */
33  double stopband_edge; /* Hz, > 0.0, replaces stopband_db, elliptic only */
34  double stopband_db; /* dB, < 0.0, elliptic only */
36 
37 #define BSE_IIR_MAX_ORDER (64)
38 #define BSE_IIR_CARRAY_SIZE (4 * BSE_IIR_MAX_ORDER + 2) /* size of arrays used to store coefficients */
39 
40 typedef struct {
41  double sampling_frequency; /* same as BseIIRFilterRequest.sampling_frequency */
42  uint order;
43  double center_frequency;
44  /* z-plane poles and zeros */
45  double gain;
46  uint n_zeros;
47  BseComplex zz[BSE_IIR_CARRAY_SIZE / 2]; /* z-plane zeros [order] */
48  uint n_poles;
49  BseComplex zp[BSE_IIR_CARRAY_SIZE / 2]; /* z-plane poles [order] */
50  /* normalized z-plane transfer function */
51  // double zn[BSE_IIR_CARRAY_SIZE]; /* numerator coefficients [order+1] */
52  // double zd[BSE_IIR_CARRAY_SIZE]; /* denominator coefficients [order+1] */
54 
55 typedef struct {
56  double xz2; // x[i-2] coefficient
57  double xz1; // x[i-1] coefficient
58  double yz2; // y[i-2] coefficient
59  double yz1; // y[i-1] coefficient
60 } BseIIRStage;
61 
62 typedef struct {
63  uint order;
64  BseIIRStage *stages;
65  double *states; /* [0..2*order] */
66 } BseIIRFilter;
67 
68 
69 bool bse_iir_filter_design (const BseIIRFilterRequest *filter_request,
70  BseIIRFilterDesign *filter_design);
71 BseIIRFilter* bse_iir_filter_new (const BseIIRFilterDesign *filter_design);
72 void bse_iir_filter_change (BseIIRFilter *filter,
73  const BseIIRFilterDesign *filter_design);
74 void bse_iir_filter_eval (BseIIRFilter *filter,
75  uint n_values,
76  const float *x,
77  float *y);
78 void bse_iir_filter_free (BseIIRFilter *filter);
79 const gchar* bse_iir_filter_kind_string (BseIIRFilterKind fkind);
80 const gchar* bse_iir_filter_type_string (BseIIRFilterType ftype);
81 gchar* bse_iir_filter_request_string (const BseIIRFilterRequest *filter_request);
82 gchar* bse_iir_filter_design_string (const BseIIRFilterDesign *filter_design);
83 gchar* bse_iir_filter_string (const BseIIRFilter *filter);
84 /* --- internal prototypes --- */
85 bool _bse_filter_design_ellf (const BseIIRFilterRequest *ifr,
86  BseIIRFilterDesign *fid);
87 
88 } // "C"
89 
90 #endif /* BSE_FILTER_H__ */ /* vim:set ts=8 sw=2 sts=2: */
Definition: bsemath.hh:39
Definition: bsefilter.hh:62
Definition: bsefilter.hh:55
Definition: bsefilter.hh:25
Definition: bsefilter.hh:40