* IIR filter
* Copyright (c) 2008 Konstantin Shishkov
*
- * This file is part of FFmpeg.
+ * This file is part of Libav.
*
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "iirfilter.h"
#include <math.h>
+#include "libavutil/attributes.h"
+#include "libavutil/common.h"
/**
* IIR filter global parameters
/// maximum supported filter order
#define MAXORDER 30
-static int butterworth_init_coeffs(void *avc, struct FFIIRFilterCoeffs *c,
- enum IIRFilterMode filt_mode,
- int order, float cutoff_ratio,
- float stopband)
+static av_cold int butterworth_init_coeffs(void *avc,
+ struct FFIIRFilterCoeffs *c,
+ enum IIRFilterMode filt_mode,
+ int order, float cutoff_ratio,
+ float stopband)
{
int i, j;
double wa;
return 0;
}
-static int biquad_init_coeffs(void *avc, struct FFIIRFilterCoeffs *c,
- enum IIRFilterMode filt_mode, int order,
- float cutoff_ratio, float stopband)
+static av_cold int biquad_init_coeffs(void *avc, struct FFIIRFilterCoeffs *c,
+ enum IIRFilterMode filt_mode, int order,
+ float cutoff_ratio, float stopband)
{
double cos_w0, sin_w0;
double a0, x0, x1;
// during filtering, the delay state will include the gain multiplication
c->cx[0] = lrintf(x0 / c->gain);
c->cx[1] = lrintf(x1 / c->gain);
- c->cy[0] /= c->gain;
- c->cy[1] /= c->gain;
return 0;
}
}
#ifdef TEST
+#include <stdio.h>
+
#define FILT_ORDER 4
#define SIZE 1024
int main(void)
float cutoff_coeff = 0.4;
int16_t x[SIZE], y[SIZE];
int i;
- FILE* fd;
- fcoeffs = ff_iir_filter_init_coeffs(FF_FILTER_TYPE_BUTTERWORTH,
+ fcoeffs = ff_iir_filter_init_coeffs(NULL, FF_FILTER_TYPE_BUTTERWORTH,
FF_FILTER_MODE_LOWPASS, FILT_ORDER,
cutoff_coeff, 0.0, 0.0);
fstate = ff_iir_filter_init_state(FILT_ORDER);
ff_iir_filter(fcoeffs, fstate, SIZE, x, 1, y, 1);
- fd = fopen("in.bin", "w");
- fwrite(x, sizeof(x[0]), SIZE, fd);
- fclose(fd);
-
- fd = fopen("out.bin", "w");
- fwrite(y, sizeof(y[0]), SIZE, fd);
- fclose(fd);
+ for (i = 0; i < SIZE; i++)
+ printf("%6d %6d\n", x[i], y[i]);
ff_iir_filter_free_coeffs(fcoeffs);
ff_iir_filter_free_state(fstate);