52 int order,
float cutoff_ratio,
61 "low-pass filter mode\n");
66 "even filter orders\n");
70 wa = 2 * tan(
M_PI * 0.5 * cutoff_ratio);
73 for(i = 1; i < (order >> 1) + 1; i++)
74 c->
cx[i] = c->
cx[i - 1] * (order - i + 1LL) / i;
78 for(i = 1; i <= order; i++)
79 p[i][0] = p[i][1] = 0.0;
80 for(i = 0; i < order; i++){
82 double th = (i + (order >> 1) + 0.5) *
M_PI / order;
83 double a_re, a_im, c_re, c_im;
90 zp[0] = (a_re * c_re + a_im * c_im) / (c_re * c_re + c_im * c_im);
91 zp[1] = (a_im * c_re - a_re * c_im) / (c_re * c_re + c_im * c_im);
93 for(j = order; j >= 1; j--)
97 p[j][0] = a_re*zp[0] - a_im*zp[1] + p[j-1][0];
98 p[j][1] = a_re*zp[1] + a_im*zp[0] + p[j-1][1];
100 a_re = p[0][0]*zp[0] - p[0][1]*zp[1];
101 p[0][1] = p[0][0]*zp[1] + p[0][1]*zp[0];
104 c->
gain = p[order][0];
105 for(i = 0; i < order; i++){
107 c->
cy[i] = (-p[i][0] * p[order][0] + -p[i][1] * p[order][1]) /
108 (p[order][0] * p[order][0] + p[order][1] * p[order][1]);
110 c->
gain /= 1 << order;
117 float cutoff_ratio,
float stopband)
119 double cos_w0, sin_w0;
125 "high-pass and low-pass filter modes\n");
133 cos_w0 = cos(
M_PI * cutoff_ratio);
134 sin_w0 = sin(
M_PI * cutoff_ratio);
136 a0 = 1.0 + (sin_w0 / 2.0);
139 c->
gain = ((1.0 + cos_w0) / 2.0) /
a0;
140 x0 = ((1.0 + cos_w0) / 2.0) /
a0;
141 x1 = (-(1.0 + cos_w0)) /
a0;
143 c->
gain = ((1.0 - cos_w0) / 2.0) /
a0;
144 x0 = ((1.0 - cos_w0) / 2.0) /
a0;
145 x1 = (1.0 - cos_w0) / a0;
147 c->
cy[0] = (-1.0 + (sin_w0 / 2.0)) / a0;
148 c->
cy[1] = (2.0 * cos_w0) / a0;
161 int order,
float cutoff_ratio,
162 float stopband,
float ripple)
167 if (order <= 0 || order >
MAXORDER || cutoff_ratio >= 1.0)
206 #define CONV_S16(dest, source) dest = av_clip_int16(lrintf(source));
208 #define CONV_FLT(dest, source) dest = source;
210 #define FILTER_BW_O4_1(i0, i1, i2, i3, fmt) \
211 in = *src0 * c->gain \
212 + c->cy[0]*s->x[i0] + c->cy[1]*s->x[i1] \
213 + c->cy[2]*s->x[i2] + c->cy[3]*s->x[i3]; \
214 res = (s->x[i0] + in )*1 \
215 + (s->x[i1] + s->x[i3])*4 \
217 CONV_##fmt(*dst0, res) \
222 #define FILTER_BW_O4(type, fmt) { \
224 const type *src0 = src; \
226 for (i = 0; i < size; i += 4) { \
228 FILTER_BW_O4_1(0, 1, 2, 3, fmt); \
229 FILTER_BW_O4_1(1, 2, 3, 0, fmt); \
230 FILTER_BW_O4_1(2, 3, 0, 1, fmt); \
231 FILTER_BW_O4_1(3, 0, 1, 2, fmt); \
235 #define FILTER_DIRECT_FORM_II(type, fmt) { \
237 const type *src0 = src; \
239 for (i = 0; i < size; i++) { \
242 in = *src0 * c->gain; \
243 for(j = 0; j < c->order; j++) \
244 in += c->cy[j] * s->x[j]; \
245 res = s->x[0] + in + s->x[c->order >> 1] * c->cx[c->order >> 1]; \
246 for(j = 1; j < c->order >> 1; j++) \
247 res += (s->x[j] + s->x[c->order - j]) * c->cx[j]; \
248 for(j = 0; j < c->order - 1; j++) \
249 s->x[j] = s->x[j + 1]; \
250 CONV_##fmt(*dst0, res) \
251 s->x[c->order - 1] = in; \
257 #define FILTER_O2(type, fmt) { \
259 const type *src0 = src; \
261 for (i = 0; i < size; i++) { \
262 float in = *src0 * c->gain + \
263 s->x[0] * c->cy[0] + \
264 s->x[1] * c->cy[1]; \
265 CONV_##fmt(*dst0, s->x[0] + in + s->x[1] * c->cx[1]) \
275 const int16_t *src,
int sstep, int16_t *dst,
int dstep)
279 }
else if (c->
order == 4) {
288 const float *src,
int sstep,
float *dst,
int dstep)
292 }
else if (c->
order == 4) {
323 float cutoff_coeff = 0.4;
329 cutoff_coeff, 0.0, 0.0);
332 for (i = 0; i <
SIZE; i++) {
338 for (i = 0; i <
SIZE; i++)
339 printf(
"%6d %6d\n", x[i], y[i]);