shithub: mp3dec

Download patch

ref: 5f0132665740984a728a32d80bef8866578d1d2b
parent: f828186cec93b2f4ddcd18bc22ab1dcb1b6f3f1f
author: lieff <lieff@users.noreply.github.com>
date: Fri May 11 09:11:14 EDT 2018

Huffopt: do not print last comma in table, no manual edit needed

--- a/huffopt/huffopt.c
+++ b/huffopt/huffopt.c
@@ -202,7 +202,7 @@
     }
 }
 
-void huff_print_one(const huff_t *h, FILE *f, int parent_level)
+void huff_print_one(const huff_t *h, FILE *f, int parent_level, int last)
 {
     if (h->symbol_kind == E_PAIR)
     {
@@ -210,22 +210,21 @@
         {
             int x = h->symbol << 16 >> 16;
             int y = h->symbol <<  0 >> 16;
-            fprintf(f, "%d,", ((h->level - parent_level)*256 + (x << 4) + (y << 0)));
+            fprintf(f, last ? "%d" : "%d,", ((h->level - parent_level)*256 + (x << 4) + (y << 0)));
         } else
         {
             assert(h->offset < (1 << 13));
             assert(h->offset);
-            fprintf(f, "%d,", (-h->offset << 3) | h->dp.best_width);
+            fprintf(f, last ? "%d" : "%d,", (-h->offset << 3) | h->dp.best_width);
         }
     } else
     {
         if (is_leaf(h))
         {
-            fprintf(f, "%d,", (h->symbol*16 + 8 + h->level));
+            fprintf(f, last ? "%d" : "%d,", (h->symbol*16 + 8 + h->level));
         } else
         {
-            fprintf(f, "%d,", (h->offset << 3) | h->dp.best_width);
-            //fprintf(f, "[%d,%d]", h->offset , h->dp.best_width);
+            fprintf(f, last ? "%d" : "%d,", (h->offset << 3) | h->dp.best_width);
         }
     }
 }
@@ -247,7 +246,7 @@
                 huff_t *r = (huff_t *)huff_decode(q, i, q->dp.best_width);
                 if (print_flag)
                 {
-                    huff_print_one(r, f, q->level);
+                    huff_print_one(r, f, q->level, 0);
                 }
 
                 if (!is_leaf(r))
@@ -278,7 +277,7 @@
     *off += w;
     for (i = 0; print_flag && i < w; i++)
     {
-        huff_print_one(huff_decode(h, i, h->dp.best_width), f, h->level);
+        huff_print_one(huff_decode(h, i, h->dp.best_width), f, h->level, (i + 1) == w);
     }
     for (i = 0; i < w; i++)
     {
@@ -285,6 +284,8 @@
         huff_t *q = (huff_t *)huff_decode(h, i, h->dp.best_width);
         if (!is_leaf(q))
         {
+            if (print_flag)
+                fprintf(f, ",");
             huff_set_links_dfs_recursion(q, f, print_flag, off);
         }
     }
@@ -318,7 +319,7 @@
         printf("%f average memory reads ", h ? h->dp.mips : 0);
         total_size += h ? h->dp.size : 0;
 
