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