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.

117 lines
3.5KB

  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. for (n = 0; n < buffer_length; n++) {
  62. int sum = rounder;
  63. for (i = 1; i <= filter_length; i++)
  64. sum -= filter_coeffs[i-1] * out[n-i];
  65. sum = (sum >> 12) + in[n];
  66. if (sum + 0x8000 > 0xFFFFU) {
  67. if (stop_on_overflow)
  68. return 1;
  69. sum = (sum >> 31) ^ 32767;
  70. }
  71. out[n] = sum;
  72. }
  73. return 0;
  74. }
  75. void ff_celp_lp_synthesis_filterf(float *out,
  76. const float* filter_coeffs,
  77. const float* in,
  78. int buffer_length,
  79. int filter_length)
  80. {
  81. int i,n;
  82. for (n = 0; n < buffer_length; n++) {
  83. out[n] = in[n];
  84. for (i = 1; i <= filter_length; i++)
  85. out[n] -= filter_coeffs[i-1] * out[n-i];
  86. }
  87. }
  88. void ff_celp_lp_zero_synthesis_filterf(float *out,
  89. const float* filter_coeffs,
  90. const float* in,
  91. int buffer_length,
  92. int filter_length)
  93. {
  94. int i,n;
  95. for (n = 0; n < buffer_length; n++) {
  96. out[n] = in[n];
  97. for (i = 1; i <= filter_length; i++)
  98. out[n] += filter_coeffs[i-1] * in[n-i];
  99. }
  100. }