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.

154 lines
6.1KB

  1. /*
  2. * various filters for ACELP-based codecs
  3. *
  4. * Copyright (c) 2008 Vladimir Voroshilov
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVCODEC_ACELP_FILTERS_H
  23. #define AVCODEC_ACELP_FILTERS_H
  24. #include <stdint.h>
  25. typedef struct ACELPFContext {
  26. /**
  27. * Floating point version of ff_acelp_interpolate()
  28. */
  29. void (*acelp_interpolatef)(float *out, const float *in,
  30. const float *filter_coeffs, int precision,
  31. int frac_pos, int filter_length, int length);
  32. /**
  33. * Apply an order 2 rational transfer function in-place.
  34. *
  35. * @param out output buffer for filtered speech samples
  36. * @param in input buffer containing speech data (may be the same as out)
  37. * @param zero_coeffs z^-1 and z^-2 coefficients of the numerator
  38. * @param pole_coeffs z^-1 and z^-2 coefficients of the denominator
  39. * @param gain scale factor for final output
  40. * @param mem intermediate values used by filter (should be 0 initially)
  41. * @param n number of samples (should be a multiple of eight)
  42. */
  43. void (*acelp_apply_order_2_transfer_function)(float *out, const float *in,
  44. const float zero_coeffs[2],
  45. const float pole_coeffs[2],
  46. float gain,
  47. float mem[2], int n);
  48. }ACELPFContext;
  49. /**
  50. * Initialize ACELPFContext.
  51. */
  52. void ff_acelp_filter_init(ACELPFContext *c);
  53. void ff_acelp_filter_init_mips(ACELPFContext *c);
  54. /**
  55. * low-pass Finite Impulse Response filter coefficients.
  56. *
  57. * Hamming windowed sinc filter with cutoff freq 3/40 of the sampling freq,
  58. * the coefficients are scaled by 2^15.
  59. * This array only contains the right half of the filter.
  60. * This filter is likely identical to the one used in G.729, though this
  61. * could not be determined from the original comments with certainity.
  62. */
  63. extern const int16_t ff_acelp_interp_filter[61];
  64. /**
  65. * Generic FIR interpolation routine.
  66. * @param[out] out buffer for interpolated data
  67. * @param in input data
  68. * @param filter_coeffs interpolation filter coefficients (0.15)
  69. * @param precision sub sample factor, that is the precision of the position
  70. * @param frac_pos fractional part of position [0..precision-1]
  71. * @param filter_length filter length
  72. * @param length length of output
  73. *
  74. * filter_coeffs contains coefficients of the right half of the symmetric
  75. * interpolation filter. filter_coeffs[0] should the central (unpaired) coefficient.
  76. * See ff_acelp_interp_filter for an example.
  77. *
  78. */
  79. void ff_acelp_interpolate(int16_t* out, const int16_t* in,
  80. const int16_t* filter_coeffs, int precision,
  81. int frac_pos, int filter_length, int length);
  82. /**
  83. * Floating point version of ff_acelp_interpolate()
  84. */
  85. void ff_acelp_interpolatef(float *out, const float *in,
  86. const float *filter_coeffs, int precision,
  87. int frac_pos, int filter_length, int length);
  88. /**
  89. * high-pass filtering and upscaling (4.2.5 of G.729).
  90. * @param[out] out output buffer for filtered speech data
  91. * @param[in,out] hpf_f past filtered data from previous (2 items long)
  92. * frames (-0x20000000 <= (14.13) < 0x20000000)
  93. * @param in speech data to process
  94. * @param length input data size
  95. *
  96. * out[i] = 0.93980581 * in[i] - 1.8795834 * in[i-1] + 0.93980581 * in[i-2] +
  97. * 1.9330735 * out[i-1] - 0.93589199 * out[i-2]
  98. *
  99. * The filter has a cut-off frequency of 1/80 of the sampling freq
  100. *
  101. * @note Two items before the top of the in buffer must contain two items from the
  102. * tail of the previous subframe.
  103. *
  104. * @remark It is safe to pass the same array in in and out parameters.
  105. *
  106. * @remark AMR uses mostly the same filter (cut-off frequency 60Hz, same formula,
  107. * but constants differs in 5th sign after comma). Fortunately in
  108. * fixed-point all coefficients are the same as in G.729. Thus this
  109. * routine can be used for the fixed-point AMR decoder, too.
  110. */
  111. void ff_acelp_high_pass_filter(int16_t* out, int hpf_f[2],
  112. const int16_t* in, int length);
  113. /**
  114. * Apply an order 2 rational transfer function in-place.
  115. *
  116. * @param out output buffer for filtered speech samples
  117. * @param in input buffer containing speech data (may be the same as out)
  118. * @param zero_coeffs z^-1 and z^-2 coefficients of the numerator
  119. * @param pole_coeffs z^-1 and z^-2 coefficients of the denominator
  120. * @param gain scale factor for final output
  121. * @param mem intermediate values used by filter (should be 0 initially)
  122. * @param n number of samples
  123. */
  124. void ff_acelp_apply_order_2_transfer_function(float *out, const float *in,
  125. const float zero_coeffs[2],
  126. const float pole_coeffs[2],
  127. float gain,
  128. float mem[2], int n);
  129. /**
  130. * Apply tilt compensation filter, 1 - tilt * z-1.
  131. *
  132. * @param mem pointer to the filter's state (one single float)
  133. * @param tilt tilt factor
  134. * @param samples array where the filter is applied
  135. * @param size the size of the samples array
  136. */
  137. void ff_tilt_compensation(float *mem, float tilt, float *samples, int size);
  138. #endif /* AVCODEC_ACELP_FILTERS_H */