You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
4.0KB

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