acelp_vectors.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * adaptive and fixed codebook vector operations 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 "acelp_vectors.h"
  25. const uint8_t ff_fc_2pulses_9bits_track1[16] =
  26. {
  27. 1, 3,
  28. 6, 8,
  29. 11, 13,
  30. 16, 18,
  31. 21, 23,
  32. 26, 28,
  33. 31, 33,
  34. 36, 38
  35. };
  36. const uint8_t ff_fc_2pulses_9bits_track1_gray[16] =
  37. {
  38. 1, 3,
  39. 8, 6,
  40. 18, 16,
  41. 11, 13,
  42. 38, 36,
  43. 31, 33,
  44. 21, 23,
  45. 28, 26,
  46. };
  47. const uint8_t ff_fc_2pulses_9bits_track2_gray[32] =
  48. {
  49. 0, 2,
  50. 5, 4,
  51. 12, 10,
  52. 7, 9,
  53. 25, 24,
  54. 20, 22,
  55. 14, 15,
  56. 19, 17,
  57. 36, 31,
  58. 21, 26,
  59. 1, 6,
  60. 16, 11,
  61. 27, 29,
  62. 32, 30,
  63. 39, 37,
  64. 34, 35,
  65. };
  66. const uint8_t ff_fc_4pulses_8bits_tracks_13[16] =
  67. {
  68. 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75,
  69. };
  70. const uint8_t ff_fc_4pulses_8bits_track_4[32] =
  71. {
  72. 3, 4,
  73. 8, 9,
  74. 13, 14,
  75. 18, 19,
  76. 23, 24,
  77. 28, 29,
  78. 33, 34,
  79. 38, 39,
  80. 43, 44,
  81. 48, 49,
  82. 53, 54,
  83. 58, 59,
  84. 63, 64,
  85. 68, 69,
  86. 73, 74,
  87. 78, 79,
  88. };
  89. #if 0
  90. static uint8_t gray_decode[32] =
  91. {
  92. 0, 1, 3, 2, 7, 6, 4, 5,
  93. 15, 14, 12, 13, 8, 9, 11, 10,
  94. 31, 30, 28, 29, 24, 25, 27, 26,
  95. 16, 17, 19, 18, 23, 22, 20, 21
  96. };
  97. #endif
  98. void ff_acelp_fc_pulse_per_track(
  99. int16_t* fc_v,
  100. const uint8_t *tab1,
  101. const uint8_t *tab2,
  102. int pulse_indexes,
  103. int pulse_signs,
  104. int pulse_count,
  105. int bits)
  106. {
  107. int mask = (1 << bits) - 1;
  108. int i;
  109. for(i=0; i<pulse_count; i++)
  110. {
  111. fc_v[i + tab1[pulse_indexes & mask]] +=
  112. (pulse_signs & 1) ? 8191 : -8192; // +/-1 in (2.13)
  113. pulse_indexes >>= bits;
  114. pulse_signs >>= 1;
  115. }
  116. fc_v[tab2[pulse_indexes]] += (pulse_signs & 1) ? 8191 : -8192;
  117. }
  118. void ff_acelp_weighted_vector_sum(
  119. int16_t* out,
  120. const int16_t *in_a,
  121. const int16_t *in_b,
  122. int16_t weight_coeff_a,
  123. int16_t weight_coeff_b,
  124. int16_t rounder,
  125. int shift,
  126. int length)
  127. {
  128. int i;
  129. // Clipping required here; breaks OVERFLOW test.
  130. for(i=0; i<length; i++)
  131. out[i] = av_clip_int16((
  132. in_a[i] * weight_coeff_a +
  133. in_b[i] * weight_coeff_b +
  134. rounder) >> shift);
  135. }