Signed-off-by: Mans Rullgard <mans@mansr.com>
(cherry picked from commit 30112adadf06fe2f9500e4da365eb8a58095c940)
... | ... |
@@ -47,29 +47,25 @@ typedef struct FFIIRFilterState{ |
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,6 +109,38 @@ av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc, |
113 | 113 |
} |
114 | 114 |
c->gain /= 1 << order; |
115 | 115 |
|
116 |
+ return 0; |
|
117 |
+} |
|
118 |
+ |
|
119 |
+av_cold struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc, |
|
120 |
+ enum IIRFilterType filt_type, |
|
121 |
+ enum IIRFilterMode filt_mode, |
|
122 |
+ int order, float cutoff_ratio, |
|
123 |
+ float stopband, float ripple) |
|
124 |
+{ |
|
125 |
+ FFIIRFilterCoeffs *c; |
|
126 |
+ |
|
127 |
+ if (order <= 0 || order > MAXORDER || cutoff_ratio >= 1.0) |
|
128 |
+ return NULL; |
|
129 |
+ |
|
130 |
+ FF_ALLOCZ_OR_GOTO(avc, c, sizeof(FFIIRFilterCoeffs), |
|
131 |
+ init_fail); |
|
132 |
+ FF_ALLOC_OR_GOTO (avc, c->cx, sizeof(c->cx[0]) * ((order >> 1) + 1), |
|
133 |
+ init_fail); |
|
134 |
+ FF_ALLOC_OR_GOTO (avc, c->cy, sizeof(c->cy[0]) * order, |
|
135 |
+ init_fail); |
|
136 |
+ c->order = order; |
|
137 |
+ |
|
138 |
+ if (filt_type == FF_FILTER_TYPE_BUTTERWORTH) { |
|
139 |
+ if (butterworth_init_coeffs(avc, c, filt_mode, order, cutoff_ratio, |
|
140 |
+ stopband)) { |
|
141 |
+ goto init_fail; |
|
142 |
+ } |
|
143 |
+ } else { |
|
144 |
+ av_log(avc, AV_LOG_ERROR, "filter type is not currently implemented\n"); |
|
145 |
+ goto init_fail; |
|
146 |
+ } |
|
147 |
+ |
|
116 | 148 |
return c; |
117 | 149 |
|
118 | 150 |
init_fail: |