1/* 2 * IIR filter 3 * Copyright (c) 2008 Konstantin Shishkov 4 * 5 * This file is part of FFmpeg. 6 * 7 * FFmpeg 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 * FFmpeg 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 FFmpeg; 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 "avcodec.h" 31 32struct FFIIRFilterCoeffs; 33struct FFIIRFilterState; 34 35enum IIRFilterType{ 36 FF_FILTER_TYPE_BESSEL, 37 FF_FILTER_TYPE_BUTTERWORTH, 38 FF_FILTER_TYPE_CHEBYSHEV, 39 FF_FILTER_TYPE_ELLIPTIC, 40}; 41 42enum IIRFilterMode{ 43 FF_FILTER_MODE_LOWPASS, 44 FF_FILTER_MODE_HIGHPASS, 45 FF_FILTER_MODE_BANDPASS, 46 FF_FILTER_MODE_BANDSTOP, 47}; 48 49/** 50 * Initialize filter coefficients. 51 * 52 * @param filt_type filter type (e.g. Butterworth) 53 * @param filt_mode filter mode (e.g. lowpass) 54 * @param order filter order 55 * @param cutoff_ratio cutoff to input frequency ratio 56 * @param stopband stopband to input frequency ratio (used by bandpass and bandstop filter modes) 57 * @param ripple ripple factor (used only in Chebyshev filters) 58 * 59 * @return pointer to filter coefficients structure or NULL if filter cannot be created 60 */ 61struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(enum IIRFilterType filt_type, 62 enum IIRFilterMode filt_mode, 63 int order, float cutoff_ratio, 64 float stopband, float ripple); 65 66/** 67 * Create new filter state. 68 * 69 * @param order filter order 70 * 71 * @return pointer to new filter state or NULL if state creation fails 72 */ 73struct FFIIRFilterState* ff_iir_filter_init_state(int order); 74 75/** 76 * Free filter coefficients. 77 * 78 * @param coeffs pointer allocated with ff_iir_filter_init_coeffs() 79 */ 80void ff_iir_filter_free_coeffs(struct FFIIRFilterCoeffs *coeffs); 81 82/** 83 * Free filter state. 84 * 85 * @param state pointer allocated with ff_iir_filter_init_state() 86 */ 87void ff_iir_filter_free_state(struct FFIIRFilterState *state); 88 89/** 90 * Perform lowpass filtering on input samples. 91 * 92 * @param coeffs pointer to filter coefficients 93 * @param state pointer to filter state 94 * @param size input length 95 * @param src source samples 96 * @param sstep source stride 97 * @param dst filtered samples (destination may be the same as input) 98 * @param dstep destination stride 99 */ 100void ff_iir_filter(const struct FFIIRFilterCoeffs *coeffs, struct FFIIRFilterState *state, 101 int size, const int16_t *src, int sstep, int16_t *dst, int dstep); 102 103#endif /* AVCODEC_IIRFILTER_H */ 104