tables.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. /*
  2. * MPEG layer 3 tables source file
  3. *
  4. * Copyright (c) 1999 Albert L Faber
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this library; if not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. /* $Id: tables.c,v 1.29 2011/05/07 16:05:17 rbrito Exp $ */
  22. #ifdef HAVE_CONFIG_H
  23. # include <config.h>
  24. #endif
  25. #include "machine.h"
  26. #include "lame.h"
  27. #include "tables.h"
  28. static const uint16_t t1HB[] = {
  29. 1, 1,
  30. 1, 0
  31. };
  32. static const uint16_t t2HB[] = {
  33. 1, 2, 1,
  34. 3, 1, 1,
  35. 3, 2, 0
  36. };
  37. static const uint16_t t3HB[] = {
  38. 3, 2, 1,
  39. 1, 1, 1,
  40. 3, 2, 0
  41. };
  42. static const uint16_t t5HB[] = {
  43. 1, 2, 6, 5,
  44. 3, 1, 4, 4,
  45. 7, 5, 7, 1,
  46. 6, 1, 1, 0
  47. };
  48. static const uint16_t t6HB[] = {
  49. 7, 3, 5, 1,
  50. 6, 2, 3, 2,
  51. 5, 4, 4, 1,
  52. 3, 3, 2, 0
  53. };
  54. static const uint16_t t7HB[] = {
  55. 1, 2, 10, 19, 16, 10,
  56. 3, 3, 7, 10, 5, 3,
  57. 11, 4, 13, 17, 8, 4,
  58. 12, 11, 18, 15, 11, 2,
  59. 7, 6, 9, 14, 3, 1,
  60. 6, 4, 5, 3, 2, 0
  61. };
  62. static const uint16_t t8HB[] = {
  63. 3, 4, 6, 18, 12, 5,
  64. 5, 1, 2, 16, 9, 3,
  65. 7, 3, 5, 14, 7, 3,
  66. 19, 17, 15, 13, 10, 4,
  67. 13, 5, 8, 11, 5, 1,
  68. 12, 4, 4, 1, 1, 0
  69. };
  70. static const uint16_t t9HB[] = {
  71. 7, 5, 9, 14, 15, 7,
  72. 6, 4, 5, 5, 6, 7,
  73. 7, 6, 8, 8, 8, 5,
  74. 15, 6, 9, 10, 5, 1,
  75. 11, 7, 9, 6, 4, 1,
  76. 14, 4, 6, 2, 6, 0
  77. };
  78. static const uint16_t t10HB[] = {
  79. 1, 2, 10, 23, 35, 30, 12, 17,
  80. 3, 3, 8, 12, 18, 21, 12, 7,
  81. 11, 9, 15, 21, 32, 40, 19, 6,
  82. 14, 13, 22, 34, 46, 23, 18, 7,
  83. 20, 19, 33, 47, 27, 22, 9, 3,
  84. 31, 22, 41, 26, 21, 20, 5, 3,
  85. 14, 13, 10, 11, 16, 6, 5, 1,
  86. 9, 8, 7, 8, 4, 4, 2, 0
  87. };
  88. static const uint16_t t11HB[] = {
  89. 3, 4, 10, 24, 34, 33, 21, 15,
  90. 5, 3, 4, 10, 32, 17, 11, 10,
  91. 11, 7, 13, 18, 30, 31, 20, 5,
  92. 25, 11, 19, 59, 27, 18, 12, 5,
  93. 35, 33, 31, 58, 30, 16, 7, 5,
  94. 28, 26, 32, 19, 17, 15, 8, 14,
  95. 14, 12, 9, 13, 14, 9, 4, 1,
  96. 11, 4, 6, 6, 6, 3, 2, 0
  97. };
  98. static const uint16_t t12HB[] = {
  99. 9, 6, 16, 33, 41, 39, 38, 26,
  100. 7, 5, 6, 9, 23, 16, 26, 11,
  101. 17, 7, 11, 14, 21, 30, 10, 7,
  102. 17, 10, 15, 12, 18, 28, 14, 5,
  103. 32, 13, 22, 19, 18, 16, 9, 5,
  104. 40, 17, 31, 29, 17, 13, 4, 2,
  105. 27, 12, 11, 15, 10, 7, 4, 1,
  106. 27, 12, 8, 12, 6, 3, 1, 0
  107. };
  108. static const uint16_t t13HB[] = {
  109. 1, 5, 14, 21, 34, 51, 46, 71, 42, 52, 68, 52, 67, 44, 43, 19,
  110. 3, 4, 12, 19, 31, 26, 44, 33, 31, 24, 32, 24, 31, 35, 22, 14,
  111. 15, 13, 23, 36, 59, 49, 77, 65, 29, 40, 30, 40, 27, 33, 42, 16,
  112. 22, 20, 37, 61, 56, 79, 73, 64, 43, 76, 56, 37, 26, 31, 25, 14,
  113. 35, 16, 60, 57, 97, 75, 114, 91, 54, 73, 55, 41, 48, 53, 23, 24,
  114. 58, 27, 50, 96, 76, 70, 93, 84, 77, 58, 79, 29, 74, 49, 41, 17,
  115. 47, 45, 78, 74, 115, 94, 90, 79, 69, 83, 71, 50, 59, 38, 36, 15,
  116. 72, 34, 56, 95, 92, 85, 91, 90, 86, 73, 77, 65, 51, 44, 43, 42,
  117. 43, 20, 30, 44, 55, 78, 72, 87, 78, 61, 46, 54, 37, 30, 20, 16,
  118. 53, 25, 41, 37, 44, 59, 54, 81, 66, 76, 57, 54, 37, 18, 39, 11,
  119. 35, 33, 31, 57, 42, 82, 72, 80, 47, 58, 55, 21, 22, 26, 38, 22,
  120. 53, 25, 23, 38, 70, 60, 51, 36, 55, 26, 34, 23, 27, 14, 9, 7,
  121. 34, 32, 28, 39, 49, 75, 30, 52, 48, 40, 52, 28, 18, 17, 9, 5,
  122. 45, 21, 34, 64, 56, 50, 49, 45, 31, 19, 12, 15, 10, 7, 6, 3,
  123. 48, 23, 20, 39, 36, 35, 53, 21, 16, 23, 13, 10, 6, 1, 4, 2,
  124. 16, 15, 17, 27, 25, 20, 29, 11, 17, 12, 16, 8, 1, 1, 0, 1
  125. };
  126. static const uint16_t t15HB[] = {
  127. 7, 12, 18, 53, 47, 76, 124, 108, 89, 123, 108, 119, 107, 81, 122, 63,
  128. 13, 5, 16, 27, 46, 36, 61, 51, 42, 70, 52, 83, 65, 41, 59, 36,
  129. 19, 17, 15, 24, 41, 34, 59, 48, 40, 64, 50, 78, 62, 80, 56, 33,
  130. 29, 28, 25, 43, 39, 63, 55, 93, 76, 59, 93, 72, 54, 75, 50, 29,
  131. 52, 22, 42, 40, 67, 57, 95, 79, 72, 57, 89, 69, 49, 66, 46, 27,
  132. 77, 37, 35, 66, 58, 52, 91, 74, 62, 48, 79, 63, 90, 62, 40, 38,
  133. 125, 32, 60, 56, 50, 92, 78, 65, 55, 87, 71, 51, 73, 51, 70, 30,
  134. 109, 53, 49, 94, 88, 75, 66, 122, 91, 73, 56, 42, 64, 44, 21, 25,
  135. 90, 43, 41, 77, 73, 63, 56, 92, 77, 66, 47, 67, 48, 53, 36, 20,
  136. 71, 34, 67, 60, 58, 49, 88, 76, 67, 106, 71, 54, 38, 39, 23, 15,
  137. 109, 53, 51, 47, 90, 82, 58, 57, 48, 72, 57, 41, 23, 27, 62, 9,
  138. 86, 42, 40, 37, 70, 64, 52, 43, 70, 55, 42, 25, 29, 18, 11, 11,
  139. 118, 68, 30, 55, 50, 46, 74, 65, 49, 39, 24, 16, 22, 13, 14, 7,
  140. 91, 44, 39, 38, 34, 63, 52, 45, 31, 52, 28, 19, 14, 8, 9, 3,
  141. 123, 60, 58, 53, 47, 43, 32, 22, 37, 24, 17, 12, 15, 10, 2, 1,
  142. 71, 37, 34, 30, 28, 20, 17, 26, 21, 16, 10, 6, 8, 6, 2, 0
  143. };
  144. static const uint16_t t16HB[] = {
  145. 1, 5, 14, 44, 74, 63, 110, 93, 172, 149, 138, 242, 225, 195, 376, 17,
  146. 3, 4, 12, 20, 35, 62, 53, 47, 83, 75, 68, 119, 201, 107, 207, 9,
  147. 15, 13, 23, 38, 67, 58, 103, 90, 161, 72, 127, 117, 110, 209, 206, 16,
  148. 45, 21, 39, 69, 64, 114, 99, 87, 158, 140, 252, 212, 199, 387, 365, 26,
  149. 75, 36, 68, 65, 115, 101, 179, 164, 155, 264, 246, 226, 395, 382, 362, 9,
  150. 66, 30, 59, 56, 102, 185, 173, 265, 142, 253, 232, 400, 388, 378, 445, 16,
  151. 111, 54, 52, 100, 184, 178, 160, 133, 257, 244, 228, 217, 385, 366, 715, 10,
  152. 98, 48, 91, 88, 165, 157, 148, 261, 248, 407, 397, 372, 380, 889, 884, 8,
  153. 85, 84, 81, 159, 156, 143, 260, 249, 427, 401, 392, 383, 727, 713, 708, 7,
  154. 154, 76, 73, 141, 131, 256, 245, 426, 406, 394, 384, 735, 359, 710, 352, 11,
  155. 139, 129, 67, 125, 247, 233, 229, 219, 393, 743, 737, 720, 885, 882, 439, 4,
  156. 243, 120, 118, 115, 227, 223, 396, 746, 742, 736, 721, 712, 706, 223, 436, 6,
  157. 202, 224, 222, 218, 216, 389, 386, 381, 364, 888, 443, 707, 440, 437, 1728, 4,
  158. 747, 211, 210, 208, 370, 379, 734, 723, 714, 1735, 883, 877, 876, 3459, 865, 2,
  159. 377, 369, 102, 187, 726, 722, 358, 711, 709, 866, 1734, 871, 3458, 870, 434, 0,
  160. 12, 10, 7, 11, 10, 17, 11, 9, 13, 12, 10, 7, 5, 3, 1, 3
  161. };
  162. static const uint16_t t24HB[] = {
  163. 15, 13, 46, 80, 146, 262, 248, 434, 426, 669, 653, 649, 621, 517, 1032, 88,
  164. 14, 12, 21, 38, 71, 130, 122, 216, 209, 198, 327, 345, 319, 297, 279, 42,
  165. 47, 22, 41, 74, 68, 128, 120, 221, 207, 194, 182, 340, 315, 295, 541, 18,
  166. 81, 39, 75, 70, 134, 125, 116, 220, 204, 190, 178, 325, 311, 293, 271, 16,
  167. 147, 72, 69, 135, 127, 118, 112, 210, 200, 188, 352, 323, 306, 285, 540, 14,
  168. 263, 66, 129, 126, 119, 114, 214, 202, 192, 180, 341, 317, 301, 281, 262, 12,
  169. 249, 123, 121, 117, 113, 215, 206, 195, 185, 347, 330, 308, 291, 272, 520, 10,
  170. 435, 115, 111, 109, 211, 203, 196, 187, 353, 332, 313, 298, 283, 531, 381, 17,
  171. 427, 212, 208, 205, 201, 193, 186, 177, 169, 320, 303, 286, 268, 514, 377, 16,
  172. 335, 199, 197, 191, 189, 181, 174, 333, 321, 305, 289, 275, 521, 379, 371, 11,
  173. 668, 184, 183, 179, 175, 344, 331, 314, 304, 290, 277, 530, 383, 373, 366, 10,
  174. 652, 346, 171, 168, 164, 318, 309, 299, 287, 276, 263, 513, 375, 368, 362, 6,
  175. 648, 322, 316, 312, 307, 302, 292, 284, 269, 261, 512, 376, 370, 364, 359, 4,
  176. 620, 300, 296, 294, 288, 282, 273, 266, 515, 380, 374, 369, 365, 361, 357, 2,
  177. 1033, 280, 278, 274, 267, 264, 259, 382, 378, 372, 367, 363, 360, 358, 356, 0,
  178. 43, 20, 19, 17, 15, 13, 11, 9, 7, 6, 4, 7, 5, 3, 1, 3
  179. };
  180. static const uint16_t t32HB[] = {
  181. 1 << 0, 5 << 1, 4 << 1, 5 << 2, 6 << 1, 5 << 2, 4 << 2, 4 << 3,
  182. 7 << 1, 3 << 2, 6 << 2, 0 << 3, 7 << 2, 2 << 3, 3 << 3, 1 << 4
  183. };
  184. static const uint16_t t33HB[] = {
  185. 15 << 0, 14 << 1, 13 << 1, 12 << 2, 11 << 1, 10 << 2, 9 << 2, 8 << 3,
  186. 7 << 1, 6 << 2, 5 << 2, 4 << 3, 3 << 2, 2 << 3, 1 << 3, 0 << 4
  187. };
  188. const uint8_t t1l[] = {
  189. 1, 4,
  190. 3, 5
  191. };
  192. static const uint8_t t2l[] = {
  193. 1, 4, 7,
  194. 4, 5, 7,
  195. 6, 7, 8
  196. };
  197. static const uint8_t t3l[] = {
  198. 2, 3, 7,
  199. 4, 4, 7,
  200. 6, 7, 8
  201. };
  202. static const uint8_t t5l[] = {
  203. 1, 4, 7, 8,
  204. 4, 5, 8, 9,
  205. 7, 8, 9, 10,
  206. 8, 8, 9, 10
  207. };
  208. static const uint8_t t6l[] = {
  209. 3, 4, 6, 8,
  210. 4, 4, 6, 7,
  211. 5, 6, 7, 8,
  212. 7, 7, 8, 9
  213. };
  214. static const uint8_t t7l[] = {
  215. 1, 4, 7, 9, 9, 10,
  216. 4, 6, 8, 9, 9, 10,
  217. 7, 7, 9, 10, 10, 11,
  218. 8, 9, 10, 11, 11, 11,
  219. 8, 9, 10, 11, 11, 12,
  220. 9, 10, 11, 12, 12, 12
  221. };
  222. static const uint8_t t8l[] = {
  223. 2, 4, 7, 9, 9, 10,
  224. 4, 4, 6, 10, 10, 10,
  225. 7, 6, 8, 10, 10, 11,
  226. 9, 10, 10, 11, 11, 12,
  227. 9, 9, 10, 11, 12, 12,
  228. 10, 10, 11, 11, 13, 13
  229. };
  230. static const uint8_t t9l[] = {
  231. 3, 4, 6, 7, 9, 10,
  232. 4, 5, 6, 7, 8, 10,
  233. 5, 6, 7, 8, 9, 10,
  234. 7, 7, 8, 9, 9, 10,
  235. 8, 8, 9, 9, 10, 11,
  236. 9, 9, 10, 10, 11, 11
  237. };
  238. static const uint8_t t10l[] = {
  239. 1, 4, 7, 9, 10, 10, 10, 11,
  240. 4, 6, 8, 9, 10, 11, 10, 10,
  241. 7, 8, 9, 10, 11, 12, 11, 11,
  242. 8, 9, 10, 11, 12, 12, 11, 12,
  243. 9, 10, 11, 12, 12, 12, 12, 12,
  244. 10, 11, 12, 12, 13, 13, 12, 13,
  245. 9, 10, 11, 12, 12, 12, 13, 13,
  246. 10, 10, 11, 12, 12, 13, 13, 13
  247. };
  248. static const uint8_t t11l[] = {
  249. 2, 4, 6, 8, 9, 10, 9, 10,
  250. 4, 5, 6, 8, 10, 10, 9, 10,
  251. 6, 7, 8, 9, 10, 11, 10, 10,
  252. 8, 8, 9, 11, 10, 12, 10, 11,
  253. 9, 10, 10, 11, 11, 12, 11, 12,
  254. 9, 10, 11, 12, 12, 13, 12, 13,
  255. 9, 9, 9, 10, 11, 12, 12, 12,
  256. 9, 9, 10, 11, 12, 12, 12, 12
  257. };
  258. static const uint8_t t12l[] = {
  259. 4, 4, 6, 8, 9, 10, 10, 10,
  260. 4, 5, 6, 7, 9, 9, 10, 10,
  261. 6, 6, 7, 8, 9, 10, 9, 10,
  262. 7, 7, 8, 8, 9, 10, 10, 10,
  263. 8, 8, 9, 9, 10, 10, 10, 11,
  264. 9, 9, 10, 10, 10, 11, 10, 11,
  265. 9, 9, 9, 10, 10, 11, 11, 12,
  266. 10, 10, 10, 11, 11, 11, 11, 12
  267. };
  268. static const uint8_t t13l[] = {
  269. 1, 5, 7, 8, 9, 10, 10, 11, 10, 11, 12, 12, 13, 13, 14, 14,
  270. 4, 6, 8, 9, 10, 10, 11, 11, 11, 11, 12, 12, 13, 14, 14, 14,
  271. 7, 8, 9, 10, 11, 11, 12, 12, 11, 12, 12, 13, 13, 14, 15, 15,
  272. 8, 9, 10, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 15, 15,
  273. 9, 9, 11, 11, 12, 12, 13, 13, 12, 13, 13, 14, 14, 15, 15, 16,
  274. 10, 10, 11, 12, 12, 12, 13, 13, 13, 13, 14, 13, 15, 15, 16, 16,
  275. 10, 11, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16,
  276. 11, 11, 12, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 16, 18, 18,
  277. 10, 10, 11, 12, 12, 13, 13, 14, 14, 14, 14, 15, 15, 16, 17, 17,
  278. 11, 11, 12, 12, 13, 13, 13, 15, 14, 15, 15, 16, 16, 16, 18, 17,
  279. 11, 12, 12, 13, 13, 14, 14, 15, 14, 15, 16, 15, 16, 17, 18, 19,
  280. 12, 12, 12, 13, 14, 14, 14, 14, 15, 15, 15, 16, 17, 17, 17, 18,
  281. 12, 13, 13, 14, 14, 15, 14, 15, 16, 16, 17, 17, 17, 18, 18, 18,
  282. 13, 13, 14, 15, 15, 15, 16, 16, 16, 16, 16, 17, 18, 17, 18, 18,
  283. 14, 14, 14, 15, 15, 15, 17, 16, 16, 19, 17, 17, 17, 19, 18, 18,
  284. 13, 14, 15, 16, 16, 16, 17, 16, 17, 17, 18, 18, 21, 20, 21, 18
  285. };
  286. static const uint8_t t15l[] = {
  287. 3, 5, 6, 8, 8, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 14,
  288. 5, 5, 7, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13,
  289. 6, 7, 7, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 13,
  290. 7, 8, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13,
  291. 8, 8, 9, 9, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 13,
  292. 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 13, 13, 13, 14,
  293. 10, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 14, 14,
  294. 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 14,
  295. 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 14, 14, 14,
  296. 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14,
  297. 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 15, 14,
  298. 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 15,
  299. 12, 12, 11, 12, 12, 12, 13, 13, 13, 13, 13, 13, 14, 14, 15, 15,
  300. 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 14, 15, 15,
  301. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 14, 15,
  302. 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 15, 15, 15, 15
  303. };
  304. static const uint8_t t16_5l[] = {
  305. 1, 5, 7, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 11,
  306. 4, 6, 8, 9, 10, 11, 11, 11, 12, 12, 12, 13, 14, 13, 14, 11,
  307. 7, 8, 9, 10, 11, 11, 12, 12, 13, 12, 13, 13, 13, 14, 14, 12,
  308. 9, 9, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15, 13,
  309. 10, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 12,
  310. 10, 10, 11, 11, 12, 13, 13, 14, 13, 14, 14, 15, 15, 15, 16, 13,
  311. 11, 11, 11, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 16, 13,
  312. 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 15, 17, 17, 13,
  313. 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 13,
  314. 12, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 15, 16, 15, 14,
  315. 12, 13, 12, 13, 14, 14, 14, 14, 15, 16, 16, 16, 17, 17, 16, 13,
  316. 13, 13, 13, 13, 14, 14, 15, 16, 16, 16, 16, 16, 16, 15, 16, 14,
  317. 13, 14, 14, 14, 14, 15, 15, 15, 15, 17, 16, 16, 16, 16, 18, 14,
  318. 15, 14, 14, 14, 15, 15, 16, 16, 16, 18, 17, 17, 17, 19, 17, 14,
  319. 14, 15, 13, 14, 16, 16, 15, 16, 16, 17, 18, 17, 19, 17, 16, 14,
  320. 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 12
  321. };
  322. static const uint8_t t16l[] = {
  323. 1, 5, 7, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 10,
  324. 4, 6, 8, 9, 10, 11, 11, 11, 12, 12, 12, 13, 14, 13, 14, 10,
  325. 7, 8, 9, 10, 11, 11, 12, 12, 13, 12, 13, 13, 13, 14, 14, 11,
  326. 9, 9, 10, 11, 11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15, 12,
  327. 10, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 11,
  328. 10, 10, 11, 11, 12, 13, 13, 14, 13, 14, 14, 15, 15, 15, 16, 12,
  329. 11, 11, 11, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 16, 12,
  330. 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 15, 17, 17, 12,
  331. 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 12,
  332. 12, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 15, 16, 15, 13,
  333. 12, 13, 12, 13, 14, 14, 14, 14, 15, 16, 16, 16, 17, 17, 16, 12,
  334. 13, 13, 13, 13, 14, 14, 15, 16, 16, 16, 16, 16, 16, 15, 16, 13,
  335. 13, 14, 14, 14, 14, 15, 15, 15, 15, 17, 16, 16, 16, 16, 18, 13,
  336. 15, 14, 14, 14, 15, 15, 16, 16, 16, 18, 17, 17, 17, 19, 17, 13,
  337. 14, 15, 13, 14, 16, 16, 15, 16, 16, 17, 18, 17, 19, 17, 16, 13,
  338. 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 10
  339. };
  340. static const uint8_t t24l[] = {
  341. 4, 5, 7, 8, 9, 10, 10, 11, 11, 12, 12, 12, 12, 12, 13, 10,
  342. 5, 6, 7, 8, 9, 10, 10, 11, 11, 11, 12, 12, 12, 12, 12, 10,
  343. 7, 7, 8, 9, 9, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 9,
  344. 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 9,
  345. 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 9,
  346. 10, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 9,
  347. 10, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 9,
  348. 11, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 10,
  349. 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 10,
  350. 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 10,
  351. 12, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 10,
  352. 12, 12, 11, 11, 11, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 10,
  353. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 10,
  354. 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 10,
  355. 13, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 10,
  356. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 6
  357. };
  358. const uint8_t t32l[] = {
  359. 1 + 0, 4 + 1, 4 + 1, 5 + 2, 4 + 1, 6 + 2, 5 + 2, 6 + 3,
  360. 4 + 1, 5 + 2, 5 + 2, 6 + 3, 5 + 2, 6 + 3, 6 + 3, 6 + 4
  361. };
  362. const uint8_t t33l[] = {
  363. 4 + 0, 4 + 1, 4 + 1, 4 + 2, 4 + 1, 4 + 2, 4 + 2, 4 + 3,
  364. 4 + 1, 4 + 2, 4 + 2, 4 + 3, 4 + 2, 4 + 3, 4 + 3, 4 + 4
  365. };
  366. const struct huffcodetab ht[HTN] = {
  367. /* xlen, linmax, table, hlen */
  368. {0, 0, NULL, NULL},
  369. {2, 0, t1HB, t1l},
  370. {3, 0, t2HB, t2l},
  371. {3, 0, t3HB, t3l},
  372. {0, 0, NULL, NULL}, /* Apparently not used */
  373. {4, 0, t5HB, t5l},
  374. {4, 0, t6HB, t6l},
  375. {6, 0, t7HB, t7l},
  376. {6, 0, t8HB, t8l},
  377. {6, 0, t9HB, t9l},
  378. {8, 0, t10HB, t10l},
  379. {8, 0, t11HB, t11l},
  380. {8, 0, t12HB, t12l},
  381. {16, 0, t13HB, t13l},
  382. {0, 0, NULL, t16_5l}, /* Apparently not used */
  383. {16, 0, t15HB, t15l},
  384. {1, 1, t16HB, t16l},
  385. {2, 3, t16HB, t16l},
  386. {3, 7, t16HB, t16l},
  387. {4, 15, t16HB, t16l},
  388. {6, 63, t16HB, t16l},
  389. {8, 255, t16HB, t16l},
  390. {10, 1023, t16HB, t16l},
  391. {13, 8191, t16HB, t16l},
  392. {4, 15, t24HB, t24l},
  393. {5, 31, t24HB, t24l},
  394. {6, 63, t24HB, t24l},
  395. {7, 127, t24HB, t24l},
  396. {8, 255, t24HB, t24l},
  397. {9, 511, t24HB, t24l},
  398. {11, 2047, t24HB, t24l},
  399. {13, 8191, t24HB, t24l},
  400. {0, 0, t32HB, t32l},
  401. {0, 0, t33HB, t33l},
  402. };
  403. /* for (i = 0; i < 16*16; i++) {
  404. * largetbl[i] = ((ht[16].hlen[i]) << 16) + ht[24].hlen[i];
  405. * }
  406. */
  407. const uint32_t largetbl[16 * 16] = {
  408. 0x010004, 0x050005, 0x070007, 0x090008, 0x0a0009, 0x0a000a, 0x0b000a, 0x0b000b,
  409. 0x0c000b, 0x0c000c, 0x0c000c, 0x0d000c, 0x0d000c, 0x0d000c, 0x0e000d, 0x0a000a,
  410. 0x040005, 0x060006, 0x080007, 0x090008, 0x0a0009, 0x0b000a, 0x0b000a, 0x0b000b,
  411. 0x0c000b, 0x0c000b, 0x0c000c, 0x0d000c, 0x0e000c, 0x0d000c, 0x0e000c, 0x0a000a,
  412. 0x070007, 0x080007, 0x090008, 0x0a0009, 0x0b0009, 0x0b000a, 0x0c000a, 0x0c000b,
  413. 0x0d000b, 0x0c000b, 0x0d000b, 0x0d000c, 0x0d000c, 0x0e000c, 0x0e000d, 0x0b0009,
  414. 0x090008, 0x090008, 0x0a0009, 0x0b0009, 0x0b000a, 0x0c000a, 0x0c000a, 0x0c000b,
  415. 0x0d000b, 0x0d000b, 0x0e000b, 0x0e000c, 0x0e000c, 0x0f000c, 0x0f000c, 0x0c0009,
  416. 0x0a0009, 0x0a0009, 0x0b0009, 0x0b000a, 0x0c000a, 0x0c000a, 0x0d000a, 0x0d000b,
  417. 0x0d000b, 0x0e000b, 0x0e000c, 0x0e000c, 0x0f000c, 0x0f000c, 0x0f000d, 0x0b0009,
  418. 0x0a000a, 0x0a0009, 0x0b000a, 0x0b000a, 0x0c000a, 0x0d000a, 0x0d000b, 0x0e000b,
  419. 0x0d000b, 0x0e000b, 0x0e000c, 0x0f000c, 0x0f000c, 0x0f000c, 0x10000c, 0x0c0009,
  420. 0x0b000a, 0x0b000a, 0x0b000a, 0x0c000a, 0x0d000a, 0x0d000b, 0x0d000b, 0x0d000b,
  421. 0x0e000b, 0x0e000c, 0x0e000c, 0x0e000c, 0x0f000c, 0x0f000c, 0x10000d, 0x0c0009,
  422. 0x0b000b, 0x0b000a, 0x0c000a, 0x0c000a, 0x0d000b, 0x0d000b, 0x0d000b, 0x0e000b,
  423. 0x0e000c, 0x0f000c, 0x0f000c, 0x0f000c, 0x0f000c, 0x11000d, 0x11000d, 0x0c000a,
  424. 0x0b000b, 0x0c000b, 0x0c000b, 0x0d000b, 0x0d000b, 0x0d000b, 0x0e000b, 0x0e000b,
  425. 0x0f000b, 0x0f000c, 0x0f000c, 0x0f000c, 0x10000c, 0x10000d, 0x10000d, 0x0c000a,
  426. 0x0c000b, 0x0c000b, 0x0c000b, 0x0d000b, 0x0d000b, 0x0e000b, 0x0e000b, 0x0f000c,
  427. 0x0f000c, 0x0f000c, 0x0f000c, 0x10000c, 0x0f000d, 0x10000d, 0x0f000d, 0x0d000a,
  428. 0x0c000c, 0x0d000b, 0x0c000b, 0x0d000b, 0x0e000b, 0x0e000c, 0x0e000c, 0x0e000c,
  429. 0x0f000c, 0x10000c, 0x10000c, 0x10000d, 0x11000d, 0x11000d, 0x10000d, 0x0c000a,
  430. 0x0d000c, 0x0d000c, 0x0d000b, 0x0d000b, 0x0e000b, 0x0e000c, 0x0f000c, 0x10000c,
  431. 0x10000c, 0x10000c, 0x10000c, 0x10000d, 0x10000d, 0x0f000d, 0x10000d, 0x0d000a,
  432. 0x0d000c, 0x0e000c, 0x0e000c, 0x0e000c, 0x0e000c, 0x0f000c, 0x0f000c, 0x0f000c,
  433. 0x0f000c, 0x11000c, 0x10000d, 0x10000d, 0x10000d, 0x10000d, 0x12000d, 0x0d000a,
  434. 0x0f000c, 0x0e000c, 0x0e000c, 0x0e000c, 0x0f000c, 0x0f000c, 0x10000c, 0x10000c,
  435. 0x10000d, 0x12000d, 0x11000d, 0x11000d, 0x11000d, 0x13000d, 0x11000d, 0x0d000a,
  436. 0x0e000d, 0x0f000c, 0x0d000c, 0x0e000c, 0x10000c, 0x10000c, 0x0f000c, 0x10000d,
  437. 0x10000d, 0x11000d, 0x12000d, 0x11000d, 0x13000d, 0x11000d, 0x10000d, 0x0d000a,
  438. 0x0a0009, 0x0a0009, 0x0a0009, 0x0b0009, 0x0b0009, 0x0c0009, 0x0c0009, 0x0c0009,
  439. 0x0d0009, 0x0d0009, 0x0d0009, 0x0d000a, 0x0d000a, 0x0d000a, 0x0d000a, 0x0a0006
  440. };
  441. /* for (i = 0; i < 3*3; i++) {
  442. * table23[i] = ((ht[2].hlen[i]) << 16) + ht[3].hlen[i];
  443. * }
  444. */
  445. const uint32_t table23[3 * 3] = {
  446. 0x010002, 0x040003, 0x070007,
  447. 0x040004, 0x050004, 0x070007,
  448. 0x060006, 0x070007, 0x080008
  449. };
  450. /* for (i = 0; i < 4*4; i++) {
  451. * table56[i] = ((ht[5].hlen[i]) << 16) + ht[6].hlen[i];
  452. * }
  453. */
  454. const uint32_t table56[4 * 4] = {
  455. 0x010003, 0x040004, 0x070006, 0x080008, 0x040004, 0x050004, 0x080006, 0x090007,
  456. 0x070005, 0x080006, 0x090007, 0x0a0008, 0x080007, 0x080007, 0x090008, 0x0a0009
  457. };
  458. /*
  459. * 0: MPEG-2 LSF
  460. * 1: MPEG-1
  461. * 2: MPEG-2.5 LSF FhG extention (1995-07-11 shn)
  462. */
  463. typedef enum {
  464. MPEG_2 = 0,
  465. MPEG_1 = 1,
  466. MPEG_25 = 2
  467. } MPEG_t;
  468. const int bitrate_table[3][16] = {
  469. {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, -1}, /* MPEG 2 */
  470. {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1}, /* MPEG 1 */
  471. {0, 8, 16, 24, 32, 40, 48, 56, 64, -1, -1, -1, -1, -1, -1, -1}, /* MPEG 2.5 */
  472. };
  473. const int samplerate_table[3][4] = {
  474. {22050, 24000, 16000, -1}, /* MPEG 2 */
  475. {44100, 48000, 32000, -1}, /* MPEG 1 */
  476. {11025, 12000, 8000, -1}, /* MPEG 2.5 */
  477. };
  478. int
  479. lame_get_bitrate(int mpeg_version, int table_index)
  480. {
  481. if (0 <= mpeg_version && mpeg_version <= 2) {
  482. if (0 <= table_index && table_index <= 15) {
  483. return bitrate_table[mpeg_version][table_index];
  484. }
  485. }
  486. return -1;
  487. }
  488. int
  489. lame_get_samplerate(int mpeg_version, int table_index)
  490. {
  491. if (0 <= mpeg_version && mpeg_version <= 2) {
  492. if (0 <= table_index && table_index <= 3) {
  493. return samplerate_table[mpeg_version][table_index];
  494. }
  495. }
  496. return -1;
  497. }
  498. /* This is the scfsi_band table from 2.4.2.7 of the IS */
  499. const int scfsi_band[5] = { 0, 6, 11, 16, 21 };
  500. /* end of tables.c */