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.

126 lines
3.7KB

  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. #include <inttypes.h>
  23. #include "avcodec.h"
  24. #include "celp_filters.h"
  25. void ff_celp_convolve_circ(int16_t* fc_out,
  26. const int16_t* fc_in,
  27. const int16_t* filter,
  28. int len)
  29. {
  30. int i, k;
  31. memset(fc_out, 0, len * sizeof(int16_t));
  32. /* Since there are few pulses over an entire subframe (i.e. almost
  33. all fc_in[i] are zero) it is faster to loop over fc_in first. */
  34. for (i = 0; i < len; i++) {
  35. if (fc_in[i]) {
  36. for (k = 0; k < i; k++)
  37. fc_out[k] += (fc_in[i] * filter[len + k - i]) >> 15;
  38. for (k = i; k < len; k++)
  39. fc_out[k] += (fc_in[i] * filter[ k - i]) >> 15;
  40. }
  41. }
  42. }
  43. void ff_celp_circ_addf(float *out, const float *in,
  44. const float *lagged, int lag, float fac, int n)
  45. {
  46. int k;
  47. for (k = 0; k < lag; k++)
  48. out[k] = in[k] + fac * lagged[n + k - lag];
  49. for (; k < n; k++)
  50. out[k] = in[k] + fac * lagged[ k - lag];
  51. }
  52. int ff_celp_lp_synthesis_filter(int16_t *out,
  53. const int16_t* filter_coeffs,
  54. const int16_t* in,
  55. int buffer_length,
  56. int filter_length,
  57. int stop_on_overflow,
  58. int rounder)
  59. {
  60. int i,n;
  61. // Avoids a +1 in the inner loop.
  62. filter_length++;
  63. for (n = 0; n < buffer_length; n++) {
  64. int sum = rounder;
  65. for (i = 1; i < filter_length; i++)
  66. sum -= filter_coeffs[i-1] * out[n-i];
  67. sum = (sum >> 12) + in[n];
  68. if (sum + 0x8000 > 0xFFFFU) {
  69. if (stop_on_overflow)
  70. return 1;
  71. sum = (sum >> 31) ^ 32767;
  72. }
  73. out[n] = sum;
  74. }
  75. return 0;
  76. }
  77. void ff_celp_lp_synthesis_filterf(float *out,
  78. const float* filter_coeffs,
  79. const float* in,
  80. int buffer_length,
  81. int filter_length)
  82. {
  83. int i,n;
  84. // Avoids a +1 in the inner loop.
  85. filter_length++;
  86. for (n = 0; n < buffer_length; n++) {
  87. out[n] = in[n];
  88. for (i = 1; i < filter_length; i++)
  89. out[n] -= filter_coeffs[i-1] * out[n-i];
  90. }
  91. }
  92. void ff_celp_lp_zero_synthesis_filterf(float *out,
  93. const float* filter_coeffs,
  94. const float* in,
  95. int buffer_length,
  96. int filter_length)
  97. {
  98. int i,n;
  99. // Avoids a +1 in the inner loop.
  100. filter_length++;
  101. for (n = 0; n < buffer_length; n++) {
  102. out[n] = in[n];
  103. for (i = 1; i < filter_length; i++)
  104. out[n] += filter_coeffs[i-1] * in[n-i];
  105. }
  106. }