BEAST/BSE - Better Audio System and Sound Engine
0.8.2
|
00001 // CC0 Public Domain: http://creativecommons.org/publicdomain/zero/1.0/ 00002 #ifndef BSE_FILTER_H__ 00003 #define BSE_FILTER_H__ 00004 #include <bse/bsemath.hh> 00005 00006 extern "C" { 00007 00008 typedef enum /*< skip >*/ 00009 { 00010 BSE_IIR_FILTER_BUTTERWORTH = 1, 00011 BSE_IIR_FILTER_BESSEL = 2, 00012 BSE_IIR_FILTER_CHEBYSHEV1 = 3, 00013 BSE_IIR_FILTER_CHEBYSHEV2 = 4, 00014 BSE_IIR_FILTER_ELLIPTIC = 5, 00015 } BseIIRFilterKind; 00016 00017 typedef enum /*< skip >*/ 00018 { 00019 BSE_IIR_FILTER_LOW_PASS = 1, 00020 BSE_IIR_FILTER_BAND_PASS = 2, 00021 BSE_IIR_FILTER_HIGH_PASS = 3, 00022 BSE_IIR_FILTER_BAND_STOP = 4, 00023 } BseIIRFilterType; 00024 00025 typedef struct { 00026 BseIIRFilterKind kind; 00027 BseIIRFilterType type; 00028 uint order; /* >= 1 */ 00029 double sampling_frequency; /* Hz, > 0.0 && == 2 * nyquist_frequency */ 00030 double passband_ripple_db; /* dB, > 0.0, Chebyshev1 or elliptic */ 00031 double passband_edge; /* Hz, > 0.0 && < nyquist_frequency */ 00032 double passband_edge2; /* Hz, > 0.0 && < nyquist_frequency, for BAND filters */ 00033 double stopband_edge; /* Hz, > 0.0, replaces stopband_db, elliptic only */ 00034 double stopband_db; /* dB, < 0.0, elliptic only */ 00035 } BseIIRFilterRequest; 00036 00037 #define BSE_IIR_MAX_ORDER (64) 00038 #define BSE_IIR_CARRAY_SIZE (4 * BSE_IIR_MAX_ORDER + 2) /* size of arrays used to store coefficients */ 00039 00040 typedef struct { 00041 double sampling_frequency; /* same as BseIIRFilterRequest.sampling_frequency */ 00042 uint order; 00043 double center_frequency; 00044 /* z-plane poles and zeros */ 00045 double gain; 00046 uint n_zeros; 00047 BseComplex zz[BSE_IIR_CARRAY_SIZE / 2]; /* z-plane zeros [order] */ 00048 uint n_poles; 00049 BseComplex zp[BSE_IIR_CARRAY_SIZE / 2]; /* z-plane poles [order] */ 00050 /* normalized z-plane transfer function */ 00051 // double zn[BSE_IIR_CARRAY_SIZE]; /* numerator coefficients [order+1] */ 00052 // double zd[BSE_IIR_CARRAY_SIZE]; /* denominator coefficients [order+1] */ 00053 } BseIIRFilterDesign; 00054 00055 typedef struct { 00056 double xz2; // x[i-2] coefficient 00057 double xz1; // x[i-1] coefficient 00058 double yz2; // y[i-2] coefficient 00059 double yz1; // y[i-1] coefficient 00060 } BseIIRStage; 00061 00062 typedef struct { 00063 uint order; 00064 BseIIRStage *stages; 00065 double *states; /* [0..2*order] */ 00066 } BseIIRFilter; 00067 00068 00069 bool bse_iir_filter_design (const BseIIRFilterRequest *filter_request, 00070 BseIIRFilterDesign *filter_design); 00071 BseIIRFilter* bse_iir_filter_new (const BseIIRFilterDesign *filter_design); 00072 void bse_iir_filter_change (BseIIRFilter *filter, 00073 const BseIIRFilterDesign *filter_design); 00074 void bse_iir_filter_eval (BseIIRFilter *filter, 00075 uint n_values, 00076 const float *x, 00077 float *y); 00078 void bse_iir_filter_free (BseIIRFilter *filter); 00079 const gchar* bse_iir_filter_kind_string (BseIIRFilterKind fkind); 00080 const gchar* bse_iir_filter_type_string (BseIIRFilterType ftype); 00081 gchar* bse_iir_filter_request_string (const BseIIRFilterRequest *filter_request); 00082 gchar* bse_iir_filter_design_string (const BseIIRFilterDesign *filter_design); 00083 gchar* bse_iir_filter_string (const BseIIRFilter *filter); 00084 /* --- internal prototypes --- */ 00085 bool _bse_filter_design_ellf (const BseIIRFilterRequest *ifr, 00086 BseIIRFilterDesign *fid); 00087 00088 } // "C" 00089 00090 #endif /* BSE_FILTER_H__ */ /* vim:set ts=8 sw=2 sts=2: */