yading@10: /* yading@10: * IIR filter yading@10: * Copyright (c) 2008 Konstantin Shishkov yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: /** yading@10: * @file yading@10: * IIR filter interface yading@10: */ yading@10: yading@10: #ifndef AVCODEC_IIRFILTER_H yading@10: #define AVCODEC_IIRFILTER_H yading@10: yading@10: #include "avcodec.h" yading@10: yading@10: struct FFIIRFilterCoeffs; yading@10: struct FFIIRFilterState; yading@10: yading@10: enum IIRFilterType{ yading@10: FF_FILTER_TYPE_BESSEL, yading@10: FF_FILTER_TYPE_BIQUAD, yading@10: FF_FILTER_TYPE_BUTTERWORTH, yading@10: FF_FILTER_TYPE_CHEBYSHEV, yading@10: FF_FILTER_TYPE_ELLIPTIC, yading@10: }; yading@10: yading@10: enum IIRFilterMode{ yading@10: FF_FILTER_MODE_LOWPASS, yading@10: FF_FILTER_MODE_HIGHPASS, yading@10: FF_FILTER_MODE_BANDPASS, yading@10: FF_FILTER_MODE_BANDSTOP, yading@10: }; yading@10: yading@10: typedef struct FFIIRFilterContext { yading@10: /** yading@10: * Perform IIR filtering on floating-point input samples. yading@10: * yading@10: * @param coeffs pointer to filter coefficients yading@10: * @param state pointer to filter state yading@10: * @param size input length yading@10: * @param src source samples yading@10: * @param sstep source stride yading@10: * @param dst filtered samples (destination may be the same as input) yading@10: * @param dstep destination stride yading@10: */ yading@10: void (*filter_flt)(const struct FFIIRFilterCoeffs *coeffs, yading@10: struct FFIIRFilterState *state, int size, yading@10: const float *src, int sstep, float *dst, int dstep); yading@10: } FFIIRFilterContext; yading@10: yading@10: /** yading@10: * Initialize FFIIRFilterContext yading@10: */ yading@10: void ff_iir_filter_init(FFIIRFilterContext *f); yading@10: void ff_iir_filter_init_mips(FFIIRFilterContext *f); yading@10: yading@10: /** yading@10: * Initialize filter coefficients. yading@10: * yading@10: * @param avc a pointer to an arbitrary struct of which the first yading@10: * field is a pointer to an AVClass struct yading@10: * @param filt_type filter type (e.g. Butterworth) yading@10: * @param filt_mode filter mode (e.g. lowpass) yading@10: * @param order filter order yading@10: * @param cutoff_ratio cutoff to input frequency ratio yading@10: * @param stopband stopband to input frequency ratio (used by bandpass and bandstop filter modes) yading@10: * @param ripple ripple factor (used only in Chebyshev filters) yading@10: * yading@10: * @return pointer to filter coefficients structure or NULL if filter cannot be created yading@10: */ yading@10: struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc, yading@10: enum IIRFilterType filt_type, yading@10: enum IIRFilterMode filt_mode, yading@10: int order, float cutoff_ratio, yading@10: float stopband, float ripple); yading@10: yading@10: /** yading@10: * Create new filter state. yading@10: * yading@10: * @param order filter order yading@10: * yading@10: * @return pointer to new filter state or NULL if state creation fails yading@10: */ yading@10: struct FFIIRFilterState* ff_iir_filter_init_state(int order); yading@10: yading@10: /** yading@10: * Free filter coefficients. yading@10: * yading@10: * @param coeffs pointer allocated with ff_iir_filter_init_coeffs() yading@10: */ yading@10: void ff_iir_filter_free_coeffs(struct FFIIRFilterCoeffs *coeffs); yading@10: yading@10: /** yading@10: * Free filter state. yading@10: * yading@10: * @param state pointer allocated with ff_iir_filter_init_state() yading@10: */ yading@10: void ff_iir_filter_free_state(struct FFIIRFilterState *state); yading@10: yading@10: /** yading@10: * Perform IIR filtering on signed 16-bit input samples. yading@10: * yading@10: * @param coeffs pointer to filter coefficients yading@10: * @param state pointer to filter state yading@10: * @param size input length yading@10: * @param src source samples yading@10: * @param sstep source stride yading@10: * @param dst filtered samples (destination may be the same as input) yading@10: * @param dstep destination stride yading@10: */ yading@10: void ff_iir_filter(const struct FFIIRFilterCoeffs *coeffs, struct FFIIRFilterState *state, yading@10: int size, const int16_t *src, int sstep, int16_t *dst, int dstep); yading@10: yading@10: /** yading@10: * Perform IIR filtering on floating-point input samples. yading@10: * yading@10: * @param coeffs pointer to filter coefficients yading@10: * @param state pointer to filter state yading@10: * @param size input length yading@10: * @param src source samples yading@10: * @param sstep source stride yading@10: * @param dst filtered samples (destination may be the same as input) yading@10: * @param dstep destination stride yading@10: */ yading@10: void ff_iir_filter_flt(const struct FFIIRFilterCoeffs *coeffs, yading@10: struct FFIIRFilterState *state, int size, yading@10: const float *src, int sstep, float *dst, int dstep); yading@10: yading@10: #endif /* AVCODEC_IIRFILTER_H */