yading@10
|
1 /*
|
yading@10
|
2 * IIR filter
|
yading@10
|
3 * Copyright (c) 2008 Konstantin Shishkov
|
yading@10
|
4 *
|
yading@10
|
5 * This file is part of FFmpeg.
|
yading@10
|
6 *
|
yading@10
|
7 * FFmpeg is free software; you can redistribute it and/or
|
yading@10
|
8 * modify it under the terms of the GNU Lesser General Public
|
yading@10
|
9 * License as published by the Free Software Foundation; either
|
yading@10
|
10 * version 2.1 of the License, or (at your option) any later version.
|
yading@10
|
11 *
|
yading@10
|
12 * FFmpeg is distributed in the hope that it will be useful,
|
yading@10
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@10
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@10
|
15 * Lesser General Public License for more details.
|
yading@10
|
16 *
|
yading@10
|
17 * You should have received a copy of the GNU Lesser General Public
|
yading@10
|
18 * License along with FFmpeg; if not, write to the Free Software
|
yading@10
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@10
|
20 */
|
yading@10
|
21
|
yading@10
|
22 /**
|
yading@10
|
23 * @file
|
yading@10
|
24 * IIR filter interface
|
yading@10
|
25 */
|
yading@10
|
26
|
yading@10
|
27 #ifndef AVCODEC_IIRFILTER_H
|
yading@10
|
28 #define AVCODEC_IIRFILTER_H
|
yading@10
|
29
|
yading@10
|
30 #include "avcodec.h"
|
yading@10
|
31
|
yading@10
|
32 struct FFIIRFilterCoeffs;
|
yading@10
|
33 struct FFIIRFilterState;
|
yading@10
|
34
|
yading@10
|
35 enum IIRFilterType{
|
yading@10
|
36 FF_FILTER_TYPE_BESSEL,
|
yading@10
|
37 FF_FILTER_TYPE_BIQUAD,
|
yading@10
|
38 FF_FILTER_TYPE_BUTTERWORTH,
|
yading@10
|
39 FF_FILTER_TYPE_CHEBYSHEV,
|
yading@10
|
40 FF_FILTER_TYPE_ELLIPTIC,
|
yading@10
|
41 };
|
yading@10
|
42
|
yading@10
|
43 enum IIRFilterMode{
|
yading@10
|
44 FF_FILTER_MODE_LOWPASS,
|
yading@10
|
45 FF_FILTER_MODE_HIGHPASS,
|
yading@10
|
46 FF_FILTER_MODE_BANDPASS,
|
yading@10
|
47 FF_FILTER_MODE_BANDSTOP,
|
yading@10
|
48 };
|
yading@10
|
49
|
yading@10
|
50 typedef struct FFIIRFilterContext {
|
yading@10
|
51 /**
|
yading@10
|
52 * Perform IIR filtering on floating-point input samples.
|
yading@10
|
53 *
|
yading@10
|
54 * @param coeffs pointer to filter coefficients
|
yading@10
|
55 * @param state pointer to filter state
|
yading@10
|
56 * @param size input length
|
yading@10
|
57 * @param src source samples
|
yading@10
|
58 * @param sstep source stride
|
yading@10
|
59 * @param dst filtered samples (destination may be the same as input)
|
yading@10
|
60 * @param dstep destination stride
|
yading@10
|
61 */
|
yading@10
|
62 void (*filter_flt)(const struct FFIIRFilterCoeffs *coeffs,
|
yading@10
|
63 struct FFIIRFilterState *state, int size,
|
yading@10
|
64 const float *src, int sstep, float *dst, int dstep);
|
yading@10
|
65 } FFIIRFilterContext;
|
yading@10
|
66
|
yading@10
|
67 /**
|
yading@10
|
68 * Initialize FFIIRFilterContext
|
yading@10
|
69 */
|
yading@10
|
70 void ff_iir_filter_init(FFIIRFilterContext *f);
|
yading@10
|
71 void ff_iir_filter_init_mips(FFIIRFilterContext *f);
|
yading@10
|
72
|
yading@10
|
73 /**
|
yading@10
|
74 * Initialize filter coefficients.
|
yading@10
|
75 *
|
yading@10
|
76 * @param avc a pointer to an arbitrary struct of which the first
|
yading@10
|
77 * field is a pointer to an AVClass struct
|
yading@10
|
78 * @param filt_type filter type (e.g. Butterworth)
|
yading@10
|
79 * @param filt_mode filter mode (e.g. lowpass)
|
yading@10
|
80 * @param order filter order
|
yading@10
|
81 * @param cutoff_ratio cutoff to input frequency ratio
|
yading@10
|
82 * @param stopband stopband to input frequency ratio (used by bandpass and bandstop filter modes)
|
yading@10
|
83 * @param ripple ripple factor (used only in Chebyshev filters)
|
yading@10
|
84 *
|
yading@10
|
85 * @return pointer to filter coefficients structure or NULL if filter cannot be created
|
yading@10
|
86 */
|
yading@10
|
87 struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
|
yading@10
|
88 enum IIRFilterType filt_type,
|
yading@10
|
89 enum IIRFilterMode filt_mode,
|
yading@10
|
90 int order, float cutoff_ratio,
|
yading@10
|
91 float stopband, float ripple);
|
yading@10
|
92
|
yading@10
|
93 /**
|
yading@10
|
94 * Create new filter state.
|
yading@10
|
95 *
|
yading@10
|
96 * @param order filter order
|
yading@10
|
97 *
|
yading@10
|
98 * @return pointer to new filter state or NULL if state creation fails
|
yading@10
|
99 */
|
yading@10
|
100 struct FFIIRFilterState* ff_iir_filter_init_state(int order);
|
yading@10
|
101
|
yading@10
|
102 /**
|
yading@10
|
103 * Free filter coefficients.
|
yading@10
|
104 *
|
yading@10
|
105 * @param coeffs pointer allocated with ff_iir_filter_init_coeffs()
|
yading@10
|
106 */
|
yading@10
|
107 void ff_iir_filter_free_coeffs(struct FFIIRFilterCoeffs *coeffs);
|
yading@10
|
108
|
yading@10
|
109 /**
|
yading@10
|
110 * Free filter state.
|
yading@10
|
111 *
|
yading@10
|
112 * @param state pointer allocated with ff_iir_filter_init_state()
|
yading@10
|
113 */
|
yading@10
|
114 void ff_iir_filter_free_state(struct FFIIRFilterState *state);
|
yading@10
|
115
|
yading@10
|
116 /**
|
yading@10
|
117 * Perform IIR filtering on signed 16-bit input samples.
|
yading@10
|
118 *
|
yading@10
|
119 * @param coeffs pointer to filter coefficients
|
yading@10
|
120 * @param state pointer to filter state
|
yading@10
|
121 * @param size input length
|
yading@10
|
122 * @param src source samples
|
yading@10
|
123 * @param sstep source stride
|
yading@10
|
124 * @param dst filtered samples (destination may be the same as input)
|
yading@10
|
125 * @param dstep destination stride
|
yading@10
|
126 */
|
yading@10
|
127 void ff_iir_filter(const struct FFIIRFilterCoeffs *coeffs, struct FFIIRFilterState *state,
|
yading@10
|
128 int size, const int16_t *src, int sstep, int16_t *dst, int dstep);
|
yading@10
|
129
|
yading@10
|
130 /**
|
yading@10
|
131 * Perform IIR filtering on floating-point input samples.
|
yading@10
|
132 *
|
yading@10
|
133 * @param coeffs pointer to filter coefficients
|
yading@10
|
134 * @param state pointer to filter state
|
yading@10
|
135 * @param size input length
|
yading@10
|
136 * @param src source samples
|
yading@10
|
137 * @param sstep source stride
|
yading@10
|
138 * @param dst filtered samples (destination may be the same as input)
|
yading@10
|
139 * @param dstep destination stride
|
yading@10
|
140 */
|
yading@10
|
141 void ff_iir_filter_flt(const struct FFIIRFilterCoeffs *coeffs,
|
yading@10
|
142 struct FFIIRFilterState *state, int size,
|
yading@10
|
143 const float *src, int sstep, float *dst, int dstep);
|
yading@10
|
144
|
yading@10
|
145 #endif /* AVCODEC_IIRFILTER_H */
|