Beast - Music Synthesizer and Composer  0.11.1+10.g2da35
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 #include <bse/bseenums.hh>
6 
7 typedef struct {
8  BseIIRFilterKind kind;
9  BseIIRFilterType type;
10  uint order; /* >= 1 */
11  double sampling_frequency; /* Hz, > 0.0 && == 2 * nyquist_frequency */
12  double passband_ripple_db; /* dB, > 0.0, Chebyshev1 or elliptic */
13  double passband_edge; /* Hz, > 0.0 && < nyquist_frequency */
14  double passband_edge2; /* Hz, > 0.0 && < nyquist_frequency, for BAND filters */
15  double stopband_edge; /* Hz, > 0.0, replaces stopband_db, elliptic only */
16  double stopband_db; /* dB, < 0.0, elliptic only */
18 
19 #define BSE_IIR_MAX_ORDER (64)
20 #define BSE_IIR_CARRAY_SIZE (4 * BSE_IIR_MAX_ORDER + 2) /* size of arrays used to store coefficients */
21 
22 typedef struct {
23  double sampling_frequency; /* same as BseIIRFilterRequest.sampling_frequency */
24  uint order;
25  double center_frequency;
26  /* z-plane poles and zeros */
27  double gain;
28  uint n_zeros;
29  BseComplex zz[BSE_IIR_CARRAY_SIZE / 2]; /* z-plane zeros [order] */
30  uint n_poles;
31  BseComplex zp[BSE_IIR_CARRAY_SIZE / 2]; /* z-plane poles [order] */
32  /* normalized z-plane transfer function */
33  // double zn[BSE_IIR_CARRAY_SIZE]; /* numerator coefficients [order+1] */
34  // double zd[BSE_IIR_CARRAY_SIZE]; /* denominator coefficients [order+1] */
36 
37 typedef struct {
38  double xz2; // x[i-2] coefficient
39  double xz1; // x[i-1] coefficient
40  double yz2; // y[i-2] coefficient
41  double yz1; // y[i-1] coefficient
42 } BseIIRStage;
43 
44 typedef struct {
45  uint order;
46  BseIIRStage *stages;
47  double *states; /* [0..2*order] */
48 } BseIIRFilter;
49 
50 
51 bool bse_iir_filter_design (const BseIIRFilterRequest *filter_request,
52  BseIIRFilterDesign *filter_design);
53 BseIIRFilter* bse_iir_filter_new (const BseIIRFilterDesign *filter_design);
54 void bse_iir_filter_change (BseIIRFilter *filter,
55  const BseIIRFilterDesign *filter_design);
56 void bse_iir_filter_eval (BseIIRFilter *filter,
57  uint n_values,
58  const float *x,
59  float *y);
60 void bse_iir_filter_free (BseIIRFilter *filter);
61 const gchar* bse_iir_filter_kind_string (BseIIRFilterKind fkind);
62 const gchar* bse_iir_filter_type_string (BseIIRFilterType ftype);
63 gchar* bse_iir_filter_request_string (const BseIIRFilterRequest *filter_request);
64 gchar* bse_iir_filter_design_string (const BseIIRFilterDesign *filter_design);
65 gchar* bse_iir_filter_string (const BseIIRFilter *filter);
66 /* --- internal prototypes --- */
67 bool _bse_filter_design_ellf (const BseIIRFilterRequest *ifr,
68  BseIIRFilterDesign *fid);
69 
70 #endif /* BSE_FILTER_H__ */ /* vim:set ts=8 sw=2 sts=2: */
Definition: bsemath.hh:37
Definition: bsefilter.hh:44
Definition: bsefilter.hh:37
Definition: bsefilter.hh:7
Definition: bsefilter.hh:22