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