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.

146 lines
4.7KB

  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
  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. typedef struct FFIIRFilterContext {
  44. /**
  45. * Perform IIR filtering on floating-point input samples.
  46. *
  47. * @param coeffs pointer to filter coefficients
  48. * @param state pointer to filter state
  49. * @param size input length
  50. * @param src source samples
  51. * @param sstep source stride
  52. * @param dst filtered samples (destination may be the same as input)
  53. * @param dstep destination stride
  54. */
  55. void (*filter_flt)(const struct FFIIRFilterCoeffs *coeffs,
  56. struct FFIIRFilterState *state, int size,
  57. const float *src, int sstep, float *dst, int dstep);
  58. } FFIIRFilterContext;
  59. /**
  60. * Initialize FFIIRFilterContext
  61. */
  62. void ff_iir_filter_init(FFIIRFilterContext *f);
  63. void ff_iir_filter_init_mips(FFIIRFilterContext *f);
  64. /**
  65. * Initialize filter coefficients.
  66. *
  67. * @param avc a pointer to an arbitrary struct of which the first
  68. * field is a pointer to an AVClass struct
  69. * @param filt_type filter type (e.g. Butterworth)
  70. * @param filt_mode filter mode (e.g. lowpass)
  71. * @param order filter order
  72. * @param cutoff_ratio cutoff to input frequency ratio
  73. * @param stopband stopband to input frequency ratio (used by bandpass and bandstop filter modes)
  74. * @param ripple ripple factor (used only in Chebyshev filters)
  75. *
  76. * @return pointer to filter coefficients structure or NULL if filter cannot be created
  77. */
  78. struct FFIIRFilterCoeffs* ff_iir_filter_init_coeffs(void *avc,
  79. enum IIRFilterType filt_type,
  80. enum IIRFilterMode filt_mode,
  81. int order, float cutoff_ratio,
  82. float stopband, float ripple);
  83. /**
  84. * Create new filter state.
  85. *
  86. * @param order filter order
  87. *
  88. * @return pointer to new filter state or NULL if state creation fails
  89. */
  90. struct FFIIRFilterState* ff_iir_filter_init_state(int order);
  91. /**
  92. * Free filter coefficients.
  93. *
  94. * @param coeffs pointer allocated with ff_iir_filter_init_coeffs()
  95. */
  96. void ff_iir_filter_free_coeffsp(struct FFIIRFilterCoeffs **coeffs);
  97. /**
  98. * Free and zero filter state.
  99. *
  100. * @param state pointer to pointer allocated with ff_iir_filter_init_state()
  101. */
  102. void ff_iir_filter_free_statep(struct FFIIRFilterState **state);
  103. /**
  104. * Perform IIR filtering on signed 16-bit input samples.
  105. *
  106. * @param coeffs pointer to filter coefficients
  107. * @param state pointer to filter state
  108. * @param size input length
  109. * @param src source samples
  110. * @param sstep source stride
  111. * @param dst filtered samples (destination may be the same as input)
  112. * @param dstep destination stride
  113. */
  114. void ff_iir_filter(const struct FFIIRFilterCoeffs *coeffs, struct FFIIRFilterState *state,
  115. int size, const int16_t *src, int sstep, int16_t *dst, int dstep);
  116. /**
  117. * Perform IIR filtering on floating-point input samples.
  118. *
  119. * @param coeffs pointer to filter coefficients
  120. * @param state pointer to filter state
  121. * @param size input length
  122. * @param src source samples
  123. * @param sstep source stride
  124. * @param dst filtered samples (destination may be the same as input)
  125. * @param dstep destination stride
  126. */
  127. void ff_iir_filter_flt(const struct FFIIRFilterCoeffs *coeffs,
  128. struct FFIIRFilterState *state, int size,
  129. const float *src, int sstep, float *dst, int dstep);
  130. #endif /* AVCODEC_IIRFILTER_H */