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.0KB

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