From 0dac130ccdc48f4ed6b32bf13eeb5f8564823f5c Mon Sep 17 00:00:00 2001 From: max Date: Sun, 13 Sep 2009 19:28:06 +0000 Subject: [PATCH] De-bureaucratization git-svn-id: http://op25.osmocom.org/svn/trunk@178 65a5c917-d112-43f1-993d-58c26a4786be --- decoder/src/lib/Makefile.am | 3 +- decoder/src/lib/imbe_frame.cc | 314 +++++++++++++++++++++++ decoder/src/lib/imbe_frame.h | 38 +++ decoder/src/lib/software_imbe_decoder.cc | 97 +------ decoder/src/lib/software_imbe_decoder.h | 1 - decoder/src/lib/voice_data_unit.cc | 129 +--------- 6 files changed, 360 insertions(+), 222 deletions(-) create mode 100644 decoder/src/lib/imbe_frame.cc create mode 100644 decoder/src/lib/imbe_frame.h diff --git a/decoder/src/lib/Makefile.am b/decoder/src/lib/Makefile.am index 141fb13..803c8eb 100644 --- a/decoder/src/lib/Makefile.am +++ b/decoder/src/lib/Makefile.am @@ -83,7 +83,8 @@ _op25_la_SOURCES = \ vc55_imbe_decoder.cc \ value_string.cc \ golay.cc \ - hamming.cc + hamming.cc \ + imbe_frame.cc # magic flags _op25_la_LDFLAGS = $(NO_UNDEFINED) -module -avoid-version diff --git a/decoder/src/lib/imbe_frame.cc b/decoder/src/lib/imbe_frame.cc new file mode 100644 index 0000000..62de1fd --- /dev/null +++ b/decoder/src/lib/imbe_frame.cc @@ -0,0 +1,314 @@ +/* -*- C++ -*- */ + +/* + * Copyright 2008-2009 Steve Glass + * + * This file is part of OP25. + * + * OP25 is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or(at your option) + * any later version. + * + * OP25 is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + * License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OP25; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Boston, MA + * 02110-1301, USA. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void +imbe_header_decode(const voice_codeword& cw, uint32_t& u0, uint32_t& u1, uint32_t& u2, uint32_t& u3, uint32_t& u4, uint32_t& u5, uint32_t& u6, uint32_t& u7, uint32_t& E0, uint32_t& ET) +{ + ET = 0; + + size_t errs = 0; + uint32_t v0 = extract(cw, 0, 23); + errs = golay_23_decode(v0); + u0 = v0; + E0 = ET; + + uint32_t pn = u0 << 4; + uint32_t m1 = pngen23(pn); + uint32_t v1 = extract(cw, 23, 46) ^ m1; + errs += golay_23_decode(v1); + u1 = v1; + + uint32_t m2 = pngen23(pn); + uint32_t v2 = extract(cw, 46, 69) ^ m2; + errs += golay_23_decode(v2); + u2 = v2; + + uint32_t m3 = pngen23(pn); + uint32_t v3 = extract(cw, 69, 92) ^ m3; + errs += golay_23_decode(v3); + u3 = v3; + + uint32_t m4 = pngen15(pn); + uint16_t v4 = extract(cw, 92, 107) ^ m4; + errs += hamming_15_decode(v4); + u4 = v4; + + uint32_t m5 = pngen15(pn); + uint16_t v5 = extract(cw, 107, 122) ^ m5; + errs += hamming_15_decode(v5); + u5 = v5; + + uint32_t m6 = pngen15(pn); + uint16_t v6 = extract(cw, 122, 137) ^ m6; + errs += hamming_15_decode(v6); + u6 = v6; + + u7 = extract(cw, 137, 144); + u7 <<= 1; /* so that bit0 is free (see note about BOT bit */ +} + +static inline void store_bits(voice_codeword& cw, int s, int l, uint32_t v) +{ + for (int i = l-1; i >= s; i--) { + cw[i] = v & 1; + v >>= 1; + } +} + +void +imbe_header_encode(voice_codeword& cw, uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3, uint32_t u4, uint32_t u5, uint32_t u6, uint32_t u7) +{ + // given input 88-bit IMBE frame (in u0-u7), + // add golay / hamming bits to produce a 144-bit frame. + uint32_t c0, c1, c2, c3, c4, c5, c6, c7; + + uint32_t pn = u0 << 4; + + c0 = golay_23_encode(u0); + store_bits(cw, 0, 23, c0); + + uint32_t m1 = pngen23(pn); + c1 = golay_23_encode(u1) ^ m1; + store_bits(cw, 23, 46, c1); + + uint32_t m2 = pngen23(pn); + c2 = golay_23_encode(u2) ^ m2; + store_bits(cw, 46, 69, c2); + + uint32_t m3 = pngen23(pn); + c3 = golay_23_encode(u3) ^ m3; + store_bits(cw, 69, 92, c3); + + uint32_t m4 = pngen15(pn); + c4 = hamming_15_encode(u4) ^ m4; + store_bits(cw, 92, 107, c4); + + uint32_t m5 = pngen15(pn); + c5 = hamming_15_encode(u5) ^ m5; + store_bits(cw, 107, 122, c5); + + uint32_t m6 = pngen15(pn); + c6 = hamming_15_encode(u6) ^ m6; + store_bits(cw, 122, 137, c6); + + c7 = u7; + store_bits(cw, 137, 144, c7 >> 1); +} + +static const size_t voice_codeword_bits[nof_voice_codewords][voice_codeword_sz] = { + + { 114, 121, 126, 133, 138, 147, 152, 159, 164, 171, 176, 183, + 188, 195, 200, 207, 212, 221, 226, 233, 238, 245, 250, 257, + 115, 120, 127, 132, 139, 146, 153, 158, 165, 170, 177, 182, + 189, 194, 201, 206, 213, 220, 227, 232, 239, 244, 251, 256, + 116, 123, 128, 135, 140, 149, 154, 161, 166, 173, 178, 185, + 190, 197, 202, 209, 216, 223, 228, 235, 240, 247, 252, 259, + 117, 122, 129, 134, 141, 148, 155, 160, 167, 172, 179, 184, + 191, 196, 203, 208, 217, 222, 229, 234, 241, 246, 253, 258, + 118, 125, 130, 137, 144, 151, 156, 163, 168, 175, 180, 187, + 192, 199, 204, 211, 218, 225, 230, 237, 242, 249, 254, 261, + 119, 124, 131, 136, 145, 150, 157, 162, 169, 174, 181, 186, + 193, 198, 205, 210, 219, 224, 231, 236, 243, 248, 255, 260 }, + + { 262, 269, 274, 281, 288, 295, 300, 307, 312, 319, 324, 331, + 336, 343, 348, 355, 362, 369, 374, 381, 386, 393, 398, 405, + 263, 268, 275, 280, 289, 294, 301, 306, 313, 318, 325, 330, + 337, 342, 349, 354, 363, 368, 375, 380, 387, 392, 399, 404, + 264, 271, 276, 283, 290, 297, 302, 309, 314, 321, 326, 333, + 338, 345, 350, 357, 364, 371, 376, 383, 388, 395, 400, 407, + 265, 270, 277, 282, 291, 296, 303, 308, 315, 320, 327, 332, + 339, 344, 351, 356, 365, 370, 377, 382, 389, 394, 401, 406, + 266, 273, 278, 285, 292, 299, 304, 311, 316, 323, 328, 335, + 340, 347, 352, 361, 366, 373, 378, 385, 390, 397, 402, 409, + 267, 272, 279, 284, 293, 298, 305, 310, 317, 322, 329, 334, + 341, 346, 353, 360, 367, 372, 379, 384, 391, 396, 403, 408 }, + + { 452, 459, 464, 471, 476, 483, 488, 495, 500, 509, 514, 521, + 526, 533, 538, 545, 550, 557, 562, 569, 576, 583, 588, 595, + 453, 458, 465, 470, 477, 482, 489, 494, 501, 508, 515, 520, + 527, 532, 539, 544, 551, 556, 563, 568, 577, 582, 589, 594, + 454, 461, 466, 473, 478, 485, 490, 497, 504, 511, 516, 523, + 528, 535, 540, 547, 552, 559, 564, 571, 578, 585, 590, 597, + 455, 460, 467, 472, 479, 484, 491, 496, 505, 510, 517, 522, + 529, 534, 541, 546, 553, 558, 565, 570, 579, 584, 591, 596, + 456, 463, 468, 475, 480, 487, 492, 499, 506, 513, 518, 525, + 530, 537, 542, 549, 554, 561, 566, 573, 580, 587, 592, 599, + 457, 462, 469, 474, 481, 486, 493, 498, 507, 512, 519, 524, + 531, 536, 543, 548, 555, 560, 567, 572, 581, 586, 593, 598 }, + + { 640, 649, 654, 661, 666, 673, 678, 685, 690, 697, 702, 709, + 714, 723, 728, 735, 740, 747, 752, 759, 764, 771, 776, 783, + 641, 648, 655, 660, 667, 672, 679, 684, 691, 696, 703, 708, + 715, 722, 729, 734, 741, 746, 753, 758, 765, 770, 777, 782, + 642, 651, 656, 663, 668, 675, 680, 687, 692, 699, 704, 711, + 716, 725, 730, 737, 742, 749, 754, 761, 766, 773, 778, 785, + 643, 650, 657, 662, 669, 674, 681, 686, 693, 698, 705, 710, + 717, 724, 731, 736, 743, 748, 755, 760, 767, 772, 779, 784, + 644, 653, 658, 665, 670, 677, 682, 689, 694, 701, 706, 713, + 720, 727, 732, 739, 744, 751, 756, 763, 768, 775, 780, 787, + 645, 652, 659, 664, 671, 676, 683, 688, 695, 700, 707, 712, + 721, 726, 733, 738, 745, 750, 757, 762, 769, 774, 781, 786 }, + + { 830, 837, 842, 849, 854, 861, 868, 875, 880, 887, 892, 899, + 904, 911, 916, 923, 928, 937, 942, 949, 954, 961, 966, 973, + 831, 836, 843, 848, 855, 860, 869, 874, 881, 886, 893, 898, + 905, 910, 917, 922, 929, 936, 943, 948, 955, 960, 967, 972, + 832, 839, 844, 851, 856, 865, 870, 877, 882, 889, 894, 901, + 906, 913, 918, 925, 930, 939, 944, 951, 956, 963, 968, 975, + 833, 838, 845, 850, 857, 864, 871, 876, 883, 888, 895, 900, + 907, 912, 919, 924, 931, 938, 945, 950, 957, 962, 969, 974, + 834, 841, 846, 853, 858, 867, 872, 879, 884, 891, 896, 903, + 908, 915, 920, 927, 932, 941, 946, 953, 958, 965, 970, 977, + 835, 840, 847, 852, 859, 866, 873, 878, 885, 890, 897, 902, + 909, 914, 921, 926, 933, 940, 947, 952, 959, 964, 971, 976 }, + + { 1020, 1027, 1032, 1039, 1044, 1051, 1056, 1063, 1068, 1075, 1082, 1089, + 1094, 1101, 1106, 1113, 1118, 1125, 1130, 1137, 1142, 1149, 1156, 1163, + 1021, 1026, 1033, 1038, 1045, 1050, 1057, 1062, 1069, 1074, 1083, 1088, + 1095, 1100, 1107, 1112, 1119, 1124, 1131, 1136, 1143, 1148, 1157, 1162, + 1022, 1029, 1034, 1041, 1046, 1053, 1058, 1065, 1070, 1077, 1084, 1091, + 1096, 1103, 1108, 1115, 1120, 1127, 1132, 1139, 1144, 1153, 1158, 1165, + 1023, 1028, 1035, 1040, 1047, 1052, 1059, 1064, 1071, 1076, 1085, 1090, + 1097, 1102, 1109, 1114, 1121, 1126, 1133, 1138, 1145, 1152, 1159, 1164, + 1024, 1031, 1036, 1043, 1048, 1055, 1060, 1067, 1072, 1081, 1086, 1093, + 1098, 1105, 1110, 1117, 1122, 1129, 1134, 1141, 1146, 1155, 1160, 1167, + 1025, 1030, 1037, 1042, 1049, 1054, 1061, 1066, 1073, 1080, 1087, 1092, + 1099, 1104, 1111, 1116, 1123, 1128, 1135, 1140, 1147, 1154, 1161, 1166 }, + + { 1208, 1215, 1220, 1229, 1234, 1241, 1246, 1253, 1258, 1265, 1270, 1277, + 1282, 1289, 1296, 1303, 1308, 1315, 1320, 1327, 1332, 1339, 1344, 1351, + 1209, 1214, 1221, 1228, 1235, 1240, 1247, 1252, 1259, 1264, 1271, 1276, + 1283, 1288, 1297, 1302, 1309, 1314, 1321, 1326, 1333, 1338, 1345, 1350, + 1210, 1217, 1224, 1231, 1236, 1243, 1248, 1255, 1260, 1267, 1272, 1279, + 1284, 1291, 1298, 1305, 1310, 1317, 1322, 1329, 1334, 1341, 1346, 1353, + 1211, 1216, 1225, 1230, 1237, 1242, 1249, 1254, 1261, 1266, 1273, 1278, + 1285, 1290, 1299, 1304, 1311, 1316, 1323, 1328, 1335, 1340, 1347, 1352, + 1212, 1219, 1226, 1233, 1238, 1245, 1250, 1257, 1262, 1269, 1274, 1281, + 1286, 1293, 1300, 1307, 1312, 1319, 1324, 1331, 1336, 1343, 1348, 1355, + 1213, 1218, 1227, 1232, 1239, 1244, 1251, 1256, 1263, 1268, 1275, 1280, + 1287, 1292, 1301, 1306, 1313, 1318, 1325, 1330, 1337, 1342, 1349, 1354 }, + + { 1398, 1405, 1410, 1417, 1422, 1429, 1434, 1443, 1448, 1455, 1460, 1467, + 1472, 1479, 1484, 1491, 1496, 1503, 1508, 1517, 1522, 1529, 1534, 1541, + 1399, 1404, 1411, 1416, 1423, 1428, 1435, 1442, 1449, 1454, 1461, 1466, + 1473, 1478, 1485, 1490, 1497, 1502, 1509, 1516, 1523, 1528, 1535, 1540, + 1400, 1407, 1412, 1419, 1424, 1431, 1436, 1445, 1450, 1457, 1462, 1469, + 1474, 1481, 1486, 1493, 1498, 1505, 1512, 1519, 1524, 1531, 1536, 1543, + 1401, 1406, 1413, 1418, 1425, 1430, 1437, 1444, 1451, 1456, 1463, 1468, + 1475, 1480, 1487, 1492, 1499, 1504, 1513, 1518, 1525, 1530, 1537, 1542, + 1402, 1409, 1414, 1421, 1426, 1433, 1440, 1447, 1452, 1459, 1464, 1471, + 1476, 1483, 1488, 1495, 1500, 1507, 1514, 1521, 1526, 1533, 1538, 1545, + 1403, 1408, 1415, 1420, 1427, 1432, 1441, 1446, 1453, 1458, 1465, 1470, + 1477, 1482, 1489, 1494, 1501, 1506, 1515, 1520, 1527, 1532, 1539, 1544 }, + + { 1578, 1587, 1592, 1599, 1604, 1611, 1616, 1623, 1628, 1635, 1640, 1647, + 1652, 1661, 1666, 1673, 1678, 1685, 1690, 1697, 1702, 1709, 1714, 1721, + 1579, 1586, 1593, 1598, 1605, 1610, 1617, 1622, 1629, 1634, 1641, 1646, + 1653, 1660, 1667, 1672, 1679, 1684, 1691, 1696, 1703, 1708, 1715, 1720, + 1580, 1589, 1594, 1601, 1606, 1613, 1618, 1625, 1630, 1637, 1642, 1649, + 1656, 1663, 1668, 1675, 1680, 1687, 1692, 1699, 1704, 1711, 1716, 1723, + 1581, 1588, 1595, 1600, 1607, 1612, 1619, 1624, 1631, 1636, 1643, 1648, + 1657, 1662, 1669, 1674, 1681, 1686, 1693, 1698, 1705, 1710, 1717, 1722, + 1584, 1591, 1596, 1603, 1608, 1615, 1620, 1627, 1632, 1639, 1644, 1651, + 1658, 1665, 1670, 1677, 1682, 1689, 1694, 1701, 1706, 1713, 1718, 1725, + 1585, 1590, 1597, 1602, 1609, 1614, 1621, 1626, 1633, 1638, 1645, 1650, + 1659, 1664, 1671, 1676, 1683, 1688, 1695, 1700, 1707, 1712, 1719, 1724 }, + + }; + +void +imbe_deinterleave (const_bit_vector& frame_body, voice_codeword& cw, uint32_t frame_nr) +{ + for(size_t j = 0; j < voice_codeword_sz; ++j) { + cw[j] = frame_body[voice_codeword_bits[frame_nr][j]]; + } +} + +void +imbe_interleave(bit_vector& frame_body, const voice_codeword& cw, uint32_t frame_nr) +{ + for(size_t j = 0; j < voice_codeword_sz; ++j) { + frame_body[voice_codeword_bits[frame_nr][j]] = cw[j]; + } +} + +uint32_t +pngen15(uint32_t& Pr) +{ + int n = 0; + for(int i = 14; i >= 0; --i) { + Pr = (173 * Pr + 13849) & 0xffffu; + if(Pr & 32768) { + n += (1 << i); + } + } + return n; +} + +uint32_t +pngen23(uint32_t& Pr) +{ + int n = 0; + for(int i = 22; i >= 0; --i) { + Pr = (173 * Pr + 13849) & 0xffffu; + if(Pr & 32768) { + n += (1 << i); + } + } + return n; +} + +void +imbe_frame_unpack(uint8_t *A, uint32_t& u0, uint32_t& u1, uint32_t& u2, uint32_t& u3, uint32_t& u4, uint32_t& u5, uint32_t& u6, uint32_t& u7, uint32_t& E0, uint32_t& ET) +{ + E0 = A[0]; + ET = A[1]; + u0 = A[4] + (E0 & 240) * 16; + u1 = A[5] + (E0 & 15) * 256; + u2 = A[6] + (ET & 240) * 16; + u3 = A[7] + (ET & 15) * 256; + E0 = A[2]; + ET = A[3]; + u4 = A[8] + (E0 & 224) * 8; + u5 = A[9] + (E0 & 28) * 64; + u6 = A[10] + (ET & 128) * 2 + (E0 & 3) * 512; + u7 = ET & 127; + E0 = A[11]; + if(E0 & 192) exit(4); + ET = E0 & 3; + E0 = (E0 & 84) / 4; +} diff --git a/decoder/src/lib/imbe_frame.h b/decoder/src/lib/imbe_frame.h new file mode 100644 index 0000000..6e05c70 --- /dev/null +++ b/decoder/src/lib/imbe_frame.h @@ -0,0 +1,38 @@ +#ifndef INCLUDED_IMBE_HEADER_H +#define INCLUDED_IMBE_HEADER_H + +#include +#include +#include + +static const size_t nof_voice_codewords = 9, voice_codeword_sz = 144; + +/* APCO IMBE header decoder. + * + * extracts 88 bits of IMBE parameters given an input 144-bit frame + * + * \param cw Codeword containing bits to be decoded + * \param u0-u7 Result output vectors + */ + +extern void imbe_header_decode(const voice_codeword& cw, uint32_t& u0, uint32_t& u1, uint32_t& u2, uint32_t& u3, uint32_t& u4, uint32_t& u5, uint32_t& u6, uint32_t& u7, uint32_t& E0, uint32_t& ET); + +/* APCO IMBE header encoder. + * + * given 88 bits of IMBE parameters, construct output 144-bit IMBE codeword + * + * \param cw Codeword into which 144 bits of results are placed + * \param u0-u7 input parameters + */ + +extern void imbe_header_encode(voice_codeword& cw, uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3, uint32_t u4, uint32_t u5, uint32_t u6, uint32_t u7); + +extern void imbe_deinterleave (const_bit_vector& frame_body, voice_codeword& cw, uint32_t frame_nr); +extern void imbe_interleave(bit_vector& frame_body, const voice_codeword& cw, uint32_t frame_nr); + +uint32_t pngen15(uint32_t& pn); +uint32_t pngen23(uint32_t& pn); + +void imbe_frame_unpack(uint8_t *A, uint32_t& u0, uint32_t& u1, uint32_t& u2, uint32_t& u3, uint32_t& u4, uint32_t& u5, uint32_t& u6, uint32_t& u7, uint32_t& E0, uint32_t& ET); + +#endif /* INCLUDED_IMBE_HEADER_H */ diff --git a/decoder/src/lib/software_imbe_decoder.cc b/decoder/src/lib/software_imbe_decoder.cc index c42d48a..2a6f1cd 100644 --- a/decoder/src/lib/software_imbe_decoder.cc +++ b/decoder/src/lib/software_imbe_decoder.cc @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -788,7 +789,7 @@ software_imbe_decoder::decode(const voice_codeword& cw) unsigned char O[12]; // PN/Hamming/Golay - etc. - correct(cw, u0, u1, u2, u3, u4, u5, u6, u7, E0, ET) ; + imbe_header_decode(cw, u0, u1, u2, u3, u4, u5, u6, u7, E0, ET) ; //replace the sync bit(LSB of u7) with the BOT flag u7 = u7 | 0x01; //ECC procedure called above always returns u7 LSB = 0 @@ -892,7 +893,7 @@ software_imbe_decoder::decode_audio(uint8_t *A) int en, tmp_f; float SE = 0, ER = 0; - unpack(A, u0, u1, u2, u3, u4, u5, u6, u7, E0, ET); + imbe_frame_unpack(A, u0, u1, u2, u3, u4, u5, u6, u7, E0, ET); ER = .95 * ER + .000365 * ET; if( ER > .0875) { @@ -1430,95 +1431,3 @@ software_imbe_decoder::synth_voiced() } } -void -software_imbe_decoder::unpack(uint8_t *A, uint32_t& u0, uint32_t& u1, uint32_t& u2, uint32_t& u3, uint32_t& u4, uint32_t& u5, uint32_t& u6, uint32_t& u7, uint32_t& E0, uint32_t& ET) -{ - E0 = A[0]; - ET = A[1]; - u0 = A[4] + (E0 & 240) * 16; - u1 = A[5] + (E0 & 15) * 256; - u2 = A[6] + (ET & 240) * 16; - u3 = A[7] + (ET & 15) * 256; - E0 = A[2]; - ET = A[3]; - u4 = A[8] + (E0 & 224) * 8; - u5 = A[9] + (E0 & 28) * 64; - u6 = A[10] + (ET & 128) * 2 + (E0 & 3) * 512; - u7 = ET & 127; - E0 = A[11]; - if(E0 & 192) exit(4); - ET = E0 & 3; - E0 = (E0 & 84) / 4; -} - -uint32_t -software_imbe_decoder::pngen15(uint32_t& Pr) -{ - int n = 0; - for(int i = 14; i >= 0; --i) { - Pr = (173 * Pr + 13849) & 0xffffu; - if(Pr & 32768) { - n += (1 << i); - } - } - return n; -} - -uint32_t -software_imbe_decoder::pngen23(uint32_t& Pr) -{ - int n = 0; - for(int i = 22; i >= 0; --i) { - Pr = (173 * Pr + 13849) & 0xffffu; - if(Pr & 32768) { - n += (1 << i); - } - } - return n; -} - -void -software_imbe_decoder::correct(const voice_codeword& cw, uint32_t& u0, uint32_t& u1, uint32_t& u2, uint32_t& u3, uint32_t& u4, uint32_t& u5, uint32_t& u6, uint32_t& u7, uint32_t& E0, uint32_t& ET) -{ - ET = 0; - - size_t errs = 0; - uint32_t v0 = extract(cw, 0, 23); - errs = golay_23_decode(v0); - u0 = v0; - E0 = ET; - - uint32_t pn = u0 << 4; - uint32_t m1 = pngen23(pn); - uint32_t v1 = extract(cw, 23, 46) ^ m1; - errs += golay_23_decode(v1); - u1 = v1; - - uint32_t m2 = pngen23(pn); - uint32_t v2 = extract(cw, 46, 69) ^ m2; - errs += golay_23_decode(v2); - u2 = v2; - - uint32_t m3 = pngen23(pn); - uint32_t v3 = extract(cw, 69, 92) ^ m3; - errs += golay_23_decode(v3); - u3 = v3; - - uint32_t m4 = pngen15(pn); - uint16_t v4 = extract(cw, 92, 107) ^ m4; - errs += hamming_15_decode(v4); - u4 = v4; - - uint32_t m5 = pngen15(pn); - uint16_t v5 = extract(cw, 107, 122) ^ m5; - errs += hamming_15_decode(v5); - u5 = v5; - - uint32_t m6 = pngen15(pn); - uint16_t v6 = extract(cw, 122, 137) ^ m6; - errs += hamming_15_decode(v6); - u6 = v6; - - u7 = extract(cw, 137, 144); - u7 <<= 1; /* so that bit0 is free (see note about BOT bit */ -} diff --git a/decoder/src/lib/software_imbe_decoder.h b/decoder/src/lib/software_imbe_decoder.h index 90334b0..53d4be0 100644 --- a/decoder/src/lib/software_imbe_decoder.h +++ b/decoder/src/lib/software_imbe_decoder.h @@ -86,7 +86,6 @@ private: uint32_t pngen15(uint32_t& pn); uint32_t pngen23(uint32_t& pn); - void correct(const voice_codeword& cw, uint32_t& u0, uint32_t& u1, uint32_t& u2, uint32_t& u3, uint32_t& u4, uint32_t& u5, uint32_t& u6, uint32_t& u7, uint32_t& E0, uint32_t& ET); void decode_audio(uint8_t *); void decode_spectral_amplitudes(int, int ); void decode_vuv(int ); diff --git a/decoder/src/lib/voice_data_unit.cc b/decoder/src/lib/voice_data_unit.cc index 7af6f12..b19f291 100644 --- a/decoder/src/lib/voice_data_unit.cc +++ b/decoder/src/lib/voice_data_unit.cc @@ -23,6 +23,7 @@ #include #include +#include using namespace std; @@ -43,133 +44,9 @@ voice_data_unit::do_correct_errors(bit_vector& frame_body) void voice_data_unit::do_decode_audio(const_bit_vector& frame_body, imbe_decoder& imbe) { - static const size_t nof_voice_codewords = 9, voice_codeword_sz = 144; - static const size_t voice_codeword_bits[nof_voice_codewords][voice_codeword_sz] = { - - { 114, 121, 126, 133, 138, 147, 152, 159, 164, 171, 176, 183, - 188, 195, 200, 207, 212, 221, 226, 233, 238, 245, 250, 257, - 115, 120, 127, 132, 139, 146, 153, 158, 165, 170, 177, 182, - 189, 194, 201, 206, 213, 220, 227, 232, 239, 244, 251, 256, - 116, 123, 128, 135, 140, 149, 154, 161, 166, 173, 178, 185, - 190, 197, 202, 209, 216, 223, 228, 235, 240, 247, 252, 259, - 117, 122, 129, 134, 141, 148, 155, 160, 167, 172, 179, 184, - 191, 196, 203, 208, 217, 222, 229, 234, 241, 246, 253, 258, - 118, 125, 130, 137, 144, 151, 156, 163, 168, 175, 180, 187, - 192, 199, 204, 211, 218, 225, 230, 237, 242, 249, 254, 261, - 119, 124, 131, 136, 145, 150, 157, 162, 169, 174, 181, 186, - 193, 198, 205, 210, 219, 224, 231, 236, 243, 248, 255, 260 }, - - { 262, 269, 274, 281, 288, 295, 300, 307, 312, 319, 324, 331, - 336, 343, 348, 355, 362, 369, 374, 381, 386, 393, 398, 405, - 263, 268, 275, 280, 289, 294, 301, 306, 313, 318, 325, 330, - 337, 342, 349, 354, 363, 368, 375, 380, 387, 392, 399, 404, - 264, 271, 276, 283, 290, 297, 302, 309, 314, 321, 326, 333, - 338, 345, 350, 357, 364, 371, 376, 383, 388, 395, 400, 407, - 265, 270, 277, 282, 291, 296, 303, 308, 315, 320, 327, 332, - 339, 344, 351, 356, 365, 370, 377, 382, 389, 394, 401, 406, - 266, 273, 278, 285, 292, 299, 304, 311, 316, 323, 328, 335, - 340, 347, 352, 361, 366, 373, 378, 385, 390, 397, 402, 409, - 267, 272, 279, 284, 293, 298, 305, 310, 317, 322, 329, 334, - 341, 346, 353, 360, 367, 372, 379, 384, 391, 396, 403, 408 }, - - { 452, 459, 464, 471, 476, 483, 488, 495, 500, 509, 514, 521, - 526, 533, 538, 545, 550, 557, 562, 569, 576, 583, 588, 595, - 453, 458, 465, 470, 477, 482, 489, 494, 501, 508, 515, 520, - 527, 532, 539, 544, 551, 556, 563, 568, 577, 582, 589, 594, - 454, 461, 466, 473, 478, 485, 490, 497, 504, 511, 516, 523, - 528, 535, 540, 547, 552, 559, 564, 571, 578, 585, 590, 597, - 455, 460, 467, 472, 479, 484, 491, 496, 505, 510, 517, 522, - 529, 534, 541, 546, 553, 558, 565, 570, 579, 584, 591, 596, - 456, 463, 468, 475, 480, 487, 492, 499, 506, 513, 518, 525, - 530, 537, 542, 549, 554, 561, 566, 573, 580, 587, 592, 599, - 457, 462, 469, 474, 481, 486, 493, 498, 507, 512, 519, 524, - 531, 536, 543, 548, 555, 560, 567, 572, 581, 586, 593, 598 }, - - { 640, 649, 654, 661, 666, 673, 678, 685, 690, 697, 702, 709, - 714, 723, 728, 735, 740, 747, 752, 759, 764, 771, 776, 783, - 641, 648, 655, 660, 667, 672, 679, 684, 691, 696, 703, 708, - 715, 722, 729, 734, 741, 746, 753, 758, 765, 770, 777, 782, - 642, 651, 656, 663, 668, 675, 680, 687, 692, 699, 704, 711, - 716, 725, 730, 737, 742, 749, 754, 761, 766, 773, 778, 785, - 643, 650, 657, 662, 669, 674, 681, 686, 693, 698, 705, 710, - 717, 724, 731, 736, 743, 748, 755, 760, 767, 772, 779, 784, - 644, 653, 658, 665, 670, 677, 682, 689, 694, 701, 706, 713, - 720, 727, 732, 739, 744, 751, 756, 763, 768, 775, 780, 787, - 645, 652, 659, 664, 671, 676, 683, 688, 695, 700, 707, 712, - 721, 726, 733, 738, 745, 750, 757, 762, 769, 774, 781, 786 }, - - { 830, 837, 842, 849, 854, 861, 868, 875, 880, 887, 892, 899, - 904, 911, 916, 923, 928, 937, 942, 949, 954, 961, 966, 973, - 831, 836, 843, 848, 855, 860, 869, 874, 881, 886, 893, 898, - 905, 910, 917, 922, 929, 936, 943, 948, 955, 960, 967, 972, - 832, 839, 844, 851, 856, 865, 870, 877, 882, 889, 894, 901, - 906, 913, 918, 925, 930, 939, 944, 951, 956, 963, 968, 975, - 833, 838, 845, 850, 857, 864, 871, 876, 883, 888, 895, 900, - 907, 912, 919, 924, 931, 938, 945, 950, 957, 962, 969, 974, - 834, 841, 846, 853, 858, 867, 872, 879, 884, 891, 896, 903, - 908, 915, 920, 927, 932, 941, 946, 953, 958, 965, 970, 977, - 835, 840, 847, 852, 859, 866, 873, 878, 885, 890, 897, 902, - 909, 914, 921, 926, 933, 940, 947, 952, 959, 964, 971, 976 }, - - { 1020, 1027, 1032, 1039, 1044, 1051, 1056, 1063, 1068, 1075, 1082, 1089, - 1094, 1101, 1106, 1113, 1118, 1125, 1130, 1137, 1142, 1149, 1156, 1163, - 1021, 1026, 1033, 1038, 1045, 1050, 1057, 1062, 1069, 1074, 1083, 1088, - 1095, 1100, 1107, 1112, 1119, 1124, 1131, 1136, 1143, 1148, 1157, 1162, - 1022, 1029, 1034, 1041, 1046, 1053, 1058, 1065, 1070, 1077, 1084, 1091, - 1096, 1103, 1108, 1115, 1120, 1127, 1132, 1139, 1144, 1153, 1158, 1165, - 1023, 1028, 1035, 1040, 1047, 1052, 1059, 1064, 1071, 1076, 1085, 1090, - 1097, 1102, 1109, 1114, 1121, 1126, 1133, 1138, 1145, 1152, 1159, 1164, - 1024, 1031, 1036, 1043, 1048, 1055, 1060, 1067, 1072, 1081, 1086, 1093, - 1098, 1105, 1110, 1117, 1122, 1129, 1134, 1141, 1146, 1155, 1160, 1167, - 1025, 1030, 1037, 1042, 1049, 1054, 1061, 1066, 1073, 1080, 1087, 1092, - 1099, 1104, 1111, 1116, 1123, 1128, 1135, 1140, 1147, 1154, 1161, 1166 }, - - { 1208, 1215, 1220, 1229, 1234, 1241, 1246, 1253, 1258, 1265, 1270, 1277, - 1282, 1289, 1296, 1303, 1308, 1315, 1320, 1327, 1332, 1339, 1344, 1351, - 1209, 1214, 1221, 1228, 1235, 1240, 1247, 1252, 1259, 1264, 1271, 1276, - 1283, 1288, 1297, 1302, 1309, 1314, 1321, 1326, 1333, 1338, 1345, 1350, - 1210, 1217, 1224, 1231, 1236, 1243, 1248, 1255, 1260, 1267, 1272, 1279, - 1284, 1291, 1298, 1305, 1310, 1317, 1322, 1329, 1334, 1341, 1346, 1353, - 1211, 1216, 1225, 1230, 1237, 1242, 1249, 1254, 1261, 1266, 1273, 1278, - 1285, 1290, 1299, 1304, 1311, 1316, 1323, 1328, 1335, 1340, 1347, 1352, - 1212, 1219, 1226, 1233, 1238, 1245, 1250, 1257, 1262, 1269, 1274, 1281, - 1286, 1293, 1300, 1307, 1312, 1319, 1324, 1331, 1336, 1343, 1348, 1355, - 1213, 1218, 1227, 1232, 1239, 1244, 1251, 1256, 1263, 1268, 1275, 1280, - 1287, 1292, 1301, 1306, 1313, 1318, 1325, 1330, 1337, 1342, 1349, 1354 }, - - { 1398, 1405, 1410, 1417, 1422, 1429, 1434, 1443, 1448, 1455, 1460, 1467, - 1472, 1479, 1484, 1491, 1496, 1503, 1508, 1517, 1522, 1529, 1534, 1541, - 1399, 1404, 1411, 1416, 1423, 1428, 1435, 1442, 1449, 1454, 1461, 1466, - 1473, 1478, 1485, 1490, 1497, 1502, 1509, 1516, 1523, 1528, 1535, 1540, - 1400, 1407, 1412, 1419, 1424, 1431, 1436, 1445, 1450, 1457, 1462, 1469, - 1474, 1481, 1486, 1493, 1498, 1505, 1512, 1519, 1524, 1531, 1536, 1543, - 1401, 1406, 1413, 1418, 1425, 1430, 1437, 1444, 1451, 1456, 1463, 1468, - 1475, 1480, 1487, 1492, 1499, 1504, 1513, 1518, 1525, 1530, 1537, 1542, - 1402, 1409, 1414, 1421, 1426, 1433, 1440, 1447, 1452, 1459, 1464, 1471, - 1476, 1483, 1488, 1495, 1500, 1507, 1514, 1521, 1526, 1533, 1538, 1545, - 1403, 1408, 1415, 1420, 1427, 1432, 1441, 1446, 1453, 1458, 1465, 1470, - 1477, 1482, 1489, 1494, 1501, 1506, 1515, 1520, 1527, 1532, 1539, 1544 }, - - { 1578, 1587, 1592, 1599, 1604, 1611, 1616, 1623, 1628, 1635, 1640, 1647, - 1652, 1661, 1666, 1673, 1678, 1685, 1690, 1697, 1702, 1709, 1714, 1721, - 1579, 1586, 1593, 1598, 1605, 1610, 1617, 1622, 1629, 1634, 1641, 1646, - 1653, 1660, 1667, 1672, 1679, 1684, 1691, 1696, 1703, 1708, 1715, 1720, - 1580, 1589, 1594, 1601, 1606, 1613, 1618, 1625, 1630, 1637, 1642, 1649, - 1656, 1663, 1668, 1675, 1680, 1687, 1692, 1699, 1704, 1711, 1716, 1723, - 1581, 1588, 1595, 1600, 1607, 1612, 1619, 1624, 1631, 1636, 1643, 1648, - 1657, 1662, 1669, 1674, 1681, 1686, 1693, 1698, 1705, 1710, 1717, 1722, - 1584, 1591, 1596, 1603, 1608, 1615, 1620, 1627, 1632, 1639, 1644, 1651, - 1658, 1665, 1670, 1677, 1682, 1689, 1694, 1701, 1706, 1713, 1718, 1725, - 1585, 1590, 1597, 1602, 1609, 1614, 1621, 1626, 1633, 1638, 1645, 1650, - 1659, 1664, 1671, 1676, 1683, 1688, 1695, 1700, 1707, 1712, 1719, 1724 }, - - }; - + voice_codeword cw(voice_codeword_sz); for(size_t i = 0; i < nof_voice_codewords; ++i) { - voice_codeword cw(voice_codeword_sz); - for(size_t j = 0; j < voice_codeword_sz; ++j) { - cw[j] = frame_body[voice_codeword_bits[i][j]]; - } + imbe_deinterleave(frame_body, cw, i); imbe.decode(cw); } }