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