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.

116 lines
3.4KB

  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. int ff_celp_lp_synthesis_filter(int16_t *out,
  44. const int16_t* filter_coeffs,
  45. const int16_t* in,
  46. int buffer_length,
  47. int filter_length,
  48. int stop_on_overflow,
  49. int rounder)
  50. {
  51. int i,n;
  52. // Avoids a +1 in the inner loop.
  53. filter_length++;
  54. for (n = 0; n < buffer_length; n++) {
  55. int sum = rounder;
  56. for (i = 1; i < filter_length; i++)
  57. sum -= filter_coeffs[i-1] * out[n-i];
  58. sum = (sum >> 12) + in[n];
  59. if (sum + 0x8000 > 0xFFFFU) {
  60. if (stop_on_overflow)
  61. return 1;
  62. sum = (sum >> 31) ^ 32767;
  63. }
  64. out[n] = sum;
  65. }
  66. return 0;
  67. }
  68. void ff_celp_lp_synthesis_filterf(float *out,
  69. const float* filter_coeffs,
  70. const float* in,
  71. int buffer_length,
  72. int filter_length)
  73. {
  74. int i,n;
  75. // Avoids a +1 in the inner loop.
  76. filter_length++;
  77. for (n = 0; n < buffer_length; n++) {
  78. out[n] = in[n];
  79. for (i = 1; i < filter_length; i++)
  80. out[n] -= filter_coeffs[i-1] * out[n-i];
  81. }
  82. }
  83. void ff_celp_lp_zero_synthesis_filterf(float *out,
  84. const float* filter_coeffs,
  85. const float* in,
  86. int buffer_length,
  87. int filter_length)
  88. {
  89. int i,n;
  90. // Avoids a +1 in the inner loop.
  91. filter_length++;
  92. for (n = 0; n < buffer_length; n++) {
  93. out[n] = in[n];
  94. for (i = 1; i < filter_length; i++)
  95. out[n] += filter_coeffs[i-1] * in[n-i];
  96. }
  97. }