iirfilter.h 3.2 KB

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