-        fprintf(dst_file, "static const %s tab%d[] = { ", tabn[i] < 32 ? "short" : "u8", tabn[i]);
+        fprintf(dst_file, "    static const %s tab%d[] = { ", tabn[i] < 32 ? "int16_t" : "uint8_t", tabn[i]);
         if (h)
         {
             //huff_set_links_bfs(h, dst_file);
@@ -336,7 +337,7 @@
     fprintf(dst_file, "#define HUFF_ENTRY_BITS %d\n", WROOT);
 #else
     fprintf(dst_file, "#define HUFF_ENTRY_BITS 0\n");
-    fprintf(dst_file, "static const u8 g_entry_bits[] = { ");
+    fprintf(dst_file, "    static const uint8_t g_entry_bits[] = { ");
     for (i = 0; i < sizeof(tabn)/sizeof(tabn[0]); i++)
     {
         fprintf(dst_file, "%d,", entry_bits[i]);
--- a/minimp3.h
+++ b/minimp3.h
@@ -768,7 +768,7 @@
     static const int16_t tab15[] = { -250,-1179,-1579,-1836,-1996,-2124,-2253,-2333,-2413,-2477,-2542,-2574,-2607,-2622,-2655,1314,1313,1298,1312,1282,785,785,785,785,1040,1040,1025,1025,768,768,768,768,-766,-798,-830,-862,-895,-911,-927,-943,-959,-975,-991,-1007,-1023,-1039,-1055,-1070,1724,1647,-1103,-1119,1631,1767,1662,1738,1708,1723,-1135,1780,1615,1779,1599,1677,1646,1778,1583,-1151,1777,1567,1737,1692,1765,1722,1707,1630,1751,1661,1764,1614,1736,1676,1763,1750,1645,1598,1721,1691,1762,1706,1582,1761,1566,-1167,1749,1629,767,766,751,765,494,494,735,764,719,749,734,763,447,447,748,718,477,506,431,491,446,476,461,505,415,430,475,445,504,399,460,489,414,503,383,474,429,459,502,502,746,752,488,398,501,473,413,472,486,271,480,270,-1439,-1455,1357,-1471,-1487,-1503,1341,1325,-1519,1489,1463,1403,1309,-1535,1372,1448,1418,1476,1356,1462,1387,-1551,1475,1340,1447,1402,1386,-1567,1068,1068,1474,1461,455,380,468,440,395,425,410,454,364,467,466,464,453,269,409,448,268,432,1371,1473,1432,1417,1308,1460,1355,1446,1459,1431,1083,1083,1401,1416,1458,1445,1067,1067,1370,1457,1051,1051,1291,1430,1385,1444,1354,1415,1400,1443,1082,1082,1173,1113,1186,1066,1185,1050,-1967,1158,1128,1172,1097,1171,1081,-1983,1157,1112,416,266,375,400,1170,1142,1127,1065,793,793,1169,1033,1156,1096,1141,1111,1155,1080,1126,1140,898,898,808,808,897,897,792,792,1095,1152,1032,1125,1110,1139,1079,1124,882,807,838,881,853,791,-2319,867,368,263,822,852,837,866,806,865,-2399,851,352,262,534,534,821,836,594,594,549,549,593,593,533,533,848,773,579,579,564,578,548,563,276,276,577,576,306,291,516,560,305,305,275,259 };
     static const int16_t tab16[] = { -251,-892,-2058,-2620,-2828,-2957,-3023,-3039,1041,1041,1040,1040,769,769,769,769,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,256,-511,-527,-543,-559,1530,-575,-591,1528,1527,1407,1526,1391,1023,1023,1023,1023,1525,1375,1268,1268,1103,1103,1087,1087,1039,1039,1523,-604,815,815,815,815,510,495,509,479,508,463,507,447,431,505,415,399,-734,-782,1262,-815,1259,1244,-831,1258,1228,-847,-863,1196,-879,1253,987,987,748,-767,493,493,462,477,414,414,686,669,478,446,461,445,474,429,487,458,412,471,1266,1264,1009,1009,799,799,-1019,-1276,-1452,-1581,-1677,-1757,-1821,-1886,-1933,-1997,1257,1257,1483,1468,1512,1422,1497,1406,1467,1496,1421,1510,1134,1134,1225,1225,1466,1451,1374,1405,1252,1252,1358,1480,1164,1164,1251,1251,1238,1238,1389,1465,-1407,1054,1101,-1423,1207,-1439,830,830,1248,1038,1237,1117,1223,1148,1236,1208,411,426,395,410,379,269,1193,1222,1132,1235,1221,1116,976,976,1192,1162,1177,1220,1131,1191,963,963,-1647,961,780,-1663,558,558,994,993,437,408,393,407,829,978,813,797,947,-1743,721,721,377,392,844,950,828,890,706,706,812,859,796,960,948,843,934,874,571,571,-1919,690,555,689,421,346,539,539,944,779,918,873,932,842,903,888,570,570,931,917,674,674,-2575,1562,-2591,1609,-2607,1654,1322,1322,1441,1441,1696,1546,1683,1593,1669,1624,1426,1426,1321,1321,1639,1680,1425,1425,1305,1305,1545,1668,1608,1623,1667,1592,1638,1666,1320,1320,1652,1607,1409,1409,1304,1304,1288,1288,1664,1637,1395,1395,1335,1335,1622,1636,1394,1394,1319,1319,1606,1621,1392,1392,1137,1137,1137,1137,345,390,360,375,404,373,1047,-2751,-2767,-2783,1062,1121,1046,-2799,1077,-2815,1106,1061,789,789,1105,1104,263,355,310,340,325,354,352,262,339,324,1091,1076,1029,1090,1060,1075,833,833,788,788,1088,1028,818,818,803,803,561,561,531,531,816,771,546,546,289,274,288,258 };
     static const int16_t tab24[] = { -253,-317,-381,-446,-478,-509,1279,1279,-811,-1179,-1451,-1756,-1900,-2028,-2189,-2253,-2333,-2414,-2445,-2511,-2526,1313,1298,-2559,1041,1041,1040,1040,1025,1025,1024,1024,1022,1007,1021,991,1020,975,1019,959,687,687,1018,1017,671,671,655,655,1016,1015,639,639,758,758,623,623,757,607,756,591,755,575,754,559,543,543,1009,783,-575,-621,-685,-749,496,-590,750,749,734,748,974,989,1003,958,988,973,1002,942,987,957,972,1001,926,986,941,971,956,1000,910,985,925,999,894,970,-1071,-1087,-1102,1390,-1135,1436,1509,1451,1374,-1151,1405,1358,1480,1420,-1167,1507,1494,1389,1342,1465,1435,1450,1326,1505,1310,1493,1373,1479,1404,1492,1464,1419,428,443,472,397,736,526,464,464,486,457,442,471,484,482,1357,1449,1434,1478,1388,1491,1341,1490,1325,1489,1463,1403,1309,1477,1372,1448,1418,1433,1476,1356,1462,1387,-1439,1475,1340,1447,1402,1474,1324,1461,1371,1473,269,448,1432,1417,1308,1460,-1711,1459,-1727,1441,1099,1099,1446,1386,1431,1401,-1743,1289,1083,1083,1160,1160,1458,1445,1067,1067,1370,1457,1307,1430,1129,1129,1098,1098,268,432,267,416,266,400,-1887,1144,1187,1082,1173,1113,1186,1066,1050,1158,1128,1143,1172,1097,1171,1081,420,391,1157,1112,1170,1142,1127,1065,1169,1049,1156,1096,1141,1111,1155,1080,1126,1154,1064,1153,1140,1095,1048,-2159,1125,1110,1137,-2175,823,823,1139,1138,807,807,384,264,368,263,868,838,853,791,867,822,852,837,866,806,865,790,-2319,851,821,836,352,262,850,805,849,-2399,533,533,835,820,336,261,578,548,563,577,532,532,832,772,562,562,547,547,305,275,560,515,290,290,288,258 };
-    static const uint8_t tab32[] = { 130,162,193,209,44,28,76,140,9,9,9,9,9,9,9,9,190,254,222,238,126,94,157,157,109,61,173,205};
+    static const uint8_t tab32[] = { 130,162,193,209,44,28,76,140,9,9,9,9,9,9,9,9,190,254,222,238,126,94,157,157,109,61,173,205 };
     static const uint8_t tab33[] = { 252,236,220,204,188,172,156,140,124,108,92,76,60,44,28,12 };
     static const int16_t * const tabindex[2*16] = { tab0,tab1,tab2,tab3,tab0,tab5,tab6,tab7,tab8,tab9,tab10,tab11,tab12,tab13,tab0,tab15,tab16,tab16,tab16,tab16,tab16,tab16,tab16,tab16,tab24,tab24,tab24,tab24,tab24,tab24,tab24,tab24 };
     static const uint8_t g_linbits[] =  { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,6,8,10,13,4,5,6,7,8,9,11,13 };