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.

170 lines
6.4KB

  1. /*
  2. * various filters for CELP-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_CELP_FILTERS_H
  23. #define AVCODEC_CELP_FILTERS_H
  24. #include <stdint.h>
  25. typedef struct CELPFContext {
  26. /**
  27. * LP synthesis filter.
  28. * @param[out] out pointer to output buffer
  29. * - the array out[-filter_length, -1] must
  30. * contain the previous result of this filter
  31. * @param filter_coeffs filter coefficients.
  32. * @param in input signal
  33. * @param buffer_length amount of data to process
  34. * @param filter_length filter length (10 for 10th order LP filter). Must be
  35. * greater than 4 and even.
  36. *
  37. * @note Output buffer must contain filter_length samples of past
  38. * speech data before pointer.
  39. *
  40. * Routine applies 1/A(z) filter to given speech data.
  41. */
  42. void (*celp_lp_synthesis_filterf)(float *out, const float *filter_coeffs,
  43. const float *in, int buffer_length,
  44. int filter_length);
  45. /**
  46. * LP zero synthesis filter.
  47. * @param[out] out pointer to output buffer
  48. * @param filter_coeffs filter coefficients.
  49. * @param in input signal
  50. * - the array in[-filter_length, -1] must
  51. * contain the previous input of this filter
  52. * @param buffer_length amount of data to process (should be a multiple of eight)
  53. * @param filter_length filter length (10 for 10th order LP filter;
  54. * should be a multiple of two)
  55. *
  56. * @note Output buffer must contain filter_length samples of past
  57. * speech data before pointer.
  58. *
  59. * Routine applies A(z) filter to given speech data.
  60. */
  61. void (*celp_lp_zero_synthesis_filterf)(float *out, const float *filter_coeffs,
  62. const float *in, int buffer_length,
  63. int filter_length);
  64. }CELPFContext;
  65. /**
  66. * Initialize CELPFContext.
  67. */
  68. void ff_celp_filter_init(CELPFContext *c);
  69. void ff_celp_filter_init_mips(CELPFContext *c);
  70. /**
  71. * Circularly convolve fixed vector with a phase dispersion impulse
  72. * response filter (D.6.2 of G.729 and 6.1.5 of AMR).
  73. * @param fc_out vector with filter applied
  74. * @param fc_in source vector
  75. * @param filter phase filter coefficients
  76. *
  77. * fc_out[n] = sum(i,0,len-1){ fc_in[i] * filter[(len + n - i)%len] }
  78. *
  79. * @note fc_in and fc_out should not overlap!
  80. */
  81. void ff_celp_convolve_circ(int16_t *fc_out, const int16_t *fc_in,
  82. const int16_t *filter, int len);
  83. /**
  84. * Add an array to a rotated array.
  85. *
  86. * out[k] = in[k] + fac * lagged[k-lag] with wrap-around
  87. *
  88. * @param out result vector
  89. * @param in samples to be added unfiltered
  90. * @param lagged samples to be rotated, multiplied and added
  91. * @param lag lagged vector delay in the range [0, n]
  92. * @param fac scalefactor for lagged samples
  93. * @param n number of samples
  94. */
  95. void ff_celp_circ_addf(float *out, const float *in,
  96. const float *lagged, int lag, float fac, int n);
  97. /**
  98. * LP synthesis filter.
  99. * @param[out] out pointer to output buffer
  100. * @param filter_coeffs filter coefficients (-0x8000 <= (3.12) < 0x8000)
  101. * @param in input signal
  102. * @param buffer_length amount of data to process
  103. * @param filter_length filter length (10 for 10th order LP filter)
  104. * @param stop_on_overflow 1 - return immediately if overflow occurs
  105. * 0 - ignore overflows
  106. * @param shift the result is shifted right by this value
  107. * @param rounder the amount to add for rounding (usually 0x800 or 0xfff)
  108. *
  109. * @return 1 if overflow occurred, 0 - otherwise
  110. *
  111. * @note Output buffer must contain filter_length samples of past
  112. * speech data before pointer.
  113. *
  114. * Routine applies 1/A(z) filter to given speech data.
  115. */
  116. int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs,
  117. const int16_t *in, int buffer_length,
  118. int filter_length, int stop_on_overflow,
  119. int shift, int rounder);
  120. /**
  121. * LP synthesis filter.
  122. * @param[out] out pointer to output buffer
  123. * - the array out[-filter_length, -1] must
  124. * contain the previous result of this filter
  125. * @param filter_coeffs filter coefficients.
  126. * @param in input signal
  127. * @param buffer_length amount of data to process
  128. * @param filter_length filter length (10 for 10th order LP filter). Must be
  129. * greater than 4 and even.
  130. *
  131. * @note Output buffer must contain filter_length samples of past
  132. * speech data before pointer.
  133. *
  134. * Routine applies 1/A(z) filter to given speech data.
  135. */
  136. void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs,
  137. const float *in, int buffer_length,
  138. int filter_length);
  139. /**
  140. * LP zero synthesis filter.
  141. * @param[out] out pointer to output buffer
  142. * @param filter_coeffs filter coefficients.
  143. * @param in input signal
  144. * - the array in[-filter_length, -1] must
  145. * contain the previous input of this filter
  146. * @param buffer_length amount of data to process
  147. * @param filter_length filter length (10 for 10th order LP filter)
  148. *
  149. * @note Output buffer must contain filter_length samples of past
  150. * speech data before pointer.
  151. *
  152. * Routine applies A(z) filter to given speech data.
  153. */
  154. void ff_celp_lp_zero_synthesis_filterf(float *out, const float *filter_coeffs,
  155. const float *in, int buffer_length,
  156. int filter_length);
  157. #endif /* AVCODEC_CELP_FILTERS_H */