dcaenc.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * DCA encoder tables
  3. * Copyright (C) 2008-2012 Alexander E. Patrakov
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef AVCODEC_DCAENC_H
  22. #define AVCODEC_DCAENC_H
  23. #include <stdint.h>
  24. #include "dcamath.h"
  25. typedef struct {
  26. int32_t m;
  27. int32_t e;
  28. } softfloat;
  29. static const int sample_rates[] = {
  30. 8000, 16000, 32000, 11025, 22050, 44100, 12000, 24000, 48000, 0,
  31. };
  32. static const uint8_t bitstream_sfreq[] = { 1, 2, 3, 6, 7, 8, 11, 12, 13 };
  33. /* Auditory filter center frequencies and bandwidths, in Hz.
  34. * The last two are made up, because there is no scientific data.
  35. */
  36. static const uint16_t fc[] = {
  37. 50, 150, 250, 350, 450, 570, 700, 840, 1000, 1170, 1370, 1600, 1850, 2150,
  38. 2500, 2900, 3400, 4000, 4800, 5800, 7000, 8500, 10500, 13500, 17000
  39. };
  40. static const uint16_t erb[] = {
  41. 80, 100, 100, 100, 110, 120, 140, 150, 160, 190, 210, 240, 280,
  42. 320, 380, 450, 550, 700, 900, 1100, 1300, 1800, 2500, 3500, 4500
  43. };
  44. static const softfloat stepsize_inv[27] = {
  45. {0, 0}, {1342177360, 21}, {2147483647, 21}, {1342177360, 20},
  46. {1819901661, 20}, {2147483647, 20}, {1278263843, 19}, {1579032492, 19},
  47. {1412817763, 18}, {1220162327, 17}, {1118482133, 16}, {1917391412, 16},
  48. {1766017772, 15}, {1525212826, 14}, {1290553940, 13}, {2097179000, 13},
  49. {1677683200, 12}, {1497972244, 11}, {1310893147, 10}, {1165354136, 9},
  50. {1748031204, 9}, {1542092044, 8}, {1636178017, 7}, {1636178017, 6},
  51. {1636178017, 5}, {1636178017, 4}, {1636178017, 3},
  52. };
  53. static const softfloat scalefactor_inv[128] = {
  54. {2147483647, 1}, {2147483647, 1}, {2147483647, 2}, {2147483647, 2},
  55. {2147483647, 2}, {2147483647, 2}, {1431655765, 2}, {1431655765, 2},
  56. {1431655765, 2}, {2147483647, 3}, {2147483647, 3}, {1717986918, 3},
  57. {1431655765, 3}, {1227133513, 3}, {1227133513, 3}, {2147483647, 4},
  58. {1717986918, 4}, {1561806289, 4}, {1431655765, 4}, {1227133513, 4},
  59. {2147483647, 5}, {1908874353, 5}, {1717986918, 5}, {1493901668, 5},
  60. {1321528398, 5}, {1145324612, 5}, {2021161080, 6}, {1808407282, 6},
  61. {1561806289, 6}, {1374389534, 6}, {1227133513, 6}, {2147483647, 7},
  62. {1908874353, 7}, {1676084798, 7}, {1477838209, 7}, {1296593900, 7},
  63. {1145324612, 7}, {2021161080, 8}, {1773405851, 8}, {1561806289, 8},
  64. {1374389534, 8}, {1216273924, 8}, {2139127680, 9}, {1882725390, 9},
  65. {1660893697, 9}, {1462116526, 9}, {1287484341, 9}, {1135859119, 9},
  66. {1999112050, 10}, {1762037865, 10}, {1552982525, 10}, {1367551775, 10},
  67. {1205604855, 10}, {2124660150, 11}, {1871509153, 11}, {1648443220, 11},
  68. {1452459217, 11}, {1279990253, 11}, {1127704233, 11}, {1987368509, 12},
  69. {1750814693, 12}, {1542632939, 12}, {1359099663, 12}, {1197398995, 12},
  70. {2109880792, 13}, {1858853132, 13}, {1638006149, 13}, {1443165385, 13},
  71. {1271479187, 13}, {1120235993, 13}, {1973767086, 14}, {1739045674, 14},
  72. {1532153461, 14}, {1349922194, 14}, {1189384493, 14}, {2095804865, 15},
  73. {1846464029, 15}, {1626872524, 15}, {1433347133, 15}, {1262853884, 15},
  74. {1112619678, 15}, {1960569045, 16}, {1727349015, 16}, {1521881227, 16},
  75. {1340842289, 16}, {1181357555, 16}, {2081669156, 17}, {1834047752, 17},
  76. {1615889229, 17}, {1423675973, 17}, {1254322457, 17}, {1105123583, 17},
  77. {1947330755, 18}, {1715693602, 18}, {1511607799, 18}, {1331801790, 18},
  78. {1173384427, 18}, {2067616532, 19}, {1821667648, 19}, {1604980024, 19},
  79. {1414066955, 19}, {1245861410, 19}, {1097665748, 19}, {1934193616, 20},
  80. {1704119624, 20}, {1501412075, 20}, {1322817107, 20}, {1165466323, 20},
  81. {2053666205, 21}, {1809379407, 21}, {1594151671, 21}, {1404526328, 21},
  82. {1237455941, 21}, {1090259329, 21}, {1921143210, 22}, {1692621231, 22},
  83. {1491281857, 22}, {1313892269, 22}, {1157603482, 22}, {2039810470, 23},
  84. {1797172644, 23}, {1583396912, 23}, {1395050052, 23}, {1229107276, 23},
  85. {1082903494, 23}, {1082903494, 23}, {1082903494, 23}, {1082903494, 23},
  86. };
  87. /* manually derived from
  88. * Table B.5: Selection of quantization levels and codebooks
  89. */
  90. static const int bit_consumption[27] = {
  91. -8, 28, 40, 48, 52, 60, 68, 76, 80, 96,
  92. 112, 128, 144, 160, 176, 192, 208, 224, 240, 256,
  93. 272, 288, 304, 320, 336, 352, 368,
  94. };
  95. static const int8_t lfe_index[16] = {
  96. 1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 1, 3, 2, 3
  97. };
  98. static const int8_t channel_reorder_lfe[16][9] = {
  99. { 0, -1, -1, -1, -1, -1, -1, -1, -1 },
  100. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  101. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  102. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  103. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  104. { 2, 0, 1, -1, -1, -1, -1, -1, -1 },
  105. { 0, 1, 3, -1, -1, -1, -1, -1, -1 },
  106. { 2, 0, 1, 4, -1, -1, -1, -1, -1 },
  107. { 0, 1, 3, 4, -1, -1, -1, -1, -1 },
  108. { 2, 0, 1, 4, 5, -1, -1, -1, -1 },
  109. { 3, 4, 0, 1, 5, 6, -1, -1, -1 },
  110. { 2, 0, 1, 4, 5, 6, -1, -1, -1 },
  111. { 0, 6, 4, 5, 2, 3, -1, -1, -1 },
  112. { 4, 2, 5, 0, 1, 6, 7, -1, -1 },
  113. { 5, 6, 0, 1, 7, 3, 8, 4, -1 },
  114. { 4, 2, 5, 0, 1, 6, 8, 7, -1 },
  115. };
  116. static const int8_t channel_reorder_nolfe[16][9] = {
  117. { 0, -1, -1, -1, -1, -1, -1, -1, -1 },
  118. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  119. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  120. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  121. { 0, 1, -1, -1, -1, -1, -1, -1, -1 },
  122. { 2, 0, 1, -1, -1, -1, -1, -1, -1 },
  123. { 0, 1, 2, -1, -1, -1, -1, -1, -1 },
  124. { 2, 0, 1, 3, -1, -1, -1, -1, -1 },
  125. { 0, 1, 2, 3, -1, -1, -1, -1, -1 },
  126. { 2, 0, 1, 3, 4, -1, -1, -1, -1 },
  127. { 2, 3, 0, 1, 4, 5, -1, -1, -1 },
  128. { 2, 0, 1, 3, 4, 5, -1, -1, -1 },
  129. { 0, 5, 3, 4, 1, 2, -1, -1, -1 },
  130. { 3, 2, 4, 0, 1, 5, 6, -1, -1 },
  131. { 4, 5, 0, 1, 6, 2, 7, 3, -1 },
  132. { 3, 2, 4, 0, 1, 5, 7, 6, -1 },
  133. };
  134. static inline int32_t quantize_value(int32_t value, softfloat quant)
  135. {
  136. int32_t offset = 1 << (quant.e - 1);
  137. value = mul32(value, quant.m) + offset;
  138. value = value >> quant.e;
  139. return value;
  140. }
  141. #endif /* AVCODEC_DCAENC_H */