qcelpdata.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /*
  2. * QCELP decoder
  3. * Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
  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_QCELPDATA_H
  22. #define AVCODEC_QCELPDATA_H
  23. /**
  24. * @file libavcodec/qcelpdata.h
  25. * Data tables for the QCELP decoder
  26. * @author Reynaldo H. Verdejo Pinochet
  27. * @remark FFmpeg merging spearheaded by Kenan Gillet
  28. * @remark Development mentored by Benjamin Larson
  29. */
  30. #include <stddef.h>
  31. #include <stdint.h>
  32. #include "libavutil/common.h"
  33. /**
  34. * QCELP unpacked data frame
  35. */
  36. typedef struct {
  37. /// @defgroup qcelp_codebook_parameters QCELP excitation codebook parameters
  38. /// @{
  39. uint8_t cbsign[16]; ///!< sign of the codebook gain for each codebook subframe
  40. uint8_t cbgain[16]; ///!< unsigned codebook gain for each codebook subframe
  41. uint8_t cindex[16]; ///!< codebook index for each codebook subframe
  42. /// @}
  43. /// @defgroup qcelp_pitch_parameters QCELP pitch prediction parameters
  44. /// @{
  45. uint8_t plag[4]; ///!< pitch lag for each pitch subframe
  46. uint8_t pfrac[4]; ///!< fractional pitch lag for each pitch subframe
  47. uint8_t pgain[4]; ///!< pitch gain for each pitch subframe
  48. /// @}
  49. /**
  50. * line spectral pair frequencies (LSP) for RATE_OCTAVE,
  51. * line spectral pair frequencies grouped into five vectors
  52. * of dimension two (LSPV) for other rates
  53. */
  54. uint8_t lspv[10];
  55. /**
  56. * reserved bits only present in bitrate 1, 1/4 and 1/8 packets
  57. */
  58. uint8_t reserved;
  59. } QCELPFrame;
  60. /**
  61. * pre-calculated table for hammsinc function
  62. * Only half of the table is needed because of symmetry.
  63. *
  64. * TIA/EIA/IS-733 2.4.5.2-2/3
  65. */
  66. static const float qcelp_hammsinc_table[4] = { -0.006822, 0.041249, -0.143459, 0.588863};
  67. typedef struct {
  68. uint8_t index; /*!< index into the QCELPContext structure */
  69. uint8_t bitpos; /*!< position of the lowest bit in the value's byte */
  70. uint8_t bitlen; /*!< number of bits to read */
  71. } QCELPBitmap;
  72. #define QCELP_OF(variable, bit, len) {offsetof(QCELPFrame, variable), bit, len}
  73. /**
  74. * bitmap unpacking tables for RATE_FULL
  75. *
  76. * TIA/EIA/IS-733 Table 2.4.7.1-1
  77. */
  78. static const QCELPBitmap qcelp_rate_full_bitmap[] = {
  79. // start on bit
  80. QCELP_OF(lspv [ 2], 0, 3), // 265
  81. QCELP_OF(lspv [ 1], 0, 7), // 262
  82. QCELP_OF(lspv [ 0], 0, 6), // 255
  83. QCELP_OF(lspv [ 4], 0, 6), // 249
  84. QCELP_OF(lspv [ 3], 0, 6), // 243
  85. QCELP_OF(lspv [ 2], 3, 4), // 237
  86. QCELP_OF(cbsign[ 0], 0, 1), // 233
  87. QCELP_OF(cbgain[ 0], 0, 4), // 232
  88. QCELP_OF(pfrac [ 0], 0, 1), // 228
  89. QCELP_OF(plag [ 0], 0, 7), // 227
  90. QCELP_OF(pgain [ 0], 0, 3), // 220
  91. QCELP_OF(cindex[ 1], 0, 4), // 217
  92. QCELP_OF(cbsign[ 1], 0, 1), // 213
  93. QCELP_OF(cbgain[ 1], 0, 4), // 212
  94. QCELP_OF(cindex[ 0], 0, 7), // 208
  95. QCELP_OF(cbgain[ 3], 0, 1), // 201
  96. QCELP_OF(cindex[ 2], 0, 7), // 200
  97. QCELP_OF(cbsign[ 2], 0, 1), // 193
  98. QCELP_OF(cbgain[ 2], 0, 4), // 192
  99. QCELP_OF(cindex[ 1], 4, 3), // 188
  100. QCELP_OF(plag [ 1], 0, 3), // 185
  101. QCELP_OF(pgain [ 1], 0, 3), // 182
  102. QCELP_OF(cindex[ 3], 0, 7), // 179
  103. QCELP_OF(cbsign[ 3], 0, 1), // 172
  104. QCELP_OF(cbgain[ 3], 1, 2), // 171
  105. QCELP_OF(cindex[ 4], 0, 6), // 169
  106. QCELP_OF(cbsign[ 4], 0, 1), // 163
  107. QCELP_OF(cbgain[ 4], 0, 4), // 162
  108. QCELP_OF(pfrac [ 1], 0, 1), // 158
  109. QCELP_OF(plag [ 1], 3, 4), // 157
  110. QCELP_OF(cbgain[ 6], 0, 3), // 153
  111. QCELP_OF(cindex[ 5], 0, 7), // 150
  112. QCELP_OF(cbsign[ 5], 0, 1), // 143
  113. QCELP_OF(cbgain[ 5], 0, 4), // 142
  114. QCELP_OF(cindex[ 4], 6, 1), // 138
  115. QCELP_OF(cindex[ 7], 0, 3), // 137
  116. QCELP_OF(cbsign[ 7], 0, 1), // 134
  117. QCELP_OF(cbgain[ 7], 0, 3), // 133
  118. QCELP_OF(cindex[ 6], 0, 7), // 130
  119. QCELP_OF(cbsign[ 6], 0, 1), // 123
  120. QCELP_OF(cbgain[ 6], 3, 1), // 122
  121. QCELP_OF(cbgain[ 8], 0, 1), // 121
  122. QCELP_OF(pfrac [ 2], 0, 1), // 120
  123. QCELP_OF(plag [ 2], 0, 7), // 119
  124. QCELP_OF(pgain [ 2], 0, 3), // 112
  125. QCELP_OF(cindex[ 7], 3, 4), // 109
  126. QCELP_OF(cbsign[ 9], 0, 1), // 105
  127. QCELP_OF(cbgain[ 9], 0, 4), // 104
  128. QCELP_OF(cindex[ 8], 0, 7), // 100
  129. QCELP_OF(cbsign[ 8], 0, 1), // 93
  130. QCELP_OF(cbgain[ 8], 1, 3), // 92
  131. QCELP_OF(cindex[10], 0, 4), // 89
  132. QCELP_OF(cbsign[10], 0, 1), // 85
  133. QCELP_OF(cbgain[10], 0, 4), // 84
  134. QCELP_OF(cindex[ 9], 0, 7), // 80
  135. QCELP_OF(pgain [ 3], 0, 2), // 73
  136. QCELP_OF(cindex[11], 0, 7), // 71
  137. QCELP_OF(cbsign[11], 0, 1), // 64
  138. QCELP_OF(cbgain[11], 0, 3), // 63
  139. QCELP_OF(cindex[10], 4, 3), // 60
  140. QCELP_OF(cindex[12], 0, 2), // 57
  141. QCELP_OF(cbsign[12], 0, 1), // 55
  142. QCELP_OF(cbgain[12], 0, 4), // 54
  143. QCELP_OF(pfrac [ 3], 0, 1), // 50
  144. QCELP_OF(plag [ 3], 0, 7), // 49
  145. QCELP_OF(pgain [ 3], 2, 1), // 42
  146. QCELP_OF(cindex[13], 0, 6), // 41
  147. QCELP_OF(cbsign[13], 0, 1), // 35
  148. QCELP_OF(cbgain[13], 0, 4), // 34
  149. QCELP_OF(cindex[12], 2, 5), // 30
  150. QCELP_OF(cbgain[15], 0, 3), // 25
  151. QCELP_OF(cindex[14], 0, 7), // 22
  152. QCELP_OF(cbsign[14], 0, 1), // 15
  153. QCELP_OF(cbgain[14], 0, 4), // 14
  154. QCELP_OF(cindex[13], 6, 1), // 10
  155. QCELP_OF(reserved, 0, 2), // 9
  156. QCELP_OF(cindex[15], 0, 7), // 7
  157. QCELP_OF(cbsign[15], 0, 1) // 0
  158. };
  159. /**
  160. * bitmap unpacking tables for RATE_HALF
  161. *
  162. * TIA/EIA/IS-733 Table 2.4.7.2-1
  163. */
  164. static const QCELPBitmap qcelp_rate_half_bitmap[] = {
  165. // start on bit
  166. QCELP_OF(lspv [2], 0, 3), // 123
  167. QCELP_OF(lspv [1], 0, 7), // 120
  168. QCELP_OF(lspv [0], 0, 6), // 113
  169. QCELP_OF(lspv [4], 0, 6), // 107
  170. QCELP_OF(lspv [3], 0, 6), // 101
  171. QCELP_OF(lspv [2], 3, 4), // 95
  172. QCELP_OF(cbsign[0], 0, 1), // 91
  173. QCELP_OF(cbgain[0], 0, 4), // 90
  174. QCELP_OF(pfrac [0], 0, 1), // 86
  175. QCELP_OF(plag [0], 0, 7), // 85
  176. QCELP_OF(pgain [0], 0, 3), // 78
  177. QCELP_OF(plag [1], 0, 6), // 75
  178. QCELP_OF(pgain [1], 0, 3), // 69
  179. QCELP_OF(cindex[0], 0, 7), // 66
  180. QCELP_OF(pgain [2], 0, 2), // 59
  181. QCELP_OF(cindex[1], 0, 7), // 57
  182. QCELP_OF(cbsign[1], 0, 1), // 50
  183. QCELP_OF(cbgain[1], 0, 4), // 49
  184. QCELP_OF(pfrac [1], 0, 1), // 45
  185. QCELP_OF(plag [1], 6, 1), // 44
  186. QCELP_OF(cindex[2], 0, 2), // 43
  187. QCELP_OF(cbsign[2], 0, 1), // 41
  188. QCELP_OF(cbgain[2], 0, 4), // 40
  189. QCELP_OF(pfrac [2], 0, 1), // 36
  190. QCELP_OF(plag [2], 0, 7), // 35
  191. QCELP_OF(pgain [2], 2, 1), // 28
  192. QCELP_OF(pfrac [3], 0, 1), // 27
  193. QCELP_OF(plag [3], 0, 7), // 26
  194. QCELP_OF(pgain [3], 0, 3), // 19
  195. QCELP_OF(cindex[2], 2, 5), // 16
  196. QCELP_OF(cindex[3], 0, 7), // 11
  197. QCELP_OF(cbsign[3], 0, 1), // 4
  198. QCELP_OF(cbgain[3], 0, 4) // 3
  199. };
  200. /**
  201. * bitmap unpacking tables for RATE_QUARTER
  202. *
  203. * TIA/EIA/IS-733 Table 2.4.7.3-1
  204. */
  205. static const QCELPBitmap qcelp_rate_quarter_bitmap[] = {
  206. // start on bit
  207. QCELP_OF(lspv [2], 0, 3), // 53
  208. QCELP_OF(lspv [1], 0, 7), // 50
  209. QCELP_OF(lspv [0], 0, 6), // 43
  210. QCELP_OF(lspv [4], 0, 6), // 37
  211. QCELP_OF(lspv [3], 0, 6), // 31
  212. QCELP_OF(lspv [2], 3, 4), // 25
  213. QCELP_OF(cbgain[3], 0, 4), // 21
  214. QCELP_OF(cbgain[2], 0, 4), // 17
  215. QCELP_OF(cbgain[1], 0, 4), // 13
  216. QCELP_OF(cbgain[0], 0, 4), // 9
  217. QCELP_OF(reserved, 0, 2), // 5
  218. QCELP_OF(cbgain[4], 0, 4) // 3
  219. };
  220. /**
  221. * bitmap unpacking tables for RATE_OCTAVE
  222. *
  223. * trick: CBSEED is written into QCELPContext.cbsign[15],
  224. * which is not used for RATE_OCTAVE.
  225. * CBSEED is only used to ensure the occurrence of random bit
  226. * patterns in the 16 first bits that are used as the seed.
  227. *
  228. * TIA/EIA/IS-733 Table 2.4.7.4-1
  229. */
  230. static const QCELPBitmap qcelp_rate_octave_bitmap[] = {
  231. // start on bit
  232. QCELP_OF(cbsign[15], 3, 1), // 19
  233. QCELP_OF(lspv [0], 0, 1), // 18
  234. QCELP_OF(lspv [1], 0, 1), // 17
  235. QCELP_OF(lspv [2], 0, 1), // 16
  236. QCELP_OF(cbsign[15], 2, 1), // 15
  237. QCELP_OF(lspv [3], 0, 1), // 14
  238. QCELP_OF(lspv [4], 0, 1), // 13
  239. QCELP_OF(lspv [5], 0, 1), // 12
  240. QCELP_OF(cbsign[15], 1, 1), // 11
  241. QCELP_OF(lspv [6], 0, 1), // 10
  242. QCELP_OF(lspv [7], 0, 1), // 9
  243. QCELP_OF(lspv [8], 0, 1), // 8
  244. QCELP_OF(cbsign[15], 0, 1), // 7
  245. QCELP_OF(lspv [9], 0, 1), // 6
  246. QCELP_OF(cbgain [0], 0, 2), // 7
  247. QCELP_OF(reserved, 0, 4) // 3
  248. };
  249. /**
  250. * position of the bitmapping data for each packet type in
  251. * the QCELPContext
  252. */
  253. static const QCELPBitmap * const qcelp_unpacking_bitmaps_per_rate[5] = {
  254. NULL, ///!< for SILENCE rate
  255. qcelp_rate_octave_bitmap,
  256. qcelp_rate_quarter_bitmap,
  257. qcelp_rate_half_bitmap,
  258. qcelp_rate_full_bitmap,
  259. };
  260. static const uint16_t qcelp_unpacking_bitmaps_lengths[5] = {
  261. 0, ///!< for SILENCE rate
  262. FF_ARRAY_ELEMS(qcelp_rate_octave_bitmap),
  263. FF_ARRAY_ELEMS(qcelp_rate_quarter_bitmap),
  264. FF_ARRAY_ELEMS(qcelp_rate_half_bitmap),
  265. FF_ARRAY_ELEMS(qcelp_rate_full_bitmap),
  266. };
  267. typedef uint16_t qcelp_vector[2];
  268. /**
  269. * LSP vector quantization tables in x*10000 form
  270. *
  271. * TIA/EIA/IS-733 tables 2.4.3.2.6.3-1 through 2.4.3.2.6.3-5
  272. */
  273. static const qcelp_vector qcelp_lspvq1[64]= {
  274. { 327, 118},{ 919, 111},{ 427, 440},{1327, 185},
  275. { 469, 50},{1272, 91},{ 892, 59},{1771, 193},
  276. { 222, 158},{1100, 127},{ 827, 55},{ 978, 791},
  277. { 665, 47},{ 700,1401},{ 670, 859},{1913,1048},
  278. { 471, 215},{1046, 125},{ 645, 298},{1599, 160},
  279. { 593, 39},{1187, 462},{ 749, 341},{1520, 511},
  280. { 290, 792},{ 909, 362},{ 753, 81},{1111,1058},
  281. { 519, 253},{ 828, 839},{ 685, 541},{1421,1258},
  282. { 386, 130},{ 962, 119},{ 542, 387},{1431, 185},
  283. { 526, 51},{1175, 260},{ 831, 167},{1728, 510},
  284. { 273, 437},{1172, 113},{ 771, 144},{1122, 751},
  285. { 619, 119},{ 492,1276},{ 658, 695},{1882, 615},
  286. { 415, 200},{1018, 88},{ 681, 339},{1436, 325},
  287. { 555, 122},{1042, 485},{ 826, 345},{1374, 743},
  288. { 383,1018},{1005, 358},{ 704, 86},{1301, 586},
  289. { 597, 241},{ 832, 621},{ 555, 573},{1504, 839}};
  290. static const qcelp_vector qcelp_lspvq2[128]= {
  291. { 255, 293},{ 904, 219},{ 151,1211},{1447, 498},
  292. { 470, 253},{1559, 177},{1547, 994},{2394, 242},
  293. { 91, 813},{ 857, 590},{ 934,1326},{1889, 282},
  294. { 813, 472},{1057,1494},{ 450,3315},{2163,1895},
  295. { 538, 532},{1399, 218},{ 146,1552},{1755, 626},
  296. { 822, 202},{1299, 663},{ 706,1732},{2656, 401},
  297. { 418, 745},{ 762,1038},{ 583,1748},{1746,1285},
  298. { 527,1169},{1314, 830},{ 556,2116},{1073,2321},
  299. { 297, 570},{ 981, 403},{ 468,1103},{1740, 243},
  300. { 725, 179},{1255, 474},{1374,1362},{1922, 912},
  301. { 285, 947},{ 930, 700},{ 593,1372},{1909, 576},
  302. { 588, 916},{1110,1116},{ 224,2719},{1633,2220},
  303. { 402, 520},{1061, 448},{ 402,1352},{1499, 775},
  304. { 664, 589},{1081, 727},{ 801,2206},{2165,1157},
  305. { 566, 802},{ 911,1116},{ 306,1703},{1792, 836},
  306. { 655, 999},{1061,1038},{ 298,2089},{1110,1753},
  307. { 361, 311},{ 970, 239},{ 265,1231},{1495, 573},
  308. { 566, 262},{1569, 293},{1341,1144},{2271, 544},
  309. { 214, 877},{ 847, 719},{ 794,1384},{2067, 274},
  310. { 703, 688},{1099,1306},{ 391,2947},{2024,1670},
  311. { 471, 525},{1245, 290},{ 264,1557},{1568, 807},
  312. { 718, 399},{1193, 685},{ 883,1594},{2729, 764},
  313. { 500, 754},{ 809,1108},{ 541,1648},{1523,1385},
  314. { 614,1196},{1209, 847},{ 345,2242},{1442,1747},
  315. { 199, 560},{1092, 194},{ 349,1253},{1653, 507},
  316. { 625, 354},{1376, 431},{1187,1465},{2164, 872},
  317. { 360, 974},{1008, 698},{ 704,1346},{2114, 452},
  318. { 720, 816},{1240,1089},{ 439,2475},{1498,2040},
  319. { 336, 718},{1213, 187},{ 451,1450},{1368, 885},
  320. { 592, 578},{1131, 531},{ 861,1855},{1764,1500},
  321. { 444, 970},{ 935, 903},{ 424,1687},{1633,1102},
  322. { 793, 897},{1060, 897},{ 185,2011},{1205,1855}};
  323. static const qcelp_vector qcelp_lspvq3[128]= {
  324. { 225, 283},{1296, 355},{ 543, 343},{2073, 274},
  325. { 204,1099},{1562, 523},{1388, 161},{2784, 274},
  326. { 112, 849},{1870, 175},{1189, 160},{1490,1088},
  327. { 969,1115},{ 659,3322},{1158,1073},{3183,1363},
  328. { 517, 223},{1740, 223},{ 704, 387},{2637, 234},
  329. { 692,1005},{1287,1610},{ 952, 532},{2393, 646},
  330. { 490, 552},{1619, 657},{ 845, 670},{1784,2280},
  331. { 191,1775},{ 272,2868},{ 942, 952},{2628,1479},
  332. { 278, 579},{1565, 218},{ 814, 180},{2379, 187},
  333. { 276,1444},{1199,1223},{1200, 349},{3009, 307},
  334. { 312, 844},{1898, 306},{ 863, 470},{1685,1241},
  335. { 513,1727},{ 711,2233},{1085, 864},{3398, 527},
  336. { 414, 440},{1356, 612},{ 964, 147},{2173, 738},
  337. { 465,1292},{ 877,1749},{1104, 689},{2105,1311},
  338. { 580, 864},{1895, 752},{ 652, 609},{1485,1699},
  339. { 514,1400},{ 386,2131},{ 933, 798},{2473, 986},
  340. { 334, 360},{1375, 398},{ 621, 276},{2183, 280},
  341. { 311,1114},{1382, 807},{1284, 175},{2605, 636},
  342. { 230, 816},{1739, 408},{1074, 176},{1619,1120},
  343. { 784,1371},{ 448,3050},{1189, 880},{3039,1165},
  344. { 424, 241},{1672, 186},{ 815, 333},{2432, 324},
  345. { 584,1029},{1137,1546},{1015, 585},{2198, 995},
  346. { 574, 581},{1746, 647},{ 733, 740},{1938,1737},
  347. { 347,1710},{ 373,2429},{ 787,1061},{2439,1438},
  348. { 185, 536},{1489, 178},{ 703, 216},{2178, 487},
  349. { 154,1421},{1414, 994},{1103, 352},{3072, 473},
  350. { 408, 819},{2055, 168},{ 998, 354},{1917,1140},
  351. { 665,1799},{ 993,2213},{1234, 631},{3003, 762},
  352. { 373, 620},{1518, 425},{ 913, 300},{1966, 836},
  353. { 402,1185},{ 948,1385},{1121, 555},{1802,1509},
  354. { 474, 886},{1888, 610},{ 739, 585},{1231,2379},
  355. { 661,1335},{ 205,2211},{ 823, 822},{2480,1179}};
  356. static const qcelp_vector qcelp_lspvq4[64]= {
  357. { 348, 311},{ 812,1145},{ 552, 461},{1826, 263},
  358. { 601, 675},{1730, 172},{1523, 193},{2449, 277},
  359. { 334, 668},{ 805,1441},{1319, 207},{1684, 910},
  360. { 582,1318},{1403,1098},{ 979, 832},{2700,1359},
  361. { 624, 228},{1292, 979},{ 800, 195},{2226, 285},
  362. { 730, 862},{1537, 601},{1115, 509},{2720, 354},
  363. { 218,1167},{1212,1538},{1074, 247},{1674,1710},
  364. { 322,2142},{1263, 777},{ 981, 556},{2119,1710},
  365. { 193, 596},{1035, 957},{ 694, 397},{1997, 253},
  366. { 743, 603},{1584, 321},{1346, 346},{2221, 708},
  367. { 451, 732},{1040,1415},{1184, 230},{1853, 919},
  368. { 310,1661},{1625, 706},{ 856, 843},{2902, 702},
  369. { 467, 348},{1108,1048},{ 859, 306},{1964, 463},
  370. { 560,1013},{1425, 533},{1142, 634},{2391, 879},
  371. { 397,1084},{1345,1700},{ 976, 248},{1887,1189},
  372. { 644,2087},{1262, 603},{ 877, 550},{2203,1307}};
  373. static const qcelp_vector qcelp_lspvq5[64]= {
  374. { 360, 222},{ 820,1097},{ 601, 319},{1656, 198},
  375. { 604, 513},{1552, 141},{1391, 155},{2474, 261},
  376. { 269, 785},{1463, 646},{1123, 191},{2015, 223},
  377. { 785, 844},{1202,1011},{ 980, 807},{3014, 793},
  378. { 570, 180},{1135,1382},{ 778, 256},{1901, 179},
  379. { 807, 622},{1461, 458},{1231, 178},{2028, 821},
  380. { 387, 927},{1496,1004},{ 888, 392},{2246, 341},
  381. { 295,1462},{1156, 694},{1022, 473},{2226,1364},
  382. { 210, 478},{1029,1020},{ 722, 181},{1730, 251},
  383. { 730, 488},{1465, 293},{1303, 326},{2595, 387},
  384. { 458, 584},{1569, 742},{1029, 173},{1910, 495},
  385. { 605,1159},{1268, 719},{ 973, 646},{2872, 428},
  386. { 443, 334},{ 835,1465},{ 912, 138},{1716, 442},
  387. { 620, 778},{1316, 450},{1186, 335},{1446,1665},
  388. { 486,1050},{1675,1019},{ 880, 278},{2214, 202},
  389. { 539,1564},{1142, 533},{ 984, 391},{2130,1089}};
  390. static const qcelp_vector * const qcelp_lspvq[5] = {
  391. qcelp_lspvq1,
  392. qcelp_lspvq2,
  393. qcelp_lspvq3,
  394. qcelp_lspvq4,
  395. qcelp_lspvq5
  396. };
  397. /**
  398. * the final gain scalefactor before clipping into a usable output float
  399. */
  400. #define QCELP_SCALE 8192.
  401. /**
  402. * the upper boundary of the clipping, depends on QCELP_SCALE
  403. */
  404. #define QCELP_CLIP_UPPER_BOUND (8191.75/8192.)
  405. /**
  406. * the lower boundary of the clipping, depends on QCELP_SCALE
  407. */
  408. #define QCELP_CLIP_LOWER_BOUND -1.
  409. /**
  410. * table for computing Ga (decoded linear codebook gain magnitude)
  411. *
  412. * @note The table could fit in int16_t in x*8 form, but it seems
  413. * to be slower on x86
  414. *
  415. * TIA/EIA/IS-733 2.4.6.2.1-3
  416. */
  417. static const float qcelp_g12ga[61] = {
  418. 1.000/QCELP_SCALE, 1.125/QCELP_SCALE, 1.250/QCELP_SCALE, 1.375/QCELP_SCALE,
  419. 1.625/QCELP_SCALE, 1.750/QCELP_SCALE, 2.000/QCELP_SCALE, 2.250/QCELP_SCALE,
  420. 2.500/QCELP_SCALE, 2.875/QCELP_SCALE, 3.125/QCELP_SCALE, 3.500/QCELP_SCALE,
  421. 4.000/QCELP_SCALE, 4.500/QCELP_SCALE, 5.000/QCELP_SCALE, 5.625/QCELP_SCALE,
  422. 6.250/QCELP_SCALE, 7.125/QCELP_SCALE, 8.000/QCELP_SCALE, 8.875/QCELP_SCALE,
  423. 10.000/QCELP_SCALE, 11.250/QCELP_SCALE, 12.625/QCELP_SCALE, 14.125/QCELP_SCALE,
  424. 15.875/QCELP_SCALE, 17.750/QCELP_SCALE, 20.000/QCELP_SCALE, 22.375/QCELP_SCALE,
  425. 25.125/QCELP_SCALE, 28.125/QCELP_SCALE, 31.625/QCELP_SCALE, 35.500/QCELP_SCALE,
  426. 39.750/QCELP_SCALE, 44.625/QCELP_SCALE, 50.125/QCELP_SCALE, 56.250/QCELP_SCALE,
  427. 63.125/QCELP_SCALE, 70.750/QCELP_SCALE, 79.375/QCELP_SCALE, 89.125/QCELP_SCALE,
  428. 100.000/QCELP_SCALE, 112.250/QCELP_SCALE, 125.875/QCELP_SCALE, 141.250/QCELP_SCALE,
  429. 158.500/QCELP_SCALE, 177.875/QCELP_SCALE, 199.500/QCELP_SCALE, 223.875/QCELP_SCALE,
  430. 251.250/QCELP_SCALE, 281.875/QCELP_SCALE, 316.250/QCELP_SCALE, 354.875/QCELP_SCALE,
  431. 398.125/QCELP_SCALE, 446.625/QCELP_SCALE, 501.125/QCELP_SCALE, 562.375/QCELP_SCALE,
  432. 631.000/QCELP_SCALE, 708.000/QCELP_SCALE, 794.375/QCELP_SCALE, 891.250/QCELP_SCALE,
  433. 1000.000/QCELP_SCALE};
  434. /**
  435. * circular codebook for rate 1 frames in x*100 form
  436. *
  437. * TIA/EIA/IS-733 2.4.6.1-2
  438. */
  439. static const int16_t qcelp_rate_full_codebook[128] = {
  440. 10, -65, -59, 12, 110, 34, -134, 157,
  441. 104, -84, -34, -115, 23, -101, 3, 45,
  442. -101, -16, -59, 28, -45, 134, -67, 22,
  443. 61, -29, 226, -26, -55, -179, 157, -51,
  444. -220, -93, -37, 60, 118, 74, -48, -95,
  445. -181, 111, 36, -52, -215, 78, -112, 39,
  446. -17, -47, -223, 19, 12, -98, -142, 130,
  447. 54, -127, 21, -12, 39, -48, 12, 128,
  448. 6, -167, 82, -102, -79, 55, -44, 48,
  449. -20, -53, 8, -61, 11, -70, -157, -168,
  450. 20, -56, -74, 78, 33, -63, -173, -2,
  451. -75, -53, -146, 77, 66, -29, 9, -75,
  452. 65, 119, -43, 76, 233, 98, 125, -156,
  453. -27, 78, -9, 170, 176, 143, -148, -7,
  454. 27, -136, 5, 27, 18, 139, 204, 7,
  455. -184, -197, 52, -3, 78, -189, 8, -65
  456. };
  457. #define QCELP_RATE_FULL_CODEBOOK_RATIO .01
  458. /**
  459. * circular codebook for rate 1/2 frames in x*2 form
  460. *
  461. * TIA/EIA/IS-733 2.4.6.1-1
  462. */
  463. static const int8_t qcelp_rate_half_codebook[128] = {
  464. 0, -4, 0, -3, 0, 0, 0, 0,
  465. 0, 0, 0, 0, 0, 0, 0, 0,
  466. 0, -3, -2, 0, 0, 0, 0, 0,
  467. 0, 0, 0, 0, 0, 0, 0, 5,
  468. 0, 0, 0, 0, 0, 0, 4, 0,
  469. 0, 3, 2, 0, 3, 4, 0, 0,
  470. 0, 0, 0, 0, 0, 0, 0, 0,
  471. 0, 0, 0, 0, 0, 3, 0, 0,
  472. -3, 3, 0, 0, -2, 0, 3, 0,
  473. 0, 0, 0, 0, 0, 0, -5, 0,
  474. 0, 0, 0, 3, 0, 0, 0, 3,
  475. 0, 0, 0, 0, 0, 0, 0, 4,
  476. 0, 0, 0, 0, 0, 0, 0, 0,
  477. 0, 3, 6, -3, -4, 0, -3, -3,
  478. 3, -3, 0, 0, 0, 0, 0, 0,
  479. 0, 0, 0, 0, 0, 0, 0, 0
  480. };
  481. #define QCELP_RATE_HALF_CODEBOOK_RATIO 0.5
  482. /**
  483. * sqrt(1.887) is the maximum of the pseudorandom
  484. * white sequence used to generate the scaled codebook
  485. * vector for bitrate 1/4.
  486. *
  487. * TIA/EIA/IS-733 2.4.8.1.2
  488. */
  489. #define QCELP_SQRT1887 1.373681186
  490. /**
  491. * table for impulse response of BPF used to filter
  492. * the white excitation for bitrate 1/4 synthesis
  493. *
  494. * Only half the tables are needed because of symmetry.
  495. *
  496. * TIA/EIA/IS-733 2.4.8.1.2-1.1
  497. */
  498. static const double qcelp_rnd_fir_coefs[11] = {
  499. -1.344519e-1, 1.735384e-2, -6.905826e-2, 2.434368e-2,
  500. -8.210701e-2, 3.041388e-2, -9.251384e-2, 3.501983e-2,
  501. -9.918777e-2, 3.749518e-2, 8.985137e-1
  502. };
  503. /**
  504. * This spread factor is used, for bitrate 1/8 and I_F_Q,
  505. * to force the LSP frequencies to be at least 80 Hz apart.
  506. *
  507. * TIA/EIA/IS-733 2.4.3.3.2
  508. */
  509. #define QCELP_LSP_SPREAD_FACTOR 0.02
  510. /**
  511. * predictor coefficient for the conversion of LSP codes
  512. * to LSP frequencies for 1/8 and I_F_Q
  513. *
  514. * TIA/EIA/IS-733 2.4.3.2.7-2
  515. */
  516. #define QCELP_LSP_OCTAVE_PREDICTOR 29.0/32
  517. #endif /* AVCODEC_QCELPDATA_H */