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.

142 lines
4.4KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <stdint.h>
  19. #include "libavutil/avutil.h"
  20. #include "mathops.h"
  21. #undef FUNC
  22. #undef sum_type
  23. #undef MUL
  24. #undef CLIP
  25. #undef FSUF
  26. #define FUNC(n) AV_JOIN(n ## _, SAMPLE_SIZE)
  27. #if SAMPLE_SIZE == 32
  28. # define sum_type int64_t
  29. # define MUL(a, b) MUL64(a, b)
  30. # define CLIP(x) av_clipl_int32(x)
  31. #else
  32. # define sum_type int32_t
  33. # define MUL(a, b) ((a) * (b))
  34. # define CLIP(x) (x)
  35. #endif
  36. #define LPC1(x) { \
  37. int c = coefs[(x)-1]; \
  38. p0 += MUL(c, s); \
  39. s = smp[i-(x)+1]; \
  40. p1 += MUL(c, s); \
  41. }
  42. static av_always_inline void FUNC(lpc_encode_unrolled)(int32_t *res,
  43. const int32_t *smp, int len, int order,
  44. const int32_t *coefs, int shift, int big)
  45. {
  46. int i;
  47. for (i = order; i < len; i += 2) {
  48. int s = smp[i-order];
  49. sum_type p0 = 0, p1 = 0;
  50. if (big) {
  51. switch (order) {
  52. case 32: LPC1(32)
  53. case 31: LPC1(31)
  54. case 30: LPC1(30)
  55. case 29: LPC1(29)
  56. case 28: LPC1(28)
  57. case 27: LPC1(27)
  58. case 26: LPC1(26)
  59. case 25: LPC1(25)
  60. case 24: LPC1(24)
  61. case 23: LPC1(23)
  62. case 22: LPC1(22)
  63. case 21: LPC1(21)
  64. case 20: LPC1(20)
  65. case 19: LPC1(19)
  66. case 18: LPC1(18)
  67. case 17: LPC1(17)
  68. case 16: LPC1(16)
  69. case 15: LPC1(15)
  70. case 14: LPC1(14)
  71. case 13: LPC1(13)
  72. case 12: LPC1(12)
  73. case 11: LPC1(11)
  74. case 10: LPC1(10)
  75. case 9: LPC1( 9)
  76. LPC1( 8)
  77. LPC1( 7)
  78. LPC1( 6)
  79. LPC1( 5)
  80. LPC1( 4)
  81. LPC1( 3)
  82. LPC1( 2)
  83. LPC1( 1)
  84. }
  85. } else {
  86. switch (order) {
  87. case 8: LPC1( 8)
  88. case 7: LPC1( 7)
  89. case 6: LPC1( 6)
  90. case 5: LPC1( 5)
  91. case 4: LPC1( 4)
  92. case 3: LPC1( 3)
  93. case 2: LPC1( 2)
  94. case 1: LPC1( 1)
  95. }
  96. }
  97. res[i ] = smp[i ] - CLIP(p0 >> shift);
  98. res[i+1] = smp[i+1] - CLIP(p1 >> shift);
  99. }
  100. }
  101. static void FUNC(flac_lpc_encode_c)(int32_t *res, const int32_t *smp, int len,
  102. int order, const int32_t *coefs, int shift)
  103. {
  104. int i;
  105. for (i = 0; i < order; i++)
  106. res[i] = smp[i];
  107. #if CONFIG_SMALL
  108. for (i = order; i < len; i += 2) {
  109. int j;
  110. int s = smp[i];
  111. sum_type p0 = 0, p1 = 0;
  112. for (j = 0; j < order; j++) {
  113. int c = coefs[j];
  114. p1 += MUL(c, s);
  115. s = smp[i-j-1];
  116. p0 += MUL(c, s);
  117. }
  118. res[i ] = smp[i ] - CLIP(p0 >> shift);
  119. res[i+1] = smp[i+1] - CLIP(p1 >> shift);
  120. }
  121. #else
  122. switch (order) {
  123. case 1: FUNC(lpc_encode_unrolled)(res, smp, len, 1, coefs, shift, 0); break;
  124. case 2: FUNC(lpc_encode_unrolled)(res, smp, len, 2, coefs, shift, 0); break;
  125. case 3: FUNC(lpc_encode_unrolled)(res, smp, len, 3, coefs, shift, 0); break;
  126. case 4: FUNC(lpc_encode_unrolled)(res, smp, len, 4, coefs, shift, 0); break;
  127. case 5: FUNC(lpc_encode_unrolled)(res, smp, len, 5, coefs, shift, 0); break;
  128. case 6: FUNC(lpc_encode_unrolled)(res, smp, len, 6, coefs, shift, 0); break;
  129. case 7: FUNC(lpc_encode_unrolled)(res, smp, len, 7, coefs, shift, 0); break;
  130. case 8: FUNC(lpc_encode_unrolled)(res, smp, len, 8, coefs, shift, 0); break;
  131. default: FUNC(lpc_encode_unrolled)(res, smp, len, order, coefs, shift, 1); break;
  132. }
  133. #endif
  134. }