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.

123 lines
3.9KB

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