1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400
|
/*
* Command line parsing related functions
*
* Copyright (c) 1999 Mark Taylor
* 2000-2012 Robert Hegemann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/* $Id: parse.c,v 1.292.2.2 2012/02/07 13:40:37 robert Exp $ */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <assert.h>
#include <ctype.h>
#ifdef STDC_HEADERS
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
#else
# ifndef HAVE_STRCHR
# define strchr index
# define strrchr rindex
# endif
char *strchr(), *strrchr();
# ifndef HAVE_MEMCPY
# define memcpy(d, s, n) bcopy ((s), (d), (n))
# define memmove(d, s, n) bcopy ((s), (d), (n))
# endif
#endif
#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif
#include "lame.h"
#include "parse.h"
#include "main.h"
#include "get_audio.h"
#include "version.h"
#include "console.h"
#undef dimension_of
#define dimension_of(array) (sizeof(array)/sizeof(array[0]))
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif
#ifdef HAVE_ICONV
#include <iconv.h>
#include <errno.h>
#endif
#if defined _ALLOW_INTERNAL_OPTIONS
#define INTERNAL_OPTS 1
#else
#define INTERNAL_OPTS 0
#endif
#if (INTERNAL_OPTS!=0)
#include "set_get.h"
#define DEV_HELP(a) a
#else
#define DEV_HELP(a)
#endif
static int const lame_alpha_version_enabled = LAME_ALPHA_VERSION;
static int const internal_opts_enabled = INTERNAL_OPTS;
/* GLOBAL VARIABLES. set by parse_args() */
/* we need to clean this up */
ReaderConfig global_reader = { sf_unknown, 0, 0, 0 };
WriterConfig global_writer = { 0 };
UiConfig global_ui_config = {0,0,0,0};
DecoderConfig global_decoder;
RawPCMConfig global_raw_pcm =
{ /* in_bitwidth */ 16
, /* in_signed */ -1
, /* in_endian */ ByteOrderLittleEndian
};
/* possible text encodings */
typedef enum TextEncoding
{ TENC_RAW /* bytes will be stored as-is into ID3 tags, which are Latin1 per definition */
, TENC_LATIN1 /* text will be converted from local encoding to Latin1, as ID3 needs it */
, TENC_UTF16 /* text will be converted from local encoding to Unicode, as ID3v2 wants it */
} TextEncoding;
#ifdef HAVE_ICONV
#define ID3TAGS_EXTENDED
/* search for Zero termination in multi-byte strings */
static size_t
strlenMultiByte(char const* str, size_t w)
{
size_t n = 0;
if (str != 0) {
size_t i, x = 0;
for (n = 0; ; ++n) {
x = 0;
for (i = 0; i < w; ++i) {
x += *str++ == 0 ? 1 : 0;
}
if (x == w) {
break;
}
}
}
return n;
}
static size_t
currCharCodeSize(void)
{
size_t n = 1;
char dst[32];
char* src = "A";
char* env_lang = getenv("LANG");
char* xxx_code = env_lang == NULL ? NULL : strrchr(env_lang, '.');
char* cur_code = xxx_code == NULL ? "" : xxx_code+1;
iconv_t xiconv = iconv_open(cur_code, "ISO_8859-1");
if (xiconv != (iconv_t)-1) {
for (n = 0; n < 32; ++n) {
char* i_ptr = src;
char* o_ptr = dst;
size_t srcln = 1;
size_t avail = n;
size_t rc = iconv(xiconv, &i_ptr, &srcln, &o_ptr, &avail);
if (rc != (size_t)-1) {
break;
}
}
iconv_close(xiconv);
}
return n;
}
#if 0
static
char* fromLatin1( char* src )
{
char* dst = 0;
if (src != 0) {
size_t const l = strlen(src);
size_t const n = l*4;
dst = calloc(n+4, 4);
if (dst != 0) {
char* env_lang = getenv("LANG");
char* xxx_code = env_lang == NULL ? NULL : strrchr(env_lang, '.');
char* cur_code = xxx_code == NULL ? "" : xxx_code+1;
iconv_t xiconv = iconv_open(cur_code, "ISO_8859-1");
if (xiconv != (iconv_t)-1) {
char* i_ptr = src;
char* o_ptr = dst;
size_t srcln = l;
size_t avail = n;
iconv(xiconv, &i_ptr, &srcln, &o_ptr, &avail);
iconv_close(xiconv);
}
}
}
return dst;
}
static
char* fromUtf16( char* src )
{
char* dst = 0;
if (src != 0) {
size_t const l = strlenMultiByte(src, 2);
size_t const n = l*4;
dst = calloc(n+4, 4);
if (dst != 0) {
char* env_lang = getenv("LANG");
char* xxx_code = env_lang == NULL ? NULL : strrchr(env_lang, '.');
char* cur_code = xxx_code == NULL ? "" : xxx_code+1;
iconv_t xiconv = iconv_open(cur_code, "UTF-16LE");
if (xiconv != (iconv_t)-1) {
char* i_ptr = (char*)src;
char* o_ptr = dst;
size_t srcln = l*2;
size_t avail = n;
iconv(xiconv, &i_ptr, &srcln, &o_ptr, &avail);
iconv_close(xiconv);
}
}
}
return dst;
}
#endif
static
char* toLatin1( char* src )
{
size_t w = currCharCodeSize();
char* dst = 0;
if (src != 0) {
size_t const l = strlenMultiByte(src, w);
size_t const n = l*4;
dst = calloc(n+4, 4);
if (dst != 0) {
char* env_lang = getenv("LANG");
char* xxx_code = env_lang == NULL ? NULL : strrchr(env_lang, '.');
char* cur_code = xxx_code == NULL ? "" : xxx_code+1;
iconv_t xiconv = iconv_open("ISO_8859-1//TRANSLIT", cur_code);
if (xiconv != (iconv_t)-1) {
char* i_ptr = (char*)src;
char* o_ptr = dst;
size_t srcln = l*w;
size_t avail = n;
iconv(xiconv, &i_ptr, &srcln, &o_ptr, &avail);
iconv_close(xiconv);
}
}
}
return dst;
}
static
char* toUtf16( char* src )
{
size_t w = currCharCodeSize();
char* dst = 0;
if (src != 0) {
size_t const l = strlenMultiByte(src, w);
size_t const n = (l+1)*4;
dst = calloc(n+4, 4);
if (dst != 0) {
char* env_lang = getenv("LANG");
char* xxx_code = env_lang == NULL ? NULL : strrchr(env_lang, '.');
char* cur_code = xxx_code == NULL ? "" : xxx_code+1;
iconv_t xiconv = iconv_open("UTF-16LE//TRANSLIT", cur_code);
dst[0] = 0xff;
dst[1] = 0xfe;
if (xiconv != (iconv_t)-1) {
char* i_ptr = (char*)src;
char* o_ptr = &dst[2];
size_t srcln = l*w;
size_t avail = n;
iconv(xiconv, &i_ptr, &srcln, &o_ptr, &avail);
iconv_close(xiconv);
}
}
}
return dst;
}
#endif
#if defined( _WIN32 ) && !defined(__MINGW32__)
#define ID3TAGS_EXTENDED
char* toLatin1(char const* s)
{
return utf8ToLatin1(s);
}
unsigned short* toUtf16(char const* s)
{
return utf8ToUtf16(s);
}
#endif
static int
set_id3v2tag(lame_global_flags* gfp, int type, unsigned short const* str)
{
switch (type)
{
case 'a': return id3tag_set_textinfo_utf16(gfp, "TPE1", str);
case 't': return id3tag_set_textinfo_utf16(gfp, "TIT2", str);
case 'l': return id3tag_set_textinfo_utf16(gfp, "TALB", str);
case 'g': return id3tag_set_textinfo_utf16(gfp, "TCON", str);
case 'c': return id3tag_set_comment_utf16(gfp, 0, 0, str);
case 'n': return id3tag_set_textinfo_utf16(gfp, "TRCK", str);
case 'y': return id3tag_set_textinfo_utf16(gfp, "TYER", str);
case 'v': return id3tag_set_fieldvalue_utf16(gfp, str);
}
return 0;
}
static int
set_id3tag(lame_global_flags* gfp, int type, char const* str)
{
switch (type)
{
case 'a': return id3tag_set_artist(gfp, str), 0;
case 't': return id3tag_set_title(gfp, str), 0;
case 'l': return id3tag_set_album(gfp, str), 0;
case 'g': return id3tag_set_genre(gfp, str);
case 'c': return id3tag_set_comment(gfp, str), 0;
case 'n': return id3tag_set_track(gfp, str);
case 'y': return id3tag_set_year(gfp, str), 0;
case 'v': return id3tag_set_fieldvalue(gfp, str);
}
return 0;
}
static int
id3_tag(lame_global_flags* gfp, int type, TextEncoding enc, char* str)
{
void* x = 0;
int result;
if (enc == TENC_UTF16 && type != 'v' ) {
id3_tag(gfp, type, TENC_LATIN1, str); /* for id3v1 */
}
switch (enc)
{
default:
#ifdef ID3TAGS_EXTENDED
case TENC_LATIN1: x = toLatin1(str); break;
case TENC_UTF16: x = toUtf16(str); break;
#else
case TENC_RAW: x = strdup(str); break;
#endif
}
switch (enc)
{
default:
#ifdef ID3TAGS_EXTENDED
case TENC_LATIN1: result = set_id3tag(gfp, type, x); break;
case TENC_UTF16: result = set_id3v2tag(gfp, type, x); break;
#else
case TENC_RAW: result = set_id3tag(gfp, type, x); break;
#endif
}
free(x);
return result;
}
/************************************************************************
*
* license
*
* PURPOSE: Writes version and license to the file specified by fp
*
************************************************************************/
static int
lame_version_print(FILE * const fp)
{
const char *b = get_lame_os_bitness();
const char *v = get_lame_version();
const char *u = get_lame_url();
const unsigned int lenb = strlen(b);
const unsigned int lenv = strlen(v);
const unsigned int lenu = strlen(u);
const unsigned int lw = 80; /* line width of terminal in characters */
const unsigned int sw = 16; /* static width of text */
if (lw >= lenb + lenv + lenu + sw || lw < lenu + 2)
/* text fits in 80 chars per line, or line even too small for url */
if (lenb > 0)
fprintf(fp, "LAME %s version %s (%s)\n\n", b, v, u);
else
fprintf(fp, "LAME version %s (%s)\n\n", v, u);
else {
int const n_white_spaces = ((lenu+2) > lw ? 0 : lw-2-lenu);
/* text too long, wrap url into next line, right aligned */
if (lenb > 0)
fprintf(fp, "LAME %s version %s\n%*s(%s)\n\n", b, v, n_white_spaces, "", u);
else
fprintf(fp, "LAME version %s\n%*s(%s)\n\n", v, n_white_spaces, "", u);
}
if (lame_alpha_version_enabled)
fprintf(fp, "warning: alpha versions should be used for testing only\n\n");
return 0;
}
static int
print_license(FILE * const fp)
{ /* print version & license */
lame_version_print(fp);
fprintf(fp,
"Copyright (c) 1999-2011 by The LAME Project\n"
"Copyright (c) 1999,2000,2001 by Mark Taylor\n"
"Copyright (c) 1998 by Michael Cheng\n"
"Copyright (c) 1995,1996,1997 by Michael Hipp: mpglib\n" "\n");
fprintf(fp,
"This library is free software; you can redistribute it and/or\n"
"modify it under the terms of the GNU Library General Public\n"
"License as published by the Free Software Foundation; either\n"
"version 2 of the License, or (at your option) any later version.\n"
"\n"
"This library is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
"Library General Public License for more details.\n"
"\n"
"You should have received a copy of the GNU Library General Public\n"
"License along with this program. If not, see\n"
"<http://www.gnu.org/licenses/>.\n");
return 0;
}
/************************************************************************
*
* usage
*
* PURPOSE: Writes command line syntax to the file specified by fp
*
************************************************************************/
int
usage(FILE * const fp, const char *ProgramName)
{ /* print general syntax */
lame_version_print(fp);
fprintf(fp,
"usage: %s [options] <infile> [outfile]\n"
"\n"
" <infile> and/or <outfile> can be \"-\", which means stdin/stdout.\n"
"\n"
"Try:\n"
" \"%s --help\" for general usage information\n"
" or:\n"
" \"%s --preset help\" for information on suggested predefined settings\n"
" or:\n"
" \"%s --longhelp\"\n"
" or \"%s -?\" for a complete options list\n\n",
ProgramName, ProgramName, ProgramName, ProgramName, ProgramName);
return 0;
}
/************************************************************************
*
* usage
*
* PURPOSE: Writes command line syntax to the file specified by fp
* but only the most important ones, to fit on a vt100 terminal
*
************************************************************************/
int
short_help(const lame_global_flags * gfp, FILE * const fp, const char *ProgramName)
{ /* print short syntax help */
lame_version_print(fp);
fprintf(fp,
"usage: %s [options] <infile> [outfile]\n"
"\n"
" <infile> and/or <outfile> can be \"-\", which means stdin/stdout.\n"
"\n" "RECOMMENDED:\n" " lame -V2 input.wav output.mp3\n" "\n", ProgramName);
fprintf(fp,
"OPTIONS:\n"
" -b bitrate set the bitrate, default 128 kbps\n"
" -h higher quality, but a little slower. Recommended.\n"
" -f fast mode (lower quality)\n"
" -V n quality setting for VBR. default n=%i\n"
" 0=high quality,bigger files. 9=smaller files\n",
lame_get_VBR_q(gfp));
fprintf(fp,
" --preset type type must be \"medium\", \"standard\", \"extreme\", \"insane\",\n"
" or a value for an average desired bitrate and depending\n"
" on the value specified, appropriate quality settings will\n"
" be used.\n"
" \"--preset help\" gives more info on these\n" "\n");
fprintf(fp,
#if defined(WIN32)
" --priority type sets the process priority\n"
" 0,1 = Low priority\n"
" 2 = normal priority\n"
" 3,4 = High priority\n" "\n"
#endif
#if defined(__OS2__)
" --priority type sets the process priority\n"
" 0 = Low priority\n"
" 1 = Medium priority\n"
" 2 = Regular priority\n"
" 3 = High priority\n"
" 4 = Maximum priority\n" "\n"
#endif
" --help id3 ID3 tagging related options\n" "\n"
DEV_HELP(
" --help dev developer options\n" "\n"
)
" --longhelp full list of options\n" "\n"
" --license print License information\n\n"
);
return 0;
}
/************************************************************************
*
* usage
*
* PURPOSE: Writes command line syntax to the file specified by fp
*
************************************************************************/
static void
wait_for(FILE * const fp, int lessmode)
{
if (lessmode) {
fflush(fp);
getchar();
}
else {
fprintf(fp, "\n");
}
fprintf(fp, "\n");
}
static void
help_id3tag(FILE * const fp)
{
fprintf(fp,
" ID3 tag options:\n"
" --tt <title> audio/song title (max 30 chars for version 1 tag)\n"
" --ta <artist> audio/song artist (max 30 chars for version 1 tag)\n"
" --tl <album> audio/song album (max 30 chars for version 1 tag)\n"
" --ty <year> audio/song year of issue (1 to 9999)\n"
" --tc <comment> user-defined text (max 30 chars for v1 tag, 28 for v1.1)\n"
" --tn <track[/total]> audio/song track number and (optionally) the total\n"
" number of tracks on the original recording. (track\n"
" and total each 1 to 255. just the track number\n"
" creates v1.1 tag, providing a total forces v2.0).\n"
" --tg <genre> audio/song genre (name or number in list)\n"
" --ti <file> audio/song albumArt (jpeg/png/gif file, v2.3 tag)\n"
" --tv <id=value> user-defined frame specified by id and value (v2.3 tag)\n"
);
fprintf(fp,
" --add-id3v2 force addition of version 2 tag\n"
" --id3v1-only add only a version 1 tag\n"
" --id3v2-only add only a version 2 tag\n"
#ifdef ID3TAGS_EXTENDED
" --id3v2-utf16 add following options in unicode text encoding\n"
" --id3v2-latin1 add following options in latin-1 text encoding\n"
#endif
" --space-id3v1 pad version 1 tag with spaces instead of nulls\n"
" --pad-id3v2 same as '--pad-id3v2-size 128'\n"
" --pad-id3v2-size <value> adds version 2 tag, pad with extra <value> bytes\n"
" --genre-list print alphabetically sorted ID3 genre list and exit\n"
" --ignore-tag-errors ignore errors in values passed for tags\n" "\n"
);
fprintf(fp,
" Note: A version 2 tag will NOT be added unless one of the input fields\n"
" won't fit in a version 1 tag (e.g. the title string is longer than 30\n"
" characters), or the '--add-id3v2' or '--id3v2-only' options are used,\n"
" or output is redirected to stdout.\n"
);
}
static void
help_developer_switches(FILE * const fp)
{
if ( !internal_opts_enabled ) {
fprintf(fp,
" Note: Almost all of the following switches aren't available in this build!\n\n"
);
}
fprintf(fp,
" ATH related:\n"
" --noath turns ATH down to a flat noise floor\n"
" --athshort ignore GPSYCHO for short blocks, use ATH only\n"
" --athonly ignore GPSYCHO completely, use ATH only\n"
" --athtype n selects between different ATH types [0-4]\n"
" --athlower x lowers ATH by x dB\n"
);
fprintf(fp,
" --athaa-type n ATH auto adjust: 0 'no' else 'loudness based'\n"
/** OBSOLETE " --athaa-loudapprox n n=1 total energy or n=2 equal loudness curve\n"*/
" --athaa-sensitivity x activation offset in -/+ dB for ATH auto-adjustment\n"
"\n");
fprintf(fp,
" PSY related:\n"
" --short use short blocks when appropriate\n"
" --noshort do not use short blocks\n"
" --allshort use only short blocks\n"
);
fprintf(fp,
"(1) --temporal-masking x x=0 disables, x=1 enables temporal masking effect\n"
" --nssafejoint M/S switching criterion\n"
" --nsmsfix <arg> M/S switching tuning [effective 0-3.5]\n"
"(2) --interch x adjust inter-channel masking ratio\n"
" --ns-bass x adjust masking for sfbs 0 - 6 (long) 0 - 5 (short)\n"
" --ns-alto x adjust masking for sfbs 7 - 13 (long) 6 - 10 (short)\n"
" --ns-treble x adjust masking for sfbs 14 - 21 (long) 11 - 12 (short)\n"
);
fprintf(fp,
" --ns-sfb21 x change ns-treble by x dB for sfb21\n"
" --shortthreshold x,y short block switching threshold,\n"
" x for L/R/M channel, y for S channel\n"
" -Z [n] always do calculate short block maskings\n"
" Noise Shaping related:\n"
"(1) --substep n use pseudo substep noise shaping method types 0-2\n"
"(1) -X n[,m] selects between different noise measurements\n"
" n for long block, m for short. if m is omitted, m = n\n"
" 1: CBR, ABR and VBR-old encoding modes only\n"
" 2: ignored\n"
);
}
int
long_help(const lame_global_flags * gfp, FILE * const fp, const char *ProgramName, int lessmode)
{ /* print long syntax help */
lame_version_print(fp);
fprintf(fp,
"usage: %s [options] <infile> [outfile]\n"
"\n"
" <infile> and/or <outfile> can be \"-\", which means stdin/stdout.\n"
"\n" "RECOMMENDED:\n" " lame -V2 input.wav output.mp3\n" "\n", ProgramName);
fprintf(fp,
"OPTIONS:\n"
" Input options:\n"
" --scale <arg> scale input (multiply PCM data) by <arg>\n"
" --scale-l <arg> scale channel 0 (left) input (multiply PCM data) by <arg>\n"
" --scale-r <arg> scale channel 1 (right) input (multiply PCM data) by <arg>\n"
#if (defined HAVE_MPGLIB || defined AMIGA_MPEGA)
" --mp1input input file is a MPEG Layer I file\n"
" --mp2input input file is a MPEG Layer II file\n"
" --mp3input input file is a MPEG Layer III file\n"
#endif
" --nogap <file1> <file2> <...>\n"
" gapless encoding for a set of contiguous files\n"
" --nogapout <dir>\n"
" output dir for gapless encoding (must precede --nogap)\n"
" --nogaptags allow the use of VBR tags in gapless encoding\n"
);
fprintf(fp,
"\n"
" Input options for RAW PCM:\n"
" -r input is raw pcm\n"
" -x force byte-swapping of input\n"
" -s sfreq sampling frequency of input file (kHz) - default 44.1 kHz\n"
" --bitwidth w input bit width is w (default 16)\n"
" --signed input is signed (default)\n"
" --unsigned input is unsigned\n"
" --little-endian input is little-endian (default)\n"
" --big-endian input is big-endian\n"
);
wait_for(fp, lessmode);
fprintf(fp,
" Operational options:\n"
" -a downmix from stereo to mono file for mono encoding\n"
" -m <mode> (j)oint, (s)imple, (f)orce, (d)ual-mono, (m)ono (l)eft (r)ight\n"
" default is (j) or (s) depending on bitrate\n"
" joint = joins the best possible of MS and LR stereo\n"
" simple = force LR stereo on all frames\n"
" force = force MS stereo on all frames.\n"
" --preset type type must be \"medium\", \"standard\", \"extreme\", \"insane\",\n"
" or a value for an average desired bitrate and depending\n"
" on the value specified, appropriate quality settings will\n"
" be used.\n"
" \"--preset help\" gives more info on these\n"
" --comp <arg> choose bitrate to achieve a compression ratio of <arg>\n");
fprintf(fp, " --replaygain-fast compute RG fast but slightly inaccurately (default)\n"
#ifdef DECODE_ON_THE_FLY
" --replaygain-accurate compute RG more accurately and find the peak sample\n"
#endif
" --noreplaygain disable ReplayGain analysis\n"
#ifdef DECODE_ON_THE_FLY
" --clipdetect enable --replaygain-accurate and print a message whether\n"
" clipping occurs and how far the waveform is from full scale\n"
#endif
);
fprintf(fp,
" --flush flush output stream as soon as possible\n"
" --freeformat produce a free format bitstream\n"
" --decode input=mp3 file, output=wav\n"
" --swap-channel swap L/R channels\n"
" -t disable writing wav header when using --decode\n");
wait_for(fp, lessmode);
fprintf(fp,
" Verbosity:\n"
" --disptime <arg>print progress report every arg seconds\n"
" -S don't print progress report, VBR histograms\n"
" --nohist disable VBR histogram display\n"
" --quiet don't print anything on screen\n"
" --silent don't print anything on screen, but fatal errors\n"
" --brief print more useful information\n"
" --verbose print a lot of useful information\n" "\n");
fprintf(fp,
" Noise shaping & psycho acoustic algorithms:\n"
" -q <arg> <arg> = 0...9. Default -q 5 \n"
" -q 0: Highest quality, very slow \n"
" -q 9: Poor quality, but fast \n"
" -h Same as -q 2. Recommended.\n"
" -f Same as -q 7. Fast, ok quality\n");
wait_for(fp, lessmode);
fprintf(fp,
" CBR (constant bitrate, the default) options:\n"
" -b <bitrate> set the bitrate in kbps, default 128 kbps\n"
" --cbr enforce use of constant bitrate\n"
"\n"
" ABR options:\n"
" --abr <bitrate> specify average bitrate desired (instead of quality)\n" "\n");
fprintf(fp,
" VBR options:\n"
" -V n quality setting for VBR. default n=%i\n"
" 0=high quality,bigger files. 9=smaller files\n"
" -v the same as -V 4\n"
" --vbr-old use old variable bitrate (VBR) routine\n"
" --vbr-new use new variable bitrate (VBR) routine (default)\n"
" -Y lets LAME ignore noise in sfb21, like in CBR\n"
,
lame_get_VBR_q(gfp));
fprintf(fp,
" -b <bitrate> specify minimum allowed bitrate, default 32 kbps\n"
" -B <bitrate> specify maximum allowed bitrate, default 320 kbps\n"
" -F strictly enforce the -b option, for use with players that\n"
" do not support low bitrate mp3\n"
" -t disable writing LAME Tag\n"
" -T enable and force writing LAME Tag\n");
wait_for(fp, lessmode);
DEV_HELP(
help_developer_switches(fp);
wait_for(fp, lessmode);
)
fprintf(fp,
" MP3 header/stream options:\n"
" -e <emp> de-emphasis n/5/c (obsolete)\n"
" -c mark as copyright\n"
" -o mark as non-original\n"
" -p error protection. adds 16 bit checksum to every frame\n"
" (the checksum is computed correctly)\n"
" --nores disable the bit reservoir\n"
" --strictly-enforce-ISO comply as much as possible to ISO MPEG spec\n");
fprintf(fp,
" --buffer-constraint <constraint> available values for constraint:\n"
" default, strict, maximum\n"
"\n"
);
fprintf(fp,
" Filter options:\n"
" --lowpass <freq> frequency(kHz), lowpass filter cutoff above freq\n"
" --lowpass-width <freq> frequency(kHz) - default 15%% of lowpass freq\n"
" --highpass <freq> frequency(kHz), highpass filter cutoff below freq\n"
" --highpass-width <freq> frequency(kHz) - default 15%% of highpass freq\n");
fprintf(fp,
" --resample <sfreq> sampling frequency of output file(kHz)- default=automatic\n");
wait_for(fp, lessmode);
help_id3tag(fp);
fprintf(fp,
#if defined(WIN32)
"\n\nMS-Windows-specific options:\n"
" --priority <type> sets the process priority:\n"
" 0,1 = Low priority (IDLE_PRIORITY_CLASS)\n"
" 2 = normal priority (NORMAL_PRIORITY_CLASS, default)\n"
" 3,4 = High priority (HIGH_PRIORITY_CLASS))\n"
" Note: Calling '--priority' without a parameter will select priority 0.\n"
#endif
#if defined(__OS2__)
"\n\nOS/2-specific options:\n"
" --priority <type> sets the process priority:\n"
" 0 = Low priority (IDLE, delta = 0)\n"
" 1 = Medium priority (IDLE, delta = +31)\n"
" 2 = Regular priority (REGULAR, delta = -31)\n"
" 3 = High priority (REGULAR, delta = 0)\n"
" 4 = Maximum priority (REGULAR, delta = +31)\n"
" Note: Calling '--priority' without a parameter will select priority 0.\n"
#endif
"\nMisc:\n --license print License information\n\n"
);
#if defined(HAVE_NASM)
wait_for(fp, lessmode);
fprintf(fp,
" Platform specific:\n"
" --noasm <instructions> disable assembly optimizations for mmx/3dnow/sse\n");
wait_for(fp, lessmode);
#endif
display_bitrates(fp);
return 0;
}
static void
display_bitrate(FILE * const fp, const char *const version, const int d, const int indx)
{
int i;
int nBitrates = 14;
if (d == 4)
nBitrates = 8;
fprintf(fp,
"\nMPEG-%-3s layer III sample frequencies (kHz): %2d %2d %g\n"
"bitrates (kbps):", version, 32 / d, 48 / d, 44.1 / d);
for (i = 1; i <= nBitrates; i++)
fprintf(fp, " %2i", lame_get_bitrate(indx, i));
fprintf(fp, "\n");
}
int
display_bitrates(FILE * const fp)
{
display_bitrate(fp, "1", 1, 1);
display_bitrate(fp, "2", 2, 0);
display_bitrate(fp, "2.5", 4, 0);
fprintf(fp, "\n");
fflush(fp);
return 0;
}
/* note: for presets it would be better to externalize them in a file.
suggestion: lame --preset <file-name> ...
or: lame --preset my-setting ... and my-setting is defined in lame.ini
*/
/*
Note from GB on 08/25/2002:
I am merging --presets and --alt-presets. Old presets are now aliases for
corresponding abr values from old alt-presets. This way we now have a
unified preset system, and I hope than more people will use the new tuned
presets instead of the old unmaintained ones.
*/
/************************************************************************
*
* usage
*
* PURPOSE: Writes presetting info to #stdout#
*
************************************************************************/
static void
presets_longinfo_dm(FILE * msgfp)
{
fprintf(msgfp,
"\n"
"The --preset switches are aliases over LAME settings.\n"
"\n" "\n");
fprintf(msgfp,
"To activate these presets:\n"
"\n" " For VBR modes (generally highest quality):\n" "\n");
fprintf(msgfp,
" \"--preset medium\" This preset should provide near transparency\n"
" to most people on most music.\n"
"\n"
" \"--preset standard\" This preset should generally be transparent\n"
" to most people on most music and is already\n"
" quite high in quality.\n" "\n");
fprintf(msgfp,
" \"--preset extreme\" If you have extremely good hearing and similar\n"
" equipment, this preset will generally provide\n"
" slightly higher quality than the \"standard\"\n"
" mode.\n" "\n");
fprintf(msgfp,
" For CBR 320kbps (highest quality possible from the --preset switches):\n"
"\n"
" \"--preset insane\" This preset will usually be overkill for most\n"
" people and most situations, but if you must\n"
" have the absolute highest quality with no\n"
" regard to filesize, this is the way to go.\n" "\n");
fprintf(msgfp,
" For ABR modes (high quality per given bitrate but not as high as VBR):\n"
"\n"
" \"--preset <kbps>\" Using this preset will usually give you good\n"
" quality at a specified bitrate. Depending on the\n"
" bitrate entered, this preset will determine the\n");
fprintf(msgfp,
" optimal settings for that particular situation.\n"
" While this approach works, it is not nearly as\n"
" flexible as VBR, and usually will not attain the\n"
" same level of quality as VBR at higher bitrates.\n" "\n");
fprintf(msgfp,
"The following options are also available for the corresponding profiles:\n"
"\n"
" standard\n"
" extreme\n"
" insane\n"
" <cbr> (ABR Mode) - The ABR Mode is implied. To use it,\n"
" simply specify a bitrate. For example:\n"
" \"--preset 185\" activates this\n"
" preset and uses 185 as an average kbps.\n" "\n");
fprintf(msgfp,
" \"cbr\" - If you use the ABR mode (read above) with a significant\n"
" bitrate such as 80, 96, 112, 128, 160, 192, 224, 256, 320,\n"
" you can use the \"cbr\" option to force CBR mode encoding\n"
" instead of the standard abr mode. ABR does provide higher\n"
" quality but CBR may be useful in situations such as when\n"
" streaming an mp3 over the internet may be important.\n" "\n");
fprintf(msgfp,
" For example:\n"
"\n"
" \"--preset standard <input file> <output file>\"\n"
" or \"--preset cbr 192 <input file> <output file>\"\n"
" or \"--preset 172 <input file> <output file>\"\n"
" or \"--preset extreme <input file> <output file>\"\n" "\n" "\n");
fprintf(msgfp,
"A few aliases are also available for ABR mode:\n"
"phone => 16kbps/mono phon+/lw/mw-eu/sw => 24kbps/mono\n"
"mw-us => 40kbps/mono voice => 56kbps/mono\n"
"fm/radio/tape => 112kbps hifi => 160kbps\n"
"cd => 192kbps studio => 256kbps\n");
}
static int
presets_set(lame_t gfp, int fast, int cbr, const char *preset_name, const char *ProgramName)
{
int mono = 0;
if ((strcmp(preset_name, "help") == 0) && (fast < 1)
&& (cbr < 1)) {
lame_version_print(stdout);
presets_longinfo_dm(stdout);
return -1;
}
/*aliases for compatibility with old presets */
if (strcmp(preset_name, "phone") == 0) {
preset_name = "16";
mono = 1;
}
if ((strcmp(preset_name, "phon+") == 0) ||
(strcmp(preset_name, "lw") == 0) ||
(strcmp(preset_name, "mw-eu") == 0) || (strcmp(preset_name, "sw") == 0)) {
preset_name = "24";
mono = 1;
}
if (strcmp(preset_name, "mw-us") == 0) {
preset_name = "40";
mono = 1;
}
if (strcmp(preset_name, "voice") == 0) {
preset_name = "56";
mono = 1;
}
if (strcmp(preset_name, "fm") == 0) {
preset_name = "112";
}
if ((strcmp(preset_name, "radio") == 0) || (strcmp(preset_name, "tape") == 0)) {
preset_name = "112";
}
if (strcmp(preset_name, "hifi") == 0) {
preset_name = "160";
}
if (strcmp(preset_name, "cd") == 0) {
preset_name = "192";
}
if (strcmp(preset_name, "studio") == 0) {
preset_name = "256";
}
if (strcmp(preset_name, "medium") == 0) {
lame_set_VBR_q(gfp, 4);
lame_set_VBR(gfp, vbr_default);
return 0;
}
if (strcmp(preset_name, "standard") == 0) {
lame_set_VBR_q(gfp, 2);
lame_set_VBR(gfp, vbr_default);
return 0;
}
else if (strcmp(preset_name, "extreme") == 0) {
lame_set_VBR_q(gfp, 0);
lame_set_VBR(gfp, vbr_default);
return 0;
}
else if ((strcmp(preset_name, "insane") == 0) && (fast < 1)) {
lame_set_preset(gfp, INSANE);
return 0;
}
/* Generic ABR Preset */
if (((atoi(preset_name)) > 0) && (fast < 1)) {
if ((atoi(preset_name)) >= 8 && (atoi(preset_name)) <= 320) {
lame_set_preset(gfp, atoi(preset_name));
if (cbr == 1)
lame_set_VBR(gfp, vbr_off);
if (mono == 1) {
lame_set_mode(gfp, MONO);
}
return 0;
}
else {
lame_version_print(Console_IO.Error_fp);
error_printf("Error: The bitrate specified is out of the valid range for this preset\n"
"\n"
"When using this mode you must enter a value between \"32\" and \"320\"\n"
"\n" "For further information try: \"%s --preset help\"\n", ProgramName);
return -1;
}
}
lame_version_print(Console_IO.Error_fp);
error_printf("Error: You did not enter a valid profile and/or options with --preset\n"
"\n"
"Available profiles are:\n"
"\n"
" medium\n"
" standard\n"
" extreme\n"
" insane\n"
" <cbr> (ABR Mode) - The ABR Mode is implied. To use it,\n"
" simply specify a bitrate. For example:\n"
" \"--preset 185\" activates this\n"
" preset and uses 185 as an average kbps.\n" "\n");
error_printf(" Some examples:\n"
"\n"
" or \"%s --preset standard <input file> <output file>\"\n"
" or \"%s --preset cbr 192 <input file> <output file>\"\n"
" or \"%s --preset 172 <input file> <output file>\"\n"
" or \"%s --preset extreme <input file> <output file>\"\n"
"\n"
"For further information try: \"%s --preset help\"\n", ProgramName, ProgramName,
ProgramName, ProgramName, ProgramName);
return -1;
}
static void
genre_list_handler(int num, const char *name, void *cookie)
{
(void) cookie;
console_printf("%3d %s\n", num, name);
}
/************************************************************************
*
* parse_args
*
* PURPOSE: Sets encoding parameters to the specifications of the
* command line. Default settings are used for parameters
* not specified in the command line.
*
* If the input file is in WAVE or AIFF format, the sampling frequency is read
* from the AIFF header.
*
* The input and output filenames are read into #inpath# and #outpath#.
*
************************************************************************/
/* would use real "strcasecmp" but it isn't portable */
static int
local_strcasecmp(const char *s1, const char *s2)
{
unsigned char c1;
unsigned char c2;
do {
c1 = (unsigned char) tolower(*s1);
c2 = (unsigned char) tolower(*s2);
if (!c1) {
break;
}
++s1;
++s2;
} while (c1 == c2);
return c1 - c2;
}
static int
local_strncasecmp(const char *s1, const char *s2, int n)
{
unsigned char c1 = 0;
unsigned char c2 = 0;
int cnt = 0;
do {
if (cnt == n) {
break;
}
c1 = (unsigned char) tolower(*s1);
c2 = (unsigned char) tolower(*s2);
if (!c1) {
break;
}
++s1;
++s2;
++cnt;
} while (c1 == c2);
return c1 - c2;
}
/* LAME is a simple frontend which just uses the file extension */
/* to determine the file type. Trying to analyze the file */
/* contents is well beyond the scope of LAME and should not be added. */
static int
filename_to_type(const char *FileName)
{
size_t len = strlen(FileName);
if (len < 4)
return sf_unknown;
FileName += len - 4;
if (0 == local_strcasecmp(FileName, ".mpg"))
return sf_mp123;
if (0 == local_strcasecmp(FileName, ".mp1"))
return sf_mp123;
if (0 == local_strcasecmp(FileName, ".mp2"))
return sf_mp123;
if (0 == local_strcasecmp(FileName, ".mp3"))
return sf_mp123;
if (0 == local_strcasecmp(FileName, ".wav"))
return sf_wave;
if (0 == local_strcasecmp(FileName, ".aif"))
return sf_aiff;
if (0 == local_strcasecmp(FileName, ".raw"))
return sf_raw;
if (0 == local_strcasecmp(FileName, ".ogg"))
return sf_ogg;
return sf_unknown;
}
static int
resample_rate(double freq)
{
if (freq >= 1.e3)
freq *= 1.e-3;
switch ((int) freq) {
case 8:
return 8000;
case 11:
return 11025;
case 12:
return 12000;
case 16:
return 16000;
case 22:
return 22050;
case 24:
return 24000;
case 32:
return 32000;
case 44:
return 44100;
case 48:
return 48000;
default:
error_printf("Illegal resample frequency: %.3f kHz\n", freq);
return 0;
}
}
#ifdef _WIN32
#define SLASH '\\'
#elif __OS2__
#define SLASH '\\'
#else
#define SLASH '/'
#endif
static
size_t scanPath(char const* s, char const** a, char const** b)
{
char const* s1 = s;
char const* s2 = s;
if (s != 0) {
for (; *s; ++s) {
switch (*s) {
case SLASH:
case ':':
s2 = s;
break;
}
}
if (*s2 == ':') {
++s2;
}
}
if (a) {
*a = s1;
}
if (b) {
*b = s2;
}
return s2-s1;
}
static
size_t scanBasename(char const* s, char const** a, char const** b)
{
char const* s1 = s;
char const* s2 = s;
if (s != 0) {
for (; *s; ++s) {
switch (*s) {
case SLASH:
case ':':
s1 = s2 = s;
break;
case '.':
s2 = s;
break;
}
}
if (s2 == s1) {
s2 = s;
}
if (*s1 == SLASH || *s1 == ':') {
++s1;
}
}
if (a != 0) {
*a = s1;
}
if (b != 0) {
*b = s2;
}
return s2-s1;
}
static
int isCommonSuffix(char const* s_ext)
{
char const* suffixes[] =
{ ".WAV", ".RAW", ".MP1", ".MP2"
, ".MP3", ".MPG", ".MPA", ".CDA"
, ".OGG", ".AIF", ".AIFF", ".AU"
, ".SND", ".FLAC", ".WV", ".OFR"
, ".TAK", ".MP4", ".M4A", ".PCM"
, ".W64"
};
size_t i;
for (i = 0; i < dimension_of(suffixes); ++i) {
if (local_strcasecmp(s_ext, suffixes[i]) == 0) {
return 1;
}
}
return 0;
}
static
int generateOutPath(lame_t gfp, char const* inPath, char const* outDir, char* outPath)
{
size_t const max_path = PATH_MAX;
char const* s_ext = lame_get_decode_only(gfp) ? ".wav" : ".mp3";
#if 1
size_t i = 0;
int out_dir_used = 0;
if (outDir != 0 && outDir[0] != 0) {
out_dir_used = 1;
while (*outDir) {
outPath[i++] = *outDir++;
if (i >= max_path) {
goto err_generateOutPath;
}
}
if (i > 0 && outPath[i-1] != SLASH) {
outPath[i++] = SLASH;
if (i >= max_path) {
goto err_generateOutPath;
}
}
outPath[i] = 0;
}
else {
char const* pa;
char const* pb;
size_t j, n = scanPath(inPath, &pa, &pb);
if (i+n >= max_path) {
goto err_generateOutPath;
}
for (j = 0; j < n; ++j) {
outPath[i++] = pa[j];
}
if (n > 0) {
outPath[i++] = SLASH;
if (i >= max_path) {
goto err_generateOutPath;
}
}
outPath[i] = 0;
}
{
int replace_suffix = 0;
char const* na;
char const* nb;
size_t j, n = scanBasename(inPath, &na, &nb);
if (i+n >= max_path) {
goto err_generateOutPath;
}
for (j = 0; j < n; ++j) {
outPath[i++] = na[j];
}
outPath[i] = 0;
if (isCommonSuffix(nb) == 1) {
replace_suffix = 1;
if (out_dir_used == 0) {
if (local_strcasecmp(nb, s_ext) == 0) {
replace_suffix = 0;
}
}
}
if (replace_suffix == 0) {
while (*nb) {
outPath[i++] = *nb++;
if (i >= max_path) {
goto err_generateOutPath;
}
}
outPath[i] = 0;
}
}
if (i+5 >= max_path) {
goto err_generateOutPath;
}
while (*s_ext) {
outPath[i++] = *s_ext++;
}
outPath[i] = 0;
return 0;
err_generateOutPath:
error_printf( "error: output file name too long" );
return 1;
#else
strncpy(outPath, inPath, PATH_MAX + 1 - 4);
strncat(outPath, s_ext, 4);
return 0;
#endif
}
static int
set_id3_albumart(lame_t gfp, char const* file_name)
{
int ret = -1;
FILE *fpi = 0;
char *albumart = 0;
if (file_name == 0) {
return 0;
}
fpi = lame_fopen(file_name, "rb");
if (!fpi) {
ret = 1;
}
else {
size_t size;
fseek(fpi, 0, SEEK_END);
size = ftell(fpi);
fseek(fpi, 0, SEEK_SET);
albumart = (char *)malloc(size);
if (!albumart) {
ret = 2;
}
else {
if (fread(albumart, 1, size, fpi) != size) {
ret = 3;
}
else {
ret = id3tag_set_albumart(gfp, albumart, size) ? 4 : 0;
}
free(albumart);
}
fclose(fpi);
}
switch (ret) {
case 1: error_printf("Could not find: '%s'.\n", file_name); break;
case 2: error_printf("Insufficient memory for reading the albumart.\n"); break;
case 3: error_printf("Read error: '%s'.\n", file_name); break;
case 4: error_printf("Unsupported image: '%s'.\nSpecify JPEG/PNG/GIF image\n", file_name); break;
default: break;
}
return ret;
}
enum ID3TAG_MODE
{ ID3TAG_MODE_DEFAULT
, ID3TAG_MODE_V1_ONLY
, ID3TAG_MODE_V2_ONLY
};
/* Ugly, NOT final version */
#define T_IF(str) if ( 0 == local_strcasecmp (token,str) ) {
#define T_ELIF(str) } else if ( 0 == local_strcasecmp (token,str) ) {
#define T_ELIF_INTERNAL(str) } else if (internal_opts_enabled && (0 == local_strcasecmp (token,str)) ) {
#define T_ELIF2(str1,str2) } else if ( 0 == local_strcasecmp (token,str1) || 0 == local_strcasecmp (token,str2) ) {
#define T_ELSE } else {
#define T_END }
int
parse_args(lame_global_flags * gfp, int argc, char **argv,
char *const inPath, char *const outPath, char **nogap_inPath, int *num_nogap)
{
char outDir[1024] = "";
int input_file = 0; /* set to 1 if we parse an input file name */
int i;
int autoconvert = 0;
double val;
int nogap = 0;
int nogap_tags = 0; /* set to 1 to use VBR tags in NOGAP mode */
const char *ProgramName = argv[0];
int count_nogap = 0;
int noreplaygain = 0; /* is RG explicitly disabled by the user */
int id3tag_mode = ID3TAG_MODE_DEFAULT;
int ignore_tag_errors = 0; /* Ignore errors in values passed for tags */
#ifdef ID3TAGS_EXTENDED
enum TextEncoding id3_tenc = TENC_UTF16;
#else
enum TextEncoding id3_tenc = TENC_LATIN1;
#endif
inPath[0] = '\0';
outPath[0] = '\0';
/* turn on display options. user settings may turn them off below */
global_ui_config.silent = 0;
global_ui_config.brhist = 1;
global_decoder.mp3_delay = 0;
global_decoder.mp3_delay_set = 0;
global_decoder.disable_wav_header = 0;
global_ui_config.print_clipping_info = 0;
id3tag_init(gfp);
/* process args */
for (i = 0; ++i < argc;) {
char c;
char *token;
char *arg;
char *nextArg;
int argUsed;
token = argv[i];
if (*token++ == '-') {
argUsed = 0;
nextArg = i + 1 < argc ? argv[i + 1] : "";
if (!*token) { /* The user wants to use stdin and/or stdout. */
input_file = 1;
if (inPath[0] == '\0')
strncpy(inPath, argv[i], PATH_MAX + 1);
else if (outPath[0] == '\0')
strncpy(outPath, argv[i], PATH_MAX + 1);
}
if (*token == '-') { /* GNU style */
token++;
T_IF("resample")
argUsed = 1;
(void) lame_set_out_samplerate(gfp, resample_rate(atof(nextArg)));
T_ELIF("vbr-old")
lame_set_VBR(gfp, vbr_rh);
T_ELIF("vbr-new")
lame_set_VBR(gfp, vbr_mt);
T_ELIF("vbr-mtrh")
lame_set_VBR(gfp, vbr_mtrh);
T_ELIF("cbr")
lame_set_VBR(gfp, vbr_off);
T_ELIF("abr")
/* values larger than 8000 are bps (like Fraunhofer), so it's strange to get 320000 bps MP3 when specifying 8000 bps MP3 */
int m = atoi(nextArg);
argUsed = 1;
if (m >= 8000) {
m = (m + 500) / 1000;
}
if (m > 320) {
m = 320;
}
if (m < 8) {
m = 8;
}
lame_set_VBR(gfp, vbr_abr);
lame_set_VBR_mean_bitrate_kbps(gfp, m);
T_ELIF("r3mix")
lame_set_preset(gfp, R3MIX);
T_ELIF("bitwidth")
argUsed = 1;
global_raw_pcm.in_bitwidth = atoi(nextArg);
T_ELIF("signed")
global_raw_pcm.in_signed = 1;
T_ELIF("unsigned")
global_raw_pcm.in_signed = 0;
T_ELIF("little-endian")
global_raw_pcm.in_endian = ByteOrderLittleEndian;
T_ELIF("big-endian")
global_raw_pcm.in_endian = ByteOrderBigEndian;
T_ELIF("mp1input")
global_reader.input_format = sf_mp1;
T_ELIF("mp2input")
global_reader.input_format = sf_mp2;
T_ELIF("mp3input")
global_reader.input_format = sf_mp3;
T_ELIF("ogginput")
error_printf("sorry, vorbis support in LAME is deprecated.\n");
return -1;
#if INTERNAL_OPTS
T_ELIF_INTERNAL("noshort")
(void) lame_set_no_short_blocks(gfp, 1);
T_ELIF_INTERNAL("short")
(void) lame_set_no_short_blocks(gfp, 0);
T_ELIF_INTERNAL("allshort")
(void) lame_set_force_short_blocks(gfp, 1);
#endif
T_ELIF("decode")
(void) lame_set_decode_only(gfp, 1);
T_ELIF("flush")
global_writer.flush_write = 1;
T_ELIF("decode-mp3delay")
global_decoder.mp3_delay = atoi(nextArg);
global_decoder.mp3_delay_set = 1;
argUsed = 1;
T_ELIF("nores")
lame_set_disable_reservoir(gfp, 1);
T_ELIF("strictly-enforce-ISO")
lame_set_strict_ISO(gfp, MDB_STRICT_ISO);
T_ELIF("buffer-constraint")
argUsed = 1;
if (strcmp(nextArg, "default") == 0)
(void) lame_set_strict_ISO(gfp, MDB_DEFAULT);
else if (strcmp(nextArg, "strict") == 0)
(void) lame_set_strict_ISO(gfp, MDB_STRICT_ISO);
else if (strcmp(nextArg, "maximum") == 0)
(void) lame_set_strict_ISO(gfp, MDB_MAXIMUM);
else {
error_printf("unknown buffer constraint '%s'\n", nextArg);
return -1;
}
T_ELIF("scale")
argUsed = 1;
(void) lame_set_scale(gfp, (float) atof(nextArg));
T_ELIF("scale-l")
argUsed = 1;
(void) lame_set_scale_left(gfp, (float) atof(nextArg));
T_ELIF("scale-r")
argUsed = 1;
(void) lame_set_scale_right(gfp, (float) atof(nextArg));
T_ELIF("noasm")
argUsed = 1;
if (!strcmp(nextArg, "mmx"))
(void) lame_set_asm_optimizations(gfp, MMX, 0);
if (!strcmp(nextArg, "3dnow"))
(void) lame_set_asm_optimizations(gfp, AMD_3DNOW, 0);
if (!strcmp(nextArg, "sse"))
(void) lame_set_asm_optimizations(gfp, SSE, 0);
T_ELIF("freeformat")
lame_set_free_format(gfp, 1);
T_ELIF("replaygain-fast")
lame_set_findReplayGain(gfp, 1);
#ifdef DECODE_ON_THE_FLY
T_ELIF("replaygain-accurate")
lame_set_decode_on_the_fly(gfp, 1);
lame_set_findReplayGain(gfp, 1);
#endif
T_ELIF("noreplaygain")
noreplaygain = 1;
lame_set_findReplayGain(gfp, 0);
#ifdef DECODE_ON_THE_FLY
T_ELIF("clipdetect")
global_ui_config.print_clipping_info = 1;
lame_set_decode_on_the_fly(gfp, 1);
#endif
T_ELIF("nohist")
global_ui_config.brhist = 0;
#if defined(__OS2__) || defined(WIN32)
T_ELIF("priority")
char *endptr;
int priority = (int) strtol(nextArg, &endptr, 10);
if (endptr != nextArg) {
argUsed = 1;
}
setProcessPriority(priority);
#endif
/* options for ID3 tag */
#ifdef ID3TAGS_EXTENDED
T_ELIF2("id3v2-utf16","id3v2-ucs2") /* id3v2-ucs2 for compatibility only */
id3_tenc = TENC_UTF16;
id3tag_add_v2(gfp);
T_ELIF("id3v2-latin1")
id3_tenc = TENC_LATIN1;
id3tag_add_v2(gfp);
#endif
T_ELIF("tt")
argUsed = 1;
id3_tag(gfp, 't', id3_tenc, nextArg);
T_ELIF("ta")
argUsed = 1;
id3_tag(gfp, 'a', id3_tenc, nextArg);
T_ELIF("tl")
argUsed = 1;
id3_tag(gfp, 'l', id3_tenc, nextArg);
T_ELIF("ty")
argUsed = 1;
id3_tag(gfp, 'y', id3_tenc, nextArg);
T_ELIF("tc")
argUsed = 1;
id3_tag(gfp, 'c', id3_tenc, nextArg);
T_ELIF("tn")
int ret = id3_tag(gfp, 'n', id3_tenc, nextArg);
argUsed = 1;
if (ret != 0) {
if (0 == ignore_tag_errors) {
if (id3tag_mode == ID3TAG_MODE_V1_ONLY) {
if (global_ui_config.silent < 9) {
error_printf("The track number has to be between 1 and 255 for ID3v1.\n");
}
return -1;
}
else if (id3tag_mode == ID3TAG_MODE_V2_ONLY) {
/* track will be stored as-is in ID3v2 case, so no problem here */
}
else {
if (global_ui_config.silent < 9) {
error_printf("The track number has to be between 1 and 255 for ID3v1, ignored for ID3v1.\n");
}
}
}
}
T_ELIF("tg")
int ret = id3_tag(gfp, 'g', id3_tenc, nextArg);
argUsed = 1;
if (ret != 0) {
if (0 == ignore_tag_errors) {
if (ret == -1) {
error_printf("Unknown ID3v1 genre number: '%s'.\n", nextArg);
return -1;
}
else if (ret == -2) {
if (id3tag_mode == ID3TAG_MODE_V1_ONLY) {
error_printf("Unknown ID3v1 genre: '%s'.\n", nextArg);
return -1;
}
else if (id3tag_mode == ID3TAG_MODE_V2_ONLY) {
/* genre will be stored as-is in ID3v2 case, so no problem here */
}
else {
if (global_ui_config.silent < 9) {
error_printf("Unknown ID3v1 genre: '%s'. Setting ID3v1 genre to 'Other'\n", nextArg);
}
}
}
else {
if (global_ui_config.silent < 10)
error_printf("Internal error.\n");
return -1;
}
}
}
T_ELIF("tv")
argUsed = 1;
if (id3_tag(gfp, 'v', id3_tenc, nextArg)) {
if (global_ui_config.silent < 9) {
error_printf("Invalid field value: '%s'. Ignored\n", nextArg);
}
}
T_ELIF("ti")
argUsed = 1;
if (set_id3_albumart(gfp, nextArg) != 0) {
if (! ignore_tag_errors) {
return -1;
}
}
T_ELIF("ignore-tag-errors")
ignore_tag_errors = 1;
T_ELIF("add-id3v2")
id3tag_add_v2(gfp);
T_ELIF("id3v1-only")
id3tag_v1_only(gfp);
id3tag_mode = ID3TAG_MODE_V1_ONLY;
T_ELIF("id3v2-only")
id3tag_v2_only(gfp);
id3tag_mode = ID3TAG_MODE_V2_ONLY;
T_ELIF("space-id3v1")
id3tag_space_v1(gfp);
T_ELIF("pad-id3v2")
id3tag_pad_v2(gfp);
T_ELIF("pad-id3v2-size")
int n = atoi(nextArg);
n = n <= 128000 ? n : 128000;
n = n >= 0 ? n : 0;
id3tag_set_pad(gfp, n);
argUsed = 1;
T_ELIF("genre-list")
id3tag_genre_list(genre_list_handler, NULL);
return -2;
T_ELIF("lowpass")
val = atof(nextArg);
argUsed = 1;
if (val < 0) {
lame_set_lowpassfreq(gfp, -1);
}
else {
/* useful are 0.001 kHz...50 kHz, 50 Hz...50000 Hz */
if (val < 0.001 || val > 50000.) {
error_printf("Must specify lowpass with --lowpass freq, freq >= 0.001 kHz\n");
return -1;
}
lame_set_lowpassfreq(gfp, (int) (val * (val < 50. ? 1.e3 : 1.e0) + 0.5));
}
T_ELIF("lowpass-width")
val = atof(nextArg);
argUsed = 1;
/* useful are 0.001 kHz...16 kHz, 16 Hz...50000 Hz */
if (val < 0.001 || val > 50000.) {
error_printf
("Must specify lowpass width with --lowpass-width freq, freq >= 0.001 kHz\n");
return -1;
}
lame_set_lowpasswidth(gfp, (int) (val * (val < 16. ? 1.e3 : 1.e0) + 0.5));
T_ELIF("highpass")
val = atof(nextArg);
argUsed = 1;
if (val < 0.0) {
lame_set_highpassfreq(gfp, -1);
}
else {
/* useful are 0.001 kHz...16 kHz, 16 Hz...50000 Hz */
if (val < 0.001 || val > 50000.) {
error_printf("Must specify highpass with --highpass freq, freq >= 0.001 kHz\n");
return -1;
}
lame_set_highpassfreq(gfp, (int) (val * (val < 16. ? 1.e3 : 1.e0) + 0.5));
}
T_ELIF("highpass-width")
val = atof(nextArg);
argUsed = 1;
/* useful are 0.001 kHz...16 kHz, 16 Hz...50000 Hz */
if (val < 0.001 || val > 50000.) {
error_printf
("Must specify highpass width with --highpass-width freq, freq >= 0.001 kHz\n");
return -1;
}
lame_set_highpasswidth(gfp, (int) val);
T_ELIF("comp")
argUsed = 1;
val = atof(nextArg);
if (val < 1.0) {
error_printf("Must specify compression ratio >= 1.0\n");
return -1;
}
lame_set_compression_ratio(gfp, (float) val);
#if INTERNAL_OPTS
T_ELIF_INTERNAL("notemp")
(void) lame_set_useTemporal(gfp, 0);
T_ELIF_INTERNAL("interch")
argUsed = 1;
(void) lame_set_interChRatio(gfp, (float) atof(nextArg));
T_ELIF_INTERNAL("temporal-masking")
argUsed = 1;
(void) lame_set_useTemporal(gfp, atoi(nextArg) ? 1 : 0);
T_ELIF_INTERNAL("nspsytune")
;
T_ELIF_INTERNAL("nssafejoint")
lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 2);
T_ELIF_INTERNAL("nsmsfix")
argUsed = 1;
(void) lame_set_msfix(gfp, atof(nextArg));
T_ELIF_INTERNAL("ns-bass")
argUsed = 1;
{
double d;
int k;
d = atof(nextArg);
k = (int) (d * 4);
if (k < -32)
k = -32;
if (k > 31)
k = 31;
if (k < 0)
k += 64;
lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | (k << 2));
}
T_ELIF_INTERNAL("ns-alto")
argUsed = 1;
{
double d;
int k;
d = atof(nextArg);
k = (int) (d * 4);
if (k < -32)
k = -32;
if (k > 31)
k = 31;
if (k < 0)
k += 64;
lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | (k << 8));
}
T_ELIF_INTERNAL("ns-treble")
argUsed = 1;
{
double d;
int k;
d = atof(nextArg);
k = (int) (d * 4);
if (k < -32)
k = -32;
if (k > 31)
k = 31;
if (k < 0)
k += 64;
lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | (k << 14));
}
T_ELIF_INTERNAL("ns-sfb21")
/* to be compatible with Naoki's original code,
* ns-sfb21 specifies how to change ns-treble for sfb21 */
argUsed = 1;
{
double d;
int k;
d = atof(nextArg);
k = (int) (d * 4);
if (k < -32)
k = -32;
if (k > 31)
k = 31;
if (k < 0)
k += 64;
lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | (k << 20));
}
#endif
/* some more GNU-ish options could be added
* brief => few messages on screen (name, status report)
* o/output file => specifies output filename
* O => stdout
* i/input file => specifies input filename
* I => stdin
*/
T_ELIF("quiet")
global_ui_config.silent = 10; /* on a scale from 1 to 10 be very silent */
T_ELIF("silent")
global_ui_config.silent = 9;
T_ELIF("brief")
global_ui_config.silent = -5; /* print few info on screen */
T_ELIF("verbose")
global_ui_config.silent = -10; /* print a lot on screen */
T_ELIF2("version", "license")
print_license(stdout);
return -2;
T_ELIF2("help", "usage")
if (0 == local_strncasecmp(nextArg, "id3", 3)) {
help_id3tag(stdout);
}
else if (0 == local_strncasecmp(nextArg, "dev", 3)) {
help_developer_switches(stdout);
}
else {
short_help(gfp, stdout, ProgramName);
}
return -2;
T_ELIF("longhelp")
long_help(gfp, stdout, ProgramName, 0 /* lessmode=NO */ );
return -2;
T_ELIF("?")
#ifdef __unix__
FILE *fp = popen("less -Mqc", "w");
long_help(gfp, fp, ProgramName, 0 /* lessmode=NO */ );
pclose(fp);
#else
long_help(gfp, stdout, ProgramName, 1 /* lessmode=YES */ );
#endif
return -2;
T_ELIF2("preset", "alt-preset")
argUsed = 1;
{
int fast = 0, cbr = 0;
while ((strcmp(nextArg, "fast") == 0) || (strcmp(nextArg, "cbr") == 0)) {
if ((strcmp(nextArg, "fast") == 0) && (fast < 1))
fast = 1;
if ((strcmp(nextArg, "cbr") == 0) && (cbr < 1))
cbr = 1;
argUsed++;
nextArg = i + argUsed < argc ? argv[i + argUsed] : "";
}
if (presets_set(gfp, fast, cbr, nextArg, ProgramName) < 0)
return -1;
}
T_ELIF("disptime")
argUsed = 1;
global_ui_config.update_interval = (float) atof(nextArg);
T_ELIF("nogaptags")
nogap_tags = 1;
T_ELIF("nogapout")
/* FIXME: replace strcpy by safer strncpy */
strcpy(outPath, nextArg);
argUsed = 1;
T_ELIF("out-dir")
/* FIXME: replace strcpy by safer strncpy */
strcpy(outDir, nextArg);
argUsed = 1;
T_ELIF("nogap")
nogap = 1;
T_ELIF("swap-channel")
global_reader.swap_channel = 1;
#if INTERNAL_OPTS
T_ELIF_INTERNAL("tune") /*without helptext */
argUsed = 1;
lame_set_tune(gfp, (float) atof(nextArg));
T_ELIF_INTERNAL("shortthreshold") {
float x, y;
int n = sscanf(nextArg, "%f,%f", &x, &y);
if (n == 1) {
y = x;
}
argUsed = 1;
(void) lame_set_short_threshold(gfp, x, y);
}
T_ELIF_INTERNAL("maskingadjust") /*without helptext */
argUsed = 1;
(void) lame_set_maskingadjust(gfp, (float) atof(nextArg));
T_ELIF_INTERNAL("maskingadjustshort") /*without helptext */
argUsed = 1;
(void) lame_set_maskingadjust_short(gfp, (float) atof(nextArg));
T_ELIF_INTERNAL("athcurve") /*without helptext */
argUsed = 1;
(void) lame_set_ATHcurve(gfp, (float) atof(nextArg));
T_ELIF_INTERNAL("no-preset-tune") /*without helptext */
(void) lame_set_preset_notune(gfp, 0);
T_ELIF_INTERNAL("substep")
argUsed = 1;
(void) lame_set_substep(gfp, atoi(nextArg));
T_ELIF_INTERNAL("sbgain") /*without helptext */
argUsed = 1;
(void) lame_set_subblock_gain(gfp, atoi(nextArg));
T_ELIF_INTERNAL("sfscale") /*without helptext */
(void) lame_set_sfscale(gfp, 1);
T_ELIF_INTERNAL("noath")
(void) lame_set_noATH(gfp, 1);
T_ELIF_INTERNAL("athonly")
(void) lame_set_ATHonly(gfp, 1);
T_ELIF_INTERNAL("athshort")
(void) lame_set_ATHshort(gfp, 1);
T_ELIF_INTERNAL("athlower")
argUsed = 1;
(void) lame_set_ATHlower(gfp, (float) atof(nextArg));
T_ELIF_INTERNAL("athtype")
argUsed = 1;
(void) lame_set_ATHtype(gfp, atoi(nextArg));
T_ELIF_INTERNAL("athaa-type") /* switch for developing, no DOCU */
argUsed = 1; /* once was 1:Gaby, 2:Robert, 3:Jon, else:off */
lame_set_athaa_type(gfp, atoi(nextArg)); /* now: 0:off else:Jon */
#endif
T_ELIF ("athaa-sensitivity")
argUsed=1;
lame_set_athaa_sensitivity(gfp, (float) atof(nextArg));
T_ELIF_INTERNAL("debug-file") /* switch for developing, no DOCU */
argUsed = 1; /* file name to print debug info into */
{
set_debug_file(nextArg);
}
T_ELSE {
error_printf("%s: unrecognized option --%s\n", ProgramName, token);
return -1;
}
T_END i += argUsed;
}
else {
while ((c = *token++) != '\0') {
arg = *token ? token : nextArg;
switch (c) {
case 'm':
argUsed = 1;
switch (*arg) {
case 's':
(void) lame_set_mode(gfp, STEREO);
break;
case 'd':
(void) lame_set_mode(gfp, DUAL_CHANNEL);
break;
case 'f':
lame_set_force_ms(gfp, 1);
/* FALLTHROUGH */
case 'j':
(void) lame_set_mode(gfp, JOINT_STEREO);
break;
case 'm':
(void) lame_set_mode(gfp, MONO);
break;
case 'l':
(void) lame_set_mode(gfp, MONO);
(void) lame_set_scale_left(gfp, 2);
(void) lame_set_scale_right(gfp, 0);
break;
case 'r':
(void) lame_set_mode(gfp, MONO);
(void) lame_set_scale_left(gfp, 0);
(void) lame_set_scale_right(gfp, 2);
break;
case 'a':
(void) lame_set_mode(gfp, JOINT_STEREO);
break;
default:
error_printf("%s: -m mode must be s/d/j/f/m not %s\n", ProgramName,
arg);
return -1;
}
break;
case 'V':
argUsed = 1;
/* to change VBR default look in lame.h */
if (lame_get_VBR(gfp) == vbr_off)
lame_set_VBR(gfp, vbr_default);
lame_set_VBR_quality(gfp, (float)atof(arg));
break;
case 'v':
/* to change VBR default look in lame.h */
if (lame_get_VBR(gfp) == vbr_off)
lame_set_VBR(gfp, vbr_default);
break;
case 'q':
argUsed = 1;
(void) lame_set_quality(gfp, atoi(arg));
break;
case 'f':
(void) lame_set_quality(gfp, 7);
break;
case 'h':
(void) lame_set_quality(gfp, 2);
break;
case 's':
argUsed = 1;
val = atof(arg);
val = (int) (val * (val <= 192 ? 1.e3 : 1.e0) + 0.5);
global_reader.input_samplerate = (int)val;
(void) lame_set_in_samplerate(gfp, (int)val);
break;
case 'b':
argUsed = 1;
lame_set_brate(gfp, atoi(arg));
lame_set_VBR_min_bitrate_kbps(gfp, lame_get_brate(gfp));
break;
case 'B':
argUsed = 1;
lame_set_VBR_max_bitrate_kbps(gfp, atoi(arg));
break;
case 'F':
lame_set_VBR_hard_min(gfp, 1);
break;
case 't': /* dont write VBR tag */
(void) lame_set_bWriteVbrTag(gfp, 0);
global_decoder.disable_wav_header = 1;
break;
case 'T': /* do write VBR tag */
(void) lame_set_bWriteVbrTag(gfp, 1);
nogap_tags = 1;
global_decoder.disable_wav_header = 0;
break;
case 'r': /* force raw pcm input file */
#if defined(LIBSNDFILE)
error_printf
("WARNING: libsndfile may ignore -r and perform fseek's on the input.\n"
"Compile without libsndfile if this is a problem.\n");
#endif
global_reader.input_format = sf_raw;
break;
case 'x': /* force byte swapping */
global_reader.swapbytes = 1;
break;
case 'p': /* (jo) error_protection: add crc16 information to stream */
lame_set_error_protection(gfp, 1);
break;
case 'a': /* autoconvert input file from stereo to mono - for mono mp3 encoding */
autoconvert = 1;
(void) lame_set_mode(gfp, MONO);
break;
case 'd': /*(void) lame_set_allow_diff_short( gfp, 1 ); */
case 'k': /*lame_set_lowpassfreq(gfp, -1);
lame_set_highpassfreq(gfp, -1); */
error_printf("WARNING: -%c is obsolete.\n", c);
break;
case 'S':
global_ui_config.silent = 5;
break;
case 'X':
/* experimental switch -X:
the differnt types of quant compare are tough
to communicate to endusers, so they shouldn't
bother to toy around with them
*/
{
int x, y;
int n = sscanf(arg, "%d,%d", &x, &y);
if (n == 1) {
y = x;
}
argUsed = 1;
if (internal_opts_enabled) {
lame_set_quant_comp(gfp, x);
lame_set_quant_comp_short(gfp, y);
}
}
break;
case 'Y':
lame_set_experimentalY(gfp, 1);
break;
case 'Z':
/* experimental switch -Z:
*/
{
int n = 1;
argUsed = sscanf(arg, "%d", &n);
/*if (internal_opts_enabled)*/
{
lame_set_experimentalZ(gfp, n);
}
}
break;
case 'e':
argUsed = 1;
switch (*arg) {
case 'n':
lame_set_emphasis(gfp, 0);
break;
case '5':
lame_set_emphasis(gfp, 1);
break;
case 'c':
lame_set_emphasis(gfp, 3);
break;
default:
error_printf("%s: -e emp must be n/5/c not %s\n", ProgramName, arg);
return -1;
}
break;
case 'c':
lame_set_copyright(gfp, 1);
break;
case 'o':
lame_set_original(gfp, 0);
break;
case '?':
long_help(gfp, stdout, ProgramName, 0 /* LESSMODE=NO */ );
return -1;
default:
error_printf("%s: unrecognized option -%c\n", ProgramName, c);
return -1;
}
if (argUsed) {
if (arg == token)
token = ""; /* no more from token */
else
++i; /* skip arg we used */
arg = "";
argUsed = 0;
}
}
}
}
else {
if (nogap) {
if ((num_nogap != NULL) && (count_nogap < *num_nogap)) {
strncpy(nogap_inPath[count_nogap++], argv[i], PATH_MAX + 1);
input_file = 1;
}
else {
/* sorry, calling program did not allocate enough space */
error_printf
("Error: 'nogap option'. Calling program does not allow nogap option, or\n"
"you have exceeded maximum number of input files for the nogap option\n");
*num_nogap = -1;
return -1;
}
}
else {
/* normal options: inputfile [outputfile], and
either one can be a '-' for stdin/stdout */
if (inPath[0] == '\0') {
strncpy(inPath, argv[i], PATH_MAX + 1);
input_file = 1;
}
else {
if (outPath[0] == '\0')
strncpy(outPath, argv[i], PATH_MAX + 1);
else {
error_printf("%s: excess arg %s\n", ProgramName, argv[i]);
return -1;
}
}
}
}
} /* loop over args */
if (!input_file) {
usage(Console_IO.Console_fp, ProgramName);
return -1;
}
if (inPath[0] == '-')
global_ui_config.silent = (global_ui_config.silent <= 1 ? 1 : global_ui_config.silent);
#ifdef WIN32
else
dosToLongFileName(inPath);
#endif
if (outPath[0] == '\0' && count_nogap == 0) {
if (inPath[0] == '-') {
/* if input is stdin, default output is stdout */
strcpy(outPath, "-");
}
else {
if (generateOutPath(gfp, inPath, outDir, outPath) != 0) {
return -1;
}
}
}
/* RG is enabled by default */
if (!noreplaygain)
lame_set_findReplayGain(gfp, 1);
/* disable VBR tags with nogap unless the VBR tags are forced */
if (nogap && lame_get_bWriteVbrTag(gfp) && nogap_tags == 0) {
console_printf("Note: Disabling VBR Xing/Info tag since it interferes with --nogap\n");
lame_set_bWriteVbrTag(gfp, 0);
}
/* some file options not allowed with stdout */
if (outPath[0] == '-') {
(void) lame_set_bWriteVbrTag(gfp, 0); /* turn off VBR tag */
}
/* if user did not explicitly specify input is mp3, check file name */
if (global_reader.input_format == sf_unknown)
global_reader.input_format = filename_to_type(inPath);
#if !(defined HAVE_MPGLIB || defined AMIGA_MPEGA)
if (is_mpeg_file_format(global_reader.input_format)) {
error_printf("Error: libmp3lame not compiled with mpg123 *decoding* support \n");
return -1;
}
#endif
/* default guess for number of channels */
if (autoconvert)
(void) lame_set_num_channels(gfp, 2);
else if (MONO == lame_get_mode(gfp))
(void) lame_set_num_channels(gfp, 1);
else
(void) lame_set_num_channels(gfp, 2);
if (lame_get_free_format(gfp)) {
if (lame_get_brate(gfp) < 8 || lame_get_brate(gfp) > 640) {
error_printf("For free format, specify a bitrate between 8 and 640 kbps\n");
error_printf("with the -b <bitrate> option\n");
return -1;
}
}
if (num_nogap != NULL)
*num_nogap = count_nogap;
return 0;
}
/* end of parse.c */
|