Revision 2293b0b6 libavcodec/iirfilter.c
libavcodec/iirfilter.c | ||
---|---|---|
47 | 47 |
/// maximum supported filter order |
48 | 48 |
#define MAXORDER 30 |
49 | 49 |
|
50 |
av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc, |
|
51 |
enum IIRFilterType filt_type, |
|
52 |
enum IIRFilterMode filt_mode, |
|
53 |
int order, float cutoff_ratio, |
|
54 |
float stopband, float ripple) |
|
50 |
static int butterworth_init_coeffs(void *avc, struct FFIIRFilterCoeffs *c, |
|
51 |
enum IIRFilterMode filt_mode, |
|
52 |
int order, float cutoff_ratio, |
|
53 |
float stopband) |
|
55 | 54 |
{ |
56 | 55 |
int i, j; |
57 |
FFIIRFilterCoeffs *c; |
|
58 | 56 |
double wa; |
59 | 57 |
double p[MAXORDER + 1][2]; |
60 | 58 |
|
61 |
if(filt_type != FF_FILTER_TYPE_BUTTERWORTH || filt_mode != FF_FILTER_MODE_LOWPASS) |
|
62 |
return NULL; |
|
63 |
if(order <= 1 || (order & 1) || order > MAXORDER || cutoff_ratio >= 1.0) |
|
64 |
return NULL; |
|
65 |
|
|
66 |
FF_ALLOCZ_OR_GOTO(avc, c, sizeof(FFIIRFilterCoeffs), |
|
67 |
init_fail); |
|
68 |
FF_ALLOC_OR_GOTO (avc, c->cx, sizeof(c->cx[0]) * ((order >> 1) + 1), |
|
69 |
init_fail); |
|
70 |
FF_ALLOC_OR_GOTO (avc, c->cy, sizeof(c->cy[0]) * order, |
|
71 |
init_fail); |
|
72 |
c->order = order; |
|
59 |
if (filt_mode != FF_FILTER_MODE_LOWPASS) { |
|
60 |
av_log(avc, AV_LOG_ERROR, "Butterworth filter currently only supports " |
|
61 |
"low-pass filter mode\n"); |
|
62 |
return -1; |
|
63 |
} |
|
64 |
if (order & 1) { |
|
65 |
av_log(avc, AV_LOG_ERROR, "Butterworth filter currently only supports " |
|
66 |
"even filter orders\n"); |
|
67 |
return -1; |
|
68 |
} |
|
73 | 69 |
|
74 | 70 |
wa = 2 * tan(M_PI * 0.5 * cutoff_ratio); |
75 | 71 |
|
... | ... | |
113 | 109 |
} |
114 | 110 |
c->gain /= 1 << order; |
115 | 111 |
|
112 |
return 0; |
|
113 |
} |
|
114 |
|
|
115 |
av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc, |
|
116 |
enum IIRFilterType filt_type, |
|
117 |
enum IIRFilterMode filt_mode, |
|
118 |
int order, float cutoff_ratio, |
|
119 |
float stopband, float ripple) |
|
120 |
{ |
|
121 |
FFIIRFilterCoeffs *c; |
|
122 |
|
|
123 |
if (order <= 0 || order > MAXORDER || cutoff_ratio >= 1.0) |
|
124 |
return NULL; |
|
125 |
|
|
126 |
FF_ALLOCZ_OR_GOTO(avc, c, sizeof(FFIIRFilterCoeffs), |
|
127 |
init_fail); |
|
128 |
FF_ALLOC_OR_GOTO (avc, c->cx, sizeof(c->cx[0]) * ((order >> 1) + 1), |
|
129 |
init_fail); |
|
130 |
FF_ALLOC_OR_GOTO (avc, c->cy, sizeof(c->cy[0]) * order, |
|
131 |
init_fail); |
|
132 |
c->order = order; |
|
133 |
|
|
134 |
if (filt_type == FF_FILTER_TYPE_BUTTERWORTH) { |
|
135 |
if (butterworth_init_coeffs(avc, c, filt_mode, order, cutoff_ratio, |
|
136 |
stopband)) { |
|
137 |
goto init_fail; |
|
138 |
} |
|
139 |
} else { |
|
140 |
av_log(avc, AV_LOG_ERROR, "filter type is not currently implemented\n"); |
|
141 |
goto init_fail; |
|
142 |
} |
|
143 |
|
|
116 | 144 |
return c; |
117 | 145 |
|
118 | 146 |
init_fail: |
Also available in: Unified diff