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
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="../../img/favicon.ico">
<title> basics - Faust Libraries</title>
<link href="../../css/bootstrap.min.css" rel="stylesheet">
<link href="../../css/font-awesome.min.css" rel="stylesheet">
<link href="../../css/base.css" rel="stylesheet">
<link rel="stylesheet" href="/usr/share/javascript/highlight.js/styles/github.css">
<link href="../../css/extra.css" rel="stylesheet">
<script src="../../js/jquery-3.6.0.min.js" defer></script>
<script src="../../js/bootstrap.min.js" defer></script>
<script src="/usr/share/javascript/highlight.js/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div class="navbar fixed-top navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="../.."><img src="../../img/faustText.svg" width="150px"> </a>
<!-- Expander button -->
<button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbar-collapse">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Expanded navigation -->
<div id="navbar-collapse" class="navbar-collapse collapse">
<!-- Main navigation -->
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">Overview <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a href="../../organization/" class="dropdown-item"> Organization </a>
</li>
<li>
<a href="../../standardFunctions/" class="dropdown-item"> Standard Functions </a>
</li>
<li>
<a href="../../contributing/" class="dropdown-item"> Contributing </a>
</li>
<li>
<a href="../../community/" class="dropdown-item"> Community </a>
</li>
<li>
<a href="../../about/" class="dropdown-item"> Copyright/License </a>
</li>
</ul>
</li>
<li class="navitem">
<a href="../" class="nav-link">Index</a>
</li>
<li class="dropdown active">
<a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">Libraries <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a href="../aanl/" class="dropdown-item"> antialiased </a>
</li>
<li>
<a href="../analyzers/" class="dropdown-item"> analyzers </a>
</li>
<li>
<a href="./" class="dropdown-item active"> basics </a>
</li>
<li>
<a href="../compressors/" class="dropdown-item"> compressors </a>
</li>
<li>
<a href="../delays/" class="dropdown-item"> delays </a>
</li>
<li>
<a href="../demos/" class="dropdown-item"> demos </a>
</li>
<li>
<a href="../dx7/dx7/" class="dropdown-item"> dx7/dx7 </a>
</li>
<li>
<a href="../dx7/env/" class="dropdown-item"> dx7/env </a>
</li>
<li>
<a href="../dx7/lfo/" class="dropdown-item"> dx7/lfo </a>
</li>
<li>
<a href="../dx7/operator/" class="dropdown-item"> dx7/operator </a>
</li>
<li>
<a href="../dx7/pitchenv/" class="dropdown-item"> dx7/pitchenv </a>
</li>
<li>
<a href="../envelopes/" class="dropdown-item"> envelopes </a>
</li>
<li>
<a href="../fds/" class="dropdown-item"> fds </a>
</li>
<li>
<a href="../filters/" class="dropdown-item"> filters </a>
</li>
<li>
<a href="../hoa/" class="dropdown-item"> hoa </a>
</li>
<li>
<a href="../interpolators/" class="dropdown-item"> interpolators </a>
</li>
<li>
<a href="../linearalgebra/" class="dropdown-item"> linearalgebra </a>
</li>
<li>
<a href="../maths/" class="dropdown-item"> maths </a>
</li>
<li>
<a href="../mi/" class="dropdown-item"> mi </a>
</li>
<li>
<a href="../misceffects/" class="dropdown-item"> misceffects </a>
</li>
<li>
<a href="../noises/" class="dropdown-item"> noises </a>
</li>
<li>
<a href="../oscillators/" class="dropdown-item"> oscillators </a>
</li>
<li>
<a href="../phaflangers/" class="dropdown-item"> phaflangers </a>
</li>
<li>
<a href="../physmodels/" class="dropdown-item"> physmodels </a>
</li>
<li>
<a href="../quantizers/" class="dropdown-item"> quantizers </a>
</li>
<li>
<a href="../reducemaps/" class="dropdown-item"> reducemaps </a>
</li>
<li>
<a href="../reverbs/" class="dropdown-item"> reverbs </a>
</li>
<li>
<a href="../routes/" class="dropdown-item"> routes </a>
</li>
<li>
<a href="../signals/" class="dropdown-item"> signals </a>
</li>
<li>
<a href="../soundfiles/" class="dropdown-item"> soundfiles </a>
</li>
<li>
<a href="../spats/" class="dropdown-item"> spats </a>
</li>
<li>
<a href="../synths/" class="dropdown-item"> synths </a>
</li>
<li>
<a href="../vaeffects/" class="dropdown-item"> vaeffects </a>
</li>
<li>
<a href="../version/" class="dropdown-item"> version </a>
</li>
<li>
<a href="../wdmodels/" class="dropdown-item"> wdmodels </a>
</li>
<li>
<a href="../webaudio/" class="dropdown-item"> webaudio </a>
</li>
</ul>
</li>
<li class="navitem">
<a href="../../about/" class="nav-link">About</a>
</li>
</ul>
<ul class="nav navbar-nav ml-auto">
<li class="nav-item">
<a href="#" class="nav-link" data-toggle="modal" data-target="#mkdocs_search_modal">
<i class="fa fa-search"></i> Search
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="row"><div class="col-md-3"><div class="navbar-light navbar-expand-md bs-sidebar hidden-print affix" role="complementary">
<div class="navbar-header">
<button type="button" class="navbar-toggler collapsed" data-toggle="collapse" data-target="#toc-collapse" title="Table of Contents">
<span class="fa fa-angle-down"></span>
</button>
</div>
<div id="toc-collapse" class="navbar-collapse collapse card bg-secondary">
<ul class="nav flex-column">
<li class="nav-item" data-level="1"><a href="#basicslib" class="nav-link">basics.lib</a>
<ul class="nav flex-column">
<li class="nav-item" data-level="2"><a href="#conversion-tools" class="nav-link">Conversion Tools</a>
<ul class="nav flex-column">
<li class="nav-item" data-level="3"><a href="#basamp2sec" class="nav-link">(ba.)samp2sec</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#basec2samp" class="nav-link">(ba.)sec2samp</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#badb2linear" class="nav-link">(ba.)db2linear</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#balinear2db" class="nav-link">(ba.)linear2db</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#balin2loggain" class="nav-link">(ba.)lin2LogGain</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#balog2lingain" class="nav-link">(ba.)log2LinGain</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#batau2pole" class="nav-link">(ba.)tau2pole</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bapole2tau" class="nav-link">(ba.)pole2tau</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bamidikey2hz" class="nav-link">(ba.)midikey2hz</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bahz2midikey" class="nav-link">(ba.)hz2midikey</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#basemi2ratio" class="nav-link">(ba.)semi2ratio</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baratio2semi" class="nav-link">(ba.)ratio2semi</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bacent2ratio" class="nav-link">(ba.)cent2ratio</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baratio2cent" class="nav-link">(ba.)ratio2cent</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bapianokey2hz" class="nav-link">(ba.)pianokey2hz</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bahz2pianokey" class="nav-link">(ba.)hz2pianokey</a>
<ul class="nav flex-column">
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-level="2"><a href="#counters-and-timetempo-tools" class="nav-link">Counters and Time/Tempo Tools</a>
<ul class="nav flex-column">
<li class="nav-item" data-level="3"><a href="#bacounter" class="nav-link">(ba.)counter</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bacountdown" class="nav-link">(ba.)countdown</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bacountup" class="nav-link">(ba.)countup</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#basweep" class="nav-link">(ba.)sweep</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#batime" class="nav-link">(ba.)time</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baramp" class="nav-link">(ba.)ramp</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baline" class="nav-link">(ba.)line</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#batempo" class="nav-link">(ba.)tempo</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baperiod" class="nav-link">(ba.)period</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baspulse" class="nav-link">(ba.)spulse</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bapulse" class="nav-link">(ba.)pulse</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bapulsen" class="nav-link">(ba.)pulsen</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bacycle" class="nav-link">(ba.)cycle</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#babeat" class="nav-link">(ba.)beat</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bapulse_countup" class="nav-link">(ba.)pulse_countup</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bapulse_countdown" class="nav-link">(ba.)pulse_countdown</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bapulse_countup_loop" class="nav-link">(ba.)pulse_countup_loop</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bapulse_countdown_loop" class="nav-link">(ba.)pulse_countdown_loop</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baresetctr" class="nav-link">(ba.)resetCtr</a>
<ul class="nav flex-column">
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-level="2"><a href="#array-processingpattern-matching" class="nav-link">Array Processing/Pattern Matching</a>
<ul class="nav flex-column">
<li class="nav-item" data-level="3"><a href="#bacount" class="nav-link">(ba.)count</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#batake" class="nav-link">(ba.)take</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bapick" class="nav-link">(ba.)pick</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bapickn" class="nav-link">(ba.)pickN</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#basubseq" class="nav-link">(ba.)subseq</a>
<ul class="nav flex-column">
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-level="2"><a href="#function-tabulation" class="nav-link">Function tabulation</a>
<ul class="nav flex-column">
<li class="nav-item" data-level="3"><a href="#batabulate" class="nav-link">(ba.)tabulate</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#batabulate_chebychev" class="nav-link">(ba.)tabulate_chebychev</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#batabulatend" class="nav-link">(ba.)tabulateNd</a>
<ul class="nav flex-column">
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-level="2"><a href="#selectors-conditions" class="nav-link">Selectors (Conditions)</a>
<ul class="nav flex-column">
<li class="nav-item" data-level="3"><a href="#baif" class="nav-link">(ba.)if</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baifnc" class="nav-link">(ba.)ifNc</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baifncno" class="nav-link">(ba.)ifNcNo</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baselector" class="nav-link">(ba.)selector</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baselect2stereo" class="nav-link">(ba.)select2stereo</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baselectn" class="nav-link">(ba.)selectn</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baselectbus" class="nav-link">(ba.)selectbus</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baselectxbus" class="nav-link">(ba.)selectxbus</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baselectmulti" class="nav-link">(ba.)selectmulti</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baselectoutn" class="nav-link">(ba.)selectoutn</a>
<ul class="nav flex-column">
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-level="2"><a href="#other" class="nav-link">Other</a>
<ul class="nav flex-column">
<li class="nav-item" data-level="3"><a href="#balatch" class="nav-link">(ba.)latch</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#basandh" class="nav-link">(ba.)sAndH</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#batandh" class="nav-link">(ba.)tAndH</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#badownsample" class="nav-link">(ba.)downSample</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#badownsamplecv" class="nav-link">(ba.)downSampleCV</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bapeakhold" class="nav-link">(ba.)peakhold</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bapeakholder" class="nav-link">(ba.)peakholder</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bakr2ar" class="nav-link">(ba.)kr2ar</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baimpulsify" class="nav-link">(ba.)impulsify</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baautomat" class="nav-link">(ba.)automat</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#babpf" class="nav-link">(ba.)bpf</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#balistinterp" class="nav-link">(ba.)listInterp</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#babypass1" class="nav-link">(ba.)bypass1</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#babypass2" class="nav-link">(ba.)bypass2</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#babypass1to2" class="nav-link">(ba.)bypass1to2</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#babypass_fade" class="nav-link">(ba.)bypass_fade</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#batoggle" class="nav-link">(ba.)toggle</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baon_and_off" class="nav-link">(ba.)on_and_off</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#babitcrusher" class="nav-link">(ba.)bitcrusher</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#bamulaw_bitcrusher" class="nav-link">(ba.)mulaw_bitcrusher</a>
<ul class="nav flex-column">
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-level="2"><a href="#sliding-reduce" class="nav-link">Sliding Reduce</a>
<ul class="nav flex-column">
<li class="nav-item" data-level="3"><a href="#baslidingreduce" class="nav-link">(ba.)slidingReduce</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baslidingsum" class="nav-link">(ba.)slidingSum</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baslidingsump" class="nav-link">(ba.)slidingSump</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baslidingmax" class="nav-link">(ba.)slidingMax</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baslidingmin" class="nav-link">(ba.)slidingMin</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baslidingmean" class="nav-link">(ba.)slidingMean</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baslidingmeanp" class="nav-link">(ba.)slidingMeanp</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baslidingrms" class="nav-link">(ba.)slidingRMS</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baslidingrmsp" class="nav-link">(ba.)slidingRMSp</a>
<ul class="nav flex-column">
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-level="2"><a href="#parallel-operators" class="nav-link">Parallel Operators</a>
<ul class="nav flex-column">
<li class="nav-item" data-level="3"><a href="#baparallelop" class="nav-link">(ba.)parallelOp</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baparallelmax" class="nav-link">(ba.)parallelMax</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baparallelmin" class="nav-link">(ba.)parallelMin</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baparallelmean" class="nav-link">(ba.)parallelMean</a>
<ul class="nav flex-column">
</ul>
</li>
<li class="nav-item" data-level="3"><a href="#baparallelrms" class="nav-link">(ba.)parallelRMS</a>
<ul class="nav flex-column">
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div></div>
<div class="col-md-9 main-container" role="main">
<h1 id="basicslib">basics.lib</h1>
<p>A library of basic elements. Its official prefix is <code>ba</code>.</p>
<h4 id="references">References</h4>
<ul>
<li><a href="https://github.com/grame-cncm/faustlibraries/blob/master/basics.lib">https://github.com/grame-cncm/faustlibraries/blob/master/basics.lib</a></li>
</ul>
<h2 id="conversion-tools">Conversion Tools</h2>
<hr />
<h3 id="basamp2sec"><code>(ba.)samp2sec</code></h3>
<p>Converts a number of samples to a duration in seconds at the current sampling rate (see <code>ma.SR</code>).
<code>samp2sec</code> is a standard Faust function.</p>
<h4 id="usage">Usage</h4>
<pre><code>samp2sec(n) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: number of samples</li>
</ul>
<hr />
<h3 id="basec2samp"><code>(ba.)sec2samp</code></h3>
<p>Converts a duration in seconds to a number of samples at the current sampling rate (see <code>ma.SR</code>).
<code>samp2sec</code> is a standard Faust function.</p>
<h4 id="usage_1">Usage</h4>
<pre><code>sec2samp(d) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>d</code>: duration in seconds</li>
</ul>
<hr />
<h3 id="badb2linear"><code>(ba.)db2linear</code></h3>
<p>dB-to-linear value converter. It can be used to convert an amplitude in dB to a linear gain ]0-N].
<code>db2linear</code> is a standard Faust function.</p>
<h4 id="usage_2">Usage</h4>
<pre><code>db2linear(l) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>l</code>: amplitude in dB</li>
</ul>
<hr />
<h3 id="balinear2db"><code>(ba.)linear2db</code></h3>
<p>linea-to-dB value converter. It can be used to convert a linear gain ]0-N] to an amplitude in dB.
<code>linear2db</code> is a standard Faust function.</p>
<h4 id="usage_3">Usage</h4>
<pre><code>linear2db(g) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>g</code>: a linear gain</li>
</ul>
<hr />
<h3 id="balin2loggain"><code>(ba.)lin2LogGain</code></h3>
<p>Converts a linear gain (0-1) to a log gain (0-1).</p>
<h4 id="usage_4">Usage</h4>
<pre><code>lin2LogGain(n) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the linear gain</li>
</ul>
<hr />
<h3 id="balog2lingain"><code>(ba.)log2LinGain</code></h3>
<p>Converts a log gain (0-1) to a linear gain (0-1).</p>
<h4 id="usage_5">Usage</h4>
<pre><code>log2LinGain(n) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the log gain</li>
</ul>
<hr />
<h3 id="batau2pole"><code>(ba.)tau2pole</code></h3>
<p>Returns a real pole giving exponential decay.
Note that t60 (time to decay 60 dB) is ~6.91 time constants.
<code>tau2pole</code> is a standard Faust function.</p>
<h4 id="usage_6">Usage</h4>
<pre><code>_ : smooth(tau2pole(tau)) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>tau</code>: time-constant in seconds</li>
</ul>
<hr />
<h3 id="bapole2tau"><code>(ba.)pole2tau</code></h3>
<p>Returns the time-constant, in seconds, corresponding to the given real,
positive pole in (0-1).
<code>pole2tau</code> is a standard Faust function.</p>
<h4 id="usage_7">Usage</h4>
<pre><code>pole2tau(pole) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>pole</code>: the pole</li>
</ul>
<hr />
<h3 id="bamidikey2hz"><code>(ba.)midikey2hz</code></h3>
<p>Converts a MIDI key number to a frequency in Hz (MIDI key 69 = A440).
<code>midikey2hz</code> is a standard Faust function.</p>
<h4 id="usage_8">Usage</h4>
<pre><code>midikey2hz(mk) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>mk</code>: the MIDI key number</li>
</ul>
<hr />
<h3 id="bahz2midikey"><code>(ba.)hz2midikey</code></h3>
<p>Converts a frequency in Hz to a MIDI key number (MIDI key 69 = A440).
<code>hz2midikey</code> is a standard Faust function.</p>
<h4 id="usage_9">Usage</h4>
<pre><code>hz2midikey(freq) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>freq</code>: frequency in Hz</li>
</ul>
<hr />
<h3 id="basemi2ratio"><code>(ba.)semi2ratio</code></h3>
<p>Converts semitones in a frequency multiplicative ratio.
<code>semi2ratio</code> is a standard Faust function.</p>
<h4 id="usage_10">Usage</h4>
<pre><code>semi2ratio(semi) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>semi</code>: number of semitone</li>
</ul>
<hr />
<h3 id="baratio2semi"><code>(ba.)ratio2semi</code></h3>
<p>Converts a frequency multiplicative ratio in semitones.
<code>ratio2semi</code> is a standard Faust function.</p>
<h4 id="usage_11">Usage</h4>
<pre><code>ratio2semi(ratio) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>ratio</code>: frequency multiplicative ratio</li>
</ul>
<hr />
<h3 id="bacent2ratio"><code>(ba.)cent2ratio</code></h3>
<p>Converts cents in a frequency multiplicative ratio.</p>
<h4 id="usage_12">Usage</h4>
<pre><code>cent2ratio(cent) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>cent</code>: number of cents</li>
</ul>
<hr />
<h3 id="baratio2cent"><code>(ba.)ratio2cent</code></h3>
<p>Converts a frequency multiplicative ratio in cents.</p>
<h4 id="usage_13">Usage</h4>
<pre><code>ratio2cent(ratio) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>ratio</code>: frequency multiplicative ratio</li>
</ul>
<hr />
<h3 id="bapianokey2hz"><code>(ba.)pianokey2hz</code></h3>
<p>Converts a piano key number to a frequency in Hz (piano key 49 = A440).</p>
<h4 id="usage_14">Usage</h4>
<pre><code>pianokey2hz(pk) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>pk</code>: the piano key number</li>
</ul>
<hr />
<h3 id="bahz2pianokey"><code>(ba.)hz2pianokey</code></h3>
<p>Converts a frequency in Hz to a piano key number (piano key 49 = A440).</p>
<h4 id="usage_15">Usage</h4>
<pre><code>hz2pianokey(freq) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>freq</code>: frequency in Hz</li>
</ul>
<h2 id="counters-and-timetempo-tools">Counters and Time/Tempo Tools</h2>
<hr />
<h3 id="bacounter"><code>(ba.)counter</code></h3>
<p>Starts counting 0, 1, 2, 3..., and raise the current integer value
at each upfront of the trigger.</p>
<h4 id="usage_16">Usage</h4>
<pre><code>counter(trig) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>trig</code>: the trigger signal, each upfront will move the counter to the next integer</li>
</ul>
<hr />
<h3 id="bacountdown"><code>(ba.)countdown</code></h3>
<p>Starts counting down from n included to 0. While trig is 1 the output is n.
The countdown starts with the transition of trig from 1 to 0. At the end
of the countdown the output value will remain at 0 until the next trig.
<code>countdown</code> is a standard Faust function.</p>
<h4 id="usage_17">Usage</h4>
<pre><code>countdown(n,trig) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the starting point of the countdown</li>
<li><code>trig</code>: the trigger signal (1: start at <code>n</code>; 0: decrease until 0)</li>
</ul>
<hr />
<h3 id="bacountup"><code>(ba.)countup</code></h3>
<p>Starts counting up from 0 to n included. While trig is 1 the output is 0.
The countup starts with the transition of trig from 1 to 0. At the end
of the countup the output value will remain at n until the next trig.
<code>countup</code> is a standard Faust function.</p>
<h4 id="usage_18">Usage</h4>
<pre><code>countup(n,trig) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the maximum count value</li>
<li><code>trig</code>: the trigger signal (1: start at 0; 0: increase until <code>n</code>)</li>
</ul>
<hr />
<h3 id="basweep"><code>(ba.)sweep</code></h3>
<p>Counts from 0 to <code>period-1</code> repeatedly, generating a
sawtooth waveform, like <code>os.lf_rawsaw</code>,
starting at 1 when <code>run</code> transitions from 0 to 1.
Outputs zero while <code>run</code> is 0.</p>
<h4 id="usage_19">Usage</h4>
<pre><code>sweep(period,run) : _
</code></pre>
<hr />
<h3 id="batime"><code>(ba.)time</code></h3>
<p>A simple counter that produces the sequence of 0,1,2...N integer values.
<code>time</code> is a standard Faust function.</p>
<h4 id="usage_20">Usage</h4>
<pre><code>time : _
</code></pre>
<hr />
<h3 id="baramp"><code>(ba.)ramp</code></h3>
<p>A linear ramp with a slope of '(+/-)1/n' samples to reach the next target value.</p>
<h4 id="usage_21">Usage</h4>
<pre><code>_ : ramp(n) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: number of samples to increment/decrement the value by one</li>
</ul>
<hr />
<h3 id="baline"><code>(ba.)line</code></h3>
<p>A ramp interpolator that generates a linear transition to reach a target value:</p>
<ul>
<li>the interpolation process restarts each time a new and distinct input value is received</li>
<li>it utilizes 'n' samples to achieve the transition to the target value</li>
<li>after reaching the target value, the output value is maintained.</li>
</ul>
<h4 id="usage_22">Usage</h4>
<pre><code>_ : line(n) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: number of samples to reach the new target received at its input</li>
</ul>
<hr />
<h3 id="batempo"><code>(ba.)tempo</code></h3>
<p>Converts a tempo in BPM into a number of samples.</p>
<h4 id="usage_23">Usage</h4>
<pre><code>tempo(t) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>t</code>: tempo in BPM</li>
</ul>
<hr />
<h3 id="baperiod"><code>(ba.)period</code></h3>
<p>Basic sawtooth wave of period <code>p</code>.</p>
<h4 id="usage_24">Usage</h4>
<pre><code>period(p) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>p</code>: period as a number of samples</li>
</ul>
<hr />
<h3 id="baspulse"><code>(ba.)spulse</code></h3>
<p>Produces a single pulse of n samples when trig goes from 0 to 1.</p>
<h4 id="usage_25">Usage</h4>
<pre><code>spulse(n,trig) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: pulse length as a number of samples</li>
<li><code>trig</code>: the trigger signal (1: start the pulse)</li>
</ul>
<hr />
<h3 id="bapulse"><code>(ba.)pulse</code></h3>
<p>Pulses (like 10000) generated at period <code>p</code>.</p>
<h4 id="usage_26">Usage</h4>
<pre><code>pulse(p) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>p</code>: period as a number of samples</li>
</ul>
<hr />
<h3 id="bapulsen"><code>(ba.)pulsen</code></h3>
<p>Pulses (like 11110000) of length <code>n</code> generated at period <code>p</code>.</p>
<h4 id="usage_27">Usage</h4>
<pre><code>pulsen(n,p) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: pulse length as a number of samples</li>
<li><code>p</code>: period as a number of samples</li>
</ul>
<hr />
<h3 id="bacycle"><code>(ba.)cycle</code></h3>
<p>Split nonzero input values into <code>n</code> cycles.</p>
<h4 id="usage_28">Usage</h4>
<pre><code>_ : cycle(n) : si.bus(n)
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the number of cycles/output signals</li>
</ul>
<hr />
<h3 id="babeat"><code>(ba.)beat</code></h3>
<p>Pulses at tempo <code>t</code> in BPM.
<code>beat</code> is a standard Faust function.</p>
<h4 id="usage_29">Usage</h4>
<pre><code>beat(t) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>t</code>: tempo in BPM</li>
</ul>
<hr />
<h3 id="bapulse_countup"><code>(ba.)pulse_countup</code></h3>
<p>Starts counting up pulses. While trig is 1 the output is
counting up, while trig is 0 the counter is reset to 0.</p>
<h4 id="usage_30">Usage</h4>
<pre><code>_ : pulse_countup(trig) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>trig</code>: the trigger signal (1: start at next pulse; 0: reset to 0)</li>
</ul>
<hr />
<h3 id="bapulse_countdown"><code>(ba.)pulse_countdown</code></h3>
<p>Starts counting down pulses. While trig is 1 the output is
counting down, while trig is 0 the counter is reset to 0.</p>
<h4 id="usage_31">Usage</h4>
<pre><code>_ : pulse_countdown(trig) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>trig</code>: the trigger signal (1: start at next pulse; 0: reset to 0)</li>
</ul>
<hr />
<h3 id="bapulse_countup_loop"><code>(ba.)pulse_countup_loop</code></h3>
<p>Starts counting up pulses from 0 to n included. While trig is 1 the output is
counting up, while trig is 0 the counter is reset to 0. At the end
of the countup (n) the output value will be reset to 0.</p>
<h4 id="usage_32">Usage</h4>
<pre><code>_ : pulse_countup_loop(n,trig) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the highest number of the countup (included) before reset to 0</li>
<li><code>trig</code>: the trigger signal (1: start at next pulse; 0: reset to 0)</li>
</ul>
<hr />
<h3 id="bapulse_countdown_loop"><code>(ba.)pulse_countdown_loop</code></h3>
<p>Starts counting down pulses from 0 to n included. While trig is 1 the output
is counting down, while trig is 0 the counter is reset to 0. At the end
of the countdown (n) the output value will be reset to 0.</p>
<h4 id="usage_33">Usage</h4>
<pre><code>_ : pulse_countdown_loop(n,trig) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the highest number of the countup (included) before reset to 0</li>
<li><code>trig</code>: the trigger signal (1: start at next pulse; 0: reset to 0)</li>
</ul>
<hr />
<h3 id="baresetctr"><code>(ba.)resetCtr</code></h3>
<p>Function that lets through the mth impulse out of
each consecutive group of <code>n</code> impulses.</p>
<h4 id="usage_34">Usage</h4>
<pre><code>_ : resetCtr(n,m) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the total number of impulses being split</li>
<li><code>m</code>: index of impulse to allow to be output</li>
</ul>
<h2 id="array-processingpattern-matching">Array Processing/Pattern Matching</h2>
<hr />
<h3 id="bacount"><code>(ba.)count</code></h3>
<p>Count the number of elements of list l.
<code>count</code> is a standard Faust function.</p>
<h4 id="usage_35">Usage</h4>
<pre><code>count(l)
count((10,20,30,40)) -> 4
</code></pre>
<p>Where:</p>
<ul>
<li><code>l</code>: list of elements</li>
</ul>
<hr />
<h3 id="batake"><code>(ba.)take</code></h3>
<p>Take an element from a list.
<code>take</code> is a standard Faust function.</p>
<h4 id="usage_36">Usage</h4>
<pre><code>take(P,l)
take(3,(10,20,30,40)) -> 30
</code></pre>
<p>Where:</p>
<ul>
<li><code>P</code>: position (int, known at compile time, P > 0)</li>
<li><code>l</code>: list of elements</li>
</ul>
<hr />
<h3 id="bapick"><code>(ba.)pick</code></h3>
<p>Pick the nth element from a list.
Similar to <code>ba.take(n+1,l)</code> but faster and more powerful.</p>
<h4 id="usage_37">Usage</h4>
<pre><code>pick(l,n) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>l</code>: list of elements</li>
<li><code>n</code>: index of element to pick, compile time constant.
if n < 0 or n >= length of <code>l</code>, <code>pick()</code> outputs 0.</li>
</ul>
<h4 id="example-test-program">Example test program</h4>
<pre><code>pick((10,20,30,40), 2) -> 30
</code></pre>
<pre><code>pick(si.bus(3), 1) // same as !,_,!
</code></pre>
<p>while <code>ba.take(2, si.bus(3))</code> acts as <code>_</code>.</p>
<p>Unlike <code>take()</code>, <code>pick()</code> always flattens the list, so
<code>pick((10,(20,30),40), 1)</code> outputs <code>20</code>, not <code>20,30</code>.</p>
<hr />
<h3 id="bapickn"><code>(ba.)pickN</code></h3>
<p>Select the inputs listed in <code>O</code> among <code>N</code> at compile time.</p>
<h4 id="usage_38">Usage</h4>
<pre><code>si.bus(N) : pickN(N,O) : si.bus(outputs(O))
</code></pre>
<p>Where:</p>
<ul>
<li><code>N</code>: number of inputs, compile time constant</li>
<li><code>O</code>: list of the inputs to select, compile time constants</li>
</ul>
<h4 id="example-test-program_1">Example test program</h4>
<pre><code>pickN(4,2) : _ // same as selector(2,4) but faster
</code></pre>
<pre><code>pick(4,(1,3)) : _,_ // same as !,_,!,_
</code></pre>
<pre><code>pickN(4,(1,3), (10,20,30,40)) -> (20,40)
</code></pre>
<pre><code>process = pickN(2, (1,0,0,1)) // same as `process(x,y) = y,x,x,y`
</code></pre>
<hr />
<h3 id="basubseq"><code>(ba.)subseq</code></h3>
<p>Extract a part of a list.</p>
<h4 id="usage_39">Usage</h4>
<pre><code>subseq(l, P, N)
subseq((10,20,30,40,50,60), 1, 3) -> (20,30,40)
subseq((10,20,30,40,50,60), 4, 1) -> 50
</code></pre>
<p>Where:</p>
<ul>
<li><code>l</code>: list</li>
<li><code>P</code>: start point (int, known at compile time, 0: begin of list)</li>
<li><code>N</code>: number of elements (int, known at compile time)</li>
</ul>
<h4 id="note">Note:</h4>
<p>Faust doesn't have proper lists. Lists are simulated with parallel
compositions and there is no empty list.</p>
<h2 id="function-tabulation">Function tabulation</h2>
<p>The purpose of function tabulation is to speed up the computation of heavy functions over an interval,
so that the computation at runtime can be faster than directly using the function.
Two techniques are implemented: </p>
<ul>
<li>
<p><code>tabulate</code> computes the function in a table and read the points using interpolation. <code>tabulateNd</code> is the N dimensions version of <code>tabulate</code></p>
</li>
<li>
<p><code>tabulate_chebychev</code> uses Chebyshev polynomial approximation</p>
</li>
</ul>
<h4 id="comparison-program-example">Comparison program example</h4>
<pre><code>process = line(50000, r0, r1) <: FX-tb,FX-ch : par(i, 2, maxerr)
with {
C = 0;
FX = sin;
NX = 50;
CD = 3;
r0 = 0;
r1 = ma.PI;
tb(x) = ba.tabulate(C, FX, NX*(CD+1), r0, r1, x).cub;
ch(x) = ba.tabulate_chebychev(C, FX, NX, CD, r0, r1, x);
maxerr = abs : max ~ _;
line(n, x0, x1) = x0 + (ba.time%n)/n * (x1-x0);
};
</code></pre>
<hr />
<h3 id="batabulate"><code>(ba.)tabulate</code></h3>
<p>Tabulate a 1D function over the range [r0, r1] for access via nearest-value, linear, cubic interpolation.
In other words, the uniformly tabulated function can be evaluated using interpolation of order 0 (none), 1 (linear), or 3 (cubic).</p>
<h4 id="usage_40">Usage</h4>
<pre><code>tabulate(C, FX, S, r0, r1, x).(val|lin|cub) : _
</code></pre>
<ul>
<li><code>C</code>: whether to dynamically force the <code>x</code> value to the range [r0, r1]: 1 forces the check, 0 deactivates it (constant numerical expression)</li>
<li><code>FX</code>: unary function Y=F(X) with one output (scalar function of one variable) </li>
<li><code>S</code>: size of the table in samples (constant numerical expression)</li>
<li><code>r0</code>: minimum value of argument x</li>
<li><code>r1</code>: maximum value of argument x</li>
</ul>
<pre><code>tabulate(C, FX, S, r0, r1, x).val uses the value in the table closest to x
</code></pre>
<pre><code>tabulate(C, FX, S, r0, r1, x).lin evaluates at x using linear interpolation between the closest stored values
</code></pre>
<pre><code>tabulate(C, FX, S, r0, r1, x).cub evaluates at x using cubic interpolation between the closest stored values
</code></pre>
<h4 id="example-test-program_2">Example test program</h4>
<pre><code>midikey2hz(mk) = ba.tabulate(1, ba.midikey2hz, 512, 0, 127, mk).lin;
process = midikey2hz(ba.time), ba.midikey2hz(ba.time);
</code></pre>
<hr />
<h3 id="batabulate_chebychev"><code>(ba.)tabulate_chebychev</code></h3>
<p>Tabulate a 1D function over the range [r0, r1] for access via Chebyshev polynomial approximation.
In contrast to <code>(ba.)tabulate</code>, which interpolates only between tabulated samples, <code>(ba.)tabulate_chebychev</code>
stores coefficients of Chebyshev polynomials that are evaluated to provide better approximations in many cases.
Two new arguments controlling this are NX, the number of segments into which [r0, r1] is divided, and CD,
the maximum Chebyshev polynomial degree to use for each segment. A <code>rdtable</code> of size NX*(CD+1) is internally used.</p>
<p>Note that processing <code>r1</code> the last point in the interval is not safe. So either be sure the input stays in [r0, r1[
or use <code>C = 1</code>.</p>
<h4 id="usage_41">Usage</h4>
<pre><code>_ : tabulate_chebychev(C, FX, NX, CD, r0, r1) : _
</code></pre>
<ul>
<li><code>C</code>: whether to dynamically force the value to the range [r0, r1]: 1 forces the check, 0 deactivates it (constant numerical expression)</li>
<li><code>FX</code>: unary function Y=F(X) with one output (scalar function of one variable)</li>
<li><code>NX</code>: number of segments for uniformly partitioning [r0, r1] (constant numerical expression)</li>
<li><code>CD</code>: maximum polynomial degree for each Chebyshev polynomial (constant numerical expression)</li>
<li><code>r0</code>: minimum value of argument x</li>
<li><code>r1</code>: maximum value of argument x</li>
</ul>
<h4 id="example-test-program_3">Example test program</h4>
<pre><code>midikey2hz_chebychev(mk) = ba.tabulate_chebychev(1, ba.midikey2hz, 100, 4, 0, 127, mk);
process = midikey2hz_chebychev(ba.time), ba.midikey2hz(ba.time);
</code></pre>
<hr />
<h3 id="batabulatend"><code>(ba.)tabulateNd</code></h3>
<p>Tabulate an nD function for access via nearest-value or linear or cubic interpolation. In other words, the tabulated function can be evaluated using interpolation of order 0 (none), 1 (linear), or 3 (cubic). </p>
<p>The table size and parameter range of each dimension can and must be separately specified. You can use it anywhere you have an expensive function with multiple parameters with known ranges. You could use it to build a wavetable synth, for example.</p>
<p>The number of dimensions is deduced from the number of parameters you give, see below.</p>
<p>Note that processing the last point in each interval is not safe. So either be sure the inputs stay in their respective ranges, or use <code>C = 1</code>. Similarly for the first point when doing cubic interpolation.</p>
<h4 id="usage_42">Usage</h4>
<pre><code>tabulateNd(C, function, (parameters) ).(val|lin|cub) : _
</code></pre>
<ul>
<li><code>C</code>: whether to dynamically force the parameter values for each dimension to the ranges specified in parameters: 1 forces the check, 0 deactivates it (constant numerical expression)</li>
<li><code>function</code>: the function we want to tabulate. Can have any number of inputs, but needs to have just one output.</li>
<li><code>(parameters)</code>: sizes, ranges and read values. Note: these need to be in brackets, to make them one entity. </li>
</ul>
<p>If N is the number of dimensions, we need:</p>
<ul>
<li>N times <code>S</code>: number of values to store for this dimension (constant numerical expression)</li>
<li>N times <code>r0</code>: minimum value of this dimension</li>
<li>N times <code>r1</code>: maximum value of this dimension</li>
<li>N times <code>x</code>: read value of this dimension</li>
</ul>
<p>By providing these parameters, you indirectly specify the number of dimensions; it's the number of parameters divided by 4.</p>
<p>The user facing functions are:</p>
<pre><code>tabulateNd(C, function, S, parameters).val
</code></pre>
<ul>
<li>Uses the value in the table closest to x.</li>
</ul>
<pre><code>tabulateNd(C, function, S, parameters).lin
</code></pre>
<ul>
<li>Evaluates at x using linear interpolation between the closest stored values.</li>
</ul>
<pre><code>tabulateNd(C, function, S, parameters).cub
</code></pre>
<ul>
<li>Evaluates at x using cubic interpolation between the closest stored values.</li>
</ul>
<h4 id="example-test-program_4">Example test program</h4>
<pre><code class="language-faust">powSin(x,y) = sin(pow(x,y)); // The function we want to tabulate
powSinTable(x,y) = ba.tabulateNd(1, powSin, (sizeX,sizeY, rx0,ry0, rx1,ry1, x,y) ).lin;
sizeX = 512; // table size of the first parameter
sizeY = 512; // table size of the second parameter
rx0 = 2; // start of the range of the first parameter
ry0 = 2; // start of the range of the second parameter
rx1 = 10; // end of the range of the first parameter
ry1 = 10; // end of the range of the second parameter
x = hslider("x", rx0, rx0, rx1, 0.001):si.smoo;
y = hslider("y", ry0, ry0, ry1, 0.001):si.smoo;
process = powSinTable(x,y), powSin(x,y);
</code></pre>
<h4 id="working-principle">Working principle</h4>
<p>The <code>.val</code> function just outputs the closest stored value.
The <code>.lin</code> and <code>.cub</code> functions interpolate in N dimensions.</p>
<h5 id="multi-dimensional-interpolation">Multi dimensional interpolation</h5>
<p>To understand what it means to interpolate in N dimensions, here's a quick reminder on the general principle of 2D linear interpolation:</p>
<ul>
<li>We have a grid of values, and we want to find the value at a point (x, y) within this grid. </li>
<li>We first find the four closest points (A, B, C, D) in the grid surrounding the point (x, y). </li>
</ul>
<p>Then, we perform linear interpolation in the x-direction between points A and B, and between points C and D. This gives us two new points E and F. Finally, we perform linear interpolation in the y-direction between points E and F to get our value.</p>
<p>To implement this in Faust, we need N sequential groups of interpolators, where N is the number of dimensions.<br />
Each group feeds into the next, with the last "group" being a single interpolator, and the group before it containing one interpolator for each input of the group it's feeding.</p>
<p>Some examples:</p>
<ul>
<li>Our 2D linear example has two interpolators feeding into one.</li>
<li>A 3D linear interpolator has four interpolators feeding into two, feeding into one.</li>
<li>A 2D cubic interpolater has four interpolators feeding into one.</li>
<li>A 3D cubic interpolator has sixteen interpolators feeding into four, feeding into one.</li>
</ul>
<p>To understand which values we need to look up, let's consider the 2D linear example again.
The four values going into the first group represent the four closest points (A, B, C, D) mentioned above.</p>
<p>1) The first interpolator gets:</p>
<ul>
<li>The closest value that is stored (A)</li>
<li>The next value in the x dimension, keeping y fixed (B)</li>
</ul>
<p>2) The second interpolator gets:</p>
<ul>
<li>One step over in the y dimension, keeping x fixed (C)</li>
<li>One step over in both the x dimension and the y dimension (D)</li>
</ul>
<p>The outputs of these two interpolators are points E and F.
In other words: the interpolated x values and, respectively, the following y values:</p>
<ul>
<li>The closest stored value of the y dimension</li>
<li>One step forward in the y dimension</li>
</ul>
<p>The last interpolator takes these two values and interpolates them in the y dimension.</p>
<p>To generalize for N dimensions and linear interpolation:</p>
<ul>
<li>The first group has 2^(n-1) parallel interpolators interpolating in the first dimension.</li>
<li>The second group has 2^(n-2) parallel interpolators interpolating in the second dimension.</li>
<li>The process continues until the n-th group, which has a single interpolator interpolating in the n-th dimension.</li>
</ul>
<p>The same principle applies to the cubic interpolation in nD. The only difference is that there would be 4^(n-1) parallel interpolators in the first group, compared to 2^(n-1) for linear interpolation.</p>
<p>This is what the <code>mixers</code> function does.</p>
<p>Besides the values, each interpolator also needs to know the weight of each value in it's output.<br />
Let's call this <code>d</code>, like in <code>ba.interpolate</code>. It is the same for each group of interpolators, since it correlates to a dimension.<br />
It's value is calculated the similarly to <code>ba.interpolate</code>:</p>
<ul>
<li>First we prepare a "float table read-index" for that dimension (<code>id</code> in <code>ba.tabulate</code>)</li>
<li>If the table only had that dimension and it could read a float index, what would it be.</li>
<li>Then we <code>int</code> the float index to get the value we have stored that is closest to, but lower than the input value; the actual index for that dimension.
Our <code>d</code> is the difference between the float index and the actual index.</li>
</ul>
<p>The <code>ids</code> function calculates the <code>id</code> for each dimension and inside the <code>mixer</code> function they get turned into <code>d</code>s.</p>
<h5 id="storage-method">Storage method</h5>
<p>The elephant in the room is: how do we get these indexes? For that we need to know how the values are stored.
We use one big table to store everything.</p>
<p>To understand the concept, let's look at the 2D example again, and then we'll extend it to 3d and the general nD case.</p>
<p>Let's say we have a 2D table with dimensions A and B where:
A has 3 values between 0 and 5 and B has 4 values between 0 and 1.
The 1D array representation of this 2D table will have a size of 3 * 4 = 12.</p>
<p>The values are stored in the following way:</p>
<ul>
<li>First 3 values: A is 0, then 3, then 5 while B is at 0.</li>
<li>Next 3 values: A changes from 0 to 5 while B is at 1/3.</li>
<li>Next 3 values: A changes from 0 to 5 while B is at 2/3.</li>
<li>Last 3 values: A changes from 0 to 5 while B is at 1.</li>
</ul>
<p>For the 3D example, let's extend the 2D example with an additional dimension C having 2 values between 0 and 2.
The total size will be 3 * 4 * 2 = 24.</p>
<p>The values are stored like so:</p>
<ul>
<li>First 3 values: A changes from 0 to 5, B is at 0, and C is at 0.</li>
<li>Next 3 values: A changes from 0 to 5, B is at 1/3, and C is at 0.</li>
<li>Next 3 values: A changes from 0 to 5, B is at 2/3, and C is at 0.</li>
<li>Next 3 values: A changes from 0 to 5, B is at 1, and C is at 0.</li>
</ul>
<p>The last 12 values are the same as the first 12, but with C at 2.</p>
<p>For the general n-dimensional case, we iterate through all dimensions, changing the values of the innermost dimension first, then moving towards the outer dimensions.</p>
<h5 id="read-indexes">Read indexes</h5>
<p>To get the float read index (<code>id</code>) corresponding to a particular dimension, we scale the function input value to be between 0 and 1, and multiply it by the size of that dimension minus one.</p>
<p>To understand how we get the <code>readIndex</code>for <code>.val</code>, let's work trough how we'd do it in our 2D linear example.<br />
For simplicity's sake, the ranges of the inputs to our <code>function</code> are both 0 to 1.<br />
Say we wanted to read the value closest to <code>x=0.5</code> and <code>y=0</code>, so the <code>id</code> of <code>x</code> is <code>1</code> (the second value) and the <code>id</code> of <code>y</code> is 0 (first value). In this case, the read index is just the <code>id</code> of <code>x</code>, rounded to the nearest integer, just like in <code>ba.tabulate</code>.</p>
<p>If we want to read the value belonging to <code>x=0.5</code> and <code>y=2/3</code>, things get more complicated. The <code>id</code> for <code>y</code> is now <code>2</code>, the third value. For each step in the <code>y</code> direction, we need to increase the index by <code>3</code>, the number of values that are stored for <code>x</code>. So the influence of the <code>y</code> is: the size of <code>x</code> times the rounded <code>id</code> of <code>y</code>. The final read index is the rounded <code>id</code> of <code>x</code> plus the influence of <code>y</code>.</p>
<p>For the general nD case, we need to do the same operation N times, each feeding into the next. This operation is the <code>riN</code> function. We take four parameters: the size of the dimension before it <code>prevSize</code>, the index of the previous dimension <code>prevIX</code>, the current size <code>sizeX</code> and the current id <code>idX</code>. <code>riN</code> has 2 outputs, the size, for feeding into the next dimension's <code>prevSize</code>, and the read index feeding into the next dimension's <code>prevIX</code>.<br />
The size is the <code>sizeX</code> times <code>prevSize</code>. The read index is the rounded <code>idX</code> times <code>prevSize</code> added to the <code>prevIX</code>. Our final <code>readIndex</code> is the read index output of the last dimension.</p>
<p>To get the read values for the interpolators need a pattern of offsets in each dimension, since we are looking for the read indexes surrounding the point of interest. These offsets are best explained by looking at the code of <code>tabulate2d</code>, the hardcoded 2D version:</p>
<pre><code class="language-faust">tabulate2d(C,function, sizeX,sizeY, rx0,ry0, rx1,ry1, x,y) =
environment {
size = sizeX*sizeY;
// Maximum X index to access
midX = sizeX-1;
// Maximum Y index to access
midY = sizeY-1;
// Maximum total index to access
mid = size-1;
// Create the table
wf = function(wfX,wfY);
// Prepare the 'float' table read index for X
idX = (x-rx0)/(rx1-rx0)*midX;
// Prepare the 'float' table read index for Y
idY = ((y-ry0)/(ry1-ry0))*midY;
// table creation X:
wfX =
rx0+float(ba.time%sizeX)*(rx1-rx0)
/float(midX);
// table creation Y:
wfY =
ry0+
((float(ba.time-(ba.time%sizeX))
/float(sizeX))
*(ry1-ry0))
/float(midY);
// Limit the table read index in [0, mid] if C = 1
rid(x,mid, 0) = x;
rid(x,mid, 1) = max(0, min(x, mid));
// Tabulate a binary 'FX' function on a range [rx0, rx1] [ry0, ry1]
val(x,y) =
rdtable(size, wf, readIndex);
readIndex =
rid(
rid(int(idX+0.5),midX, C)
+yOffset
, mid, C);
yOffset = sizeX*rid(int(idY),midY,C);
// Tabulate a binary 'FX' function over the range [rx0, rx1] [ry0, ry1] with linear interpolation
lin =
it.interpolate_linear(
dy
, it.interpolate_linear(dx,v0,v1)
, it.interpolate_linear(dx,v2,v3))
with {
i0 = rid(int(idX), midX, C)+yOffset;
i1 = i0+1;
i2 = i0+sizeX;
i3 = i1+sizeX;
dx = idX-int(idX);
dy = idY-int(idY);
v0 = rdtable(size, wf, rid(i0, mid, C));
v1 = rdtable(size, wf, rid(i1, mid, C));
v2 = rdtable(size, wf, rid(i2, mid, C));
v3 = rdtable(size, wf, rid(i3, mid, C));
};
// Tabulate a binary 'FX' function over the range [rx0, rx1] [ry0, ry1] with cubic interpolation
cub =
it.interpolate_cubic(
dy
, it.interpolate_cubic(dx,v0,v1,v2,v3)
, it.interpolate_cubic(dx,v4,v5,v6,v7)
, it.interpolate_cubic(dx,v8,v9,v10,v11)
, it.interpolate_cubic(dx,v12,v13,v14,v15)
)
with {
i0 = i4-sizeX;
i1 = i5-sizeX;
i2 = i6-sizeX;
i3 = i7-sizeX;
i4 = i5-1;
i5 = rid(int(idX), midX, C)+yOffset;
i6 = i5+1;
i7 = i6+1;
i8 = i4+sizeX;
i9 = i5+sizeX;
i10 = i6+sizeX;
i11 = i7+sizeX;
i12 = i4+(2*sizeX);
i13 = i5+(2*sizeX);
i14 = i6+(2*sizeX);
i15 = i7+(2*sizeX);
dx = idX-int(idX);
dy = idY-int(idY);
v0 = rdtable(size, wf, rid(i0 , mid, C));
v1 = rdtable(size, wf, rid(i1 , mid, C));
v2 = rdtable(size, wf, rid(i2 , mid, C));
v3 = rdtable(size, wf, rid(i3 , mid, C));
v4 = rdtable(size, wf, rid(i4 , mid, C));
v5 = rdtable(size, wf, rid(i5 , mid, C));
v6 = rdtable(size, wf, rid(i6 , mid, C));
v7 = rdtable(size, wf, rid(i7 , mid, C));
v8 = rdtable(size, wf, rid(i8 , mid, C));
v9 = rdtable(size, wf, rid(i9 , mid, C));
v10 = rdtable(size, wf, rid(i10, mid, C));
v11 = rdtable(size, wf, rid(i11, mid, C));
v12 = rdtable(size, wf, rid(i12, mid, C));
v13 = rdtable(size, wf, rid(i13, mid, C));
v14 = rdtable(size, wf, rid(i14, mid, C));
v15 = rdtable(size, wf, rid(i15, mid, C));
};
};
</code></pre>
<p>In the interest of brevity, we'll stop explaining here. If you have any more questions, feel free to open an issue on <a href="https://github.com/grame-cncm/faustlibraries">faustlibraries</a> and tag @magnetophon.</p>
<h2 id="selectors-conditions">Selectors (Conditions)</h2>
<hr />
<h3 id="baif"><code>(ba.)if</code></h3>
<p>if-then-else implemented with a select2. WARNING: since <code>select2</code> is strict (always evaluating both branches),
the resulting if does not have the usual "lazy" semantic of the C if form, and thus cannot be used to
protect against forbidden computations like division-by-zero for instance.</p>
<h4 id="usage_43">Usage</h4>
<ul>
<li><code>if(cond, then, else) : _</code></li>
</ul>
<p>Where:</p>
<ul>
<li><code>cond</code>: condition</li>
<li><code>then</code>: signal selected while cond is true</li>
<li><code>else</code>: signal selected while cond is false</li>
</ul>
<hr />
<h3 id="baifnc"><code>(ba.)ifNc</code></h3>
<p>if-then-elseif-then-...elsif-then-else implemented on top of <code>ba.if</code>.</p>
<h4 id="usage_44">Usage</h4>
<pre><code> ifNc((cond1,then1, cond2,then2, ... condN,thenN, else)) : _
or
ifNc(Nc, cond1,then1, cond2,then2, ... condN,thenN, else) : _
or
cond1,then1, cond2,then2, ... condN,thenN, else : ifNc(Nc) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>Nc</code> : number of branches/conditions (constant numerical expression)</li>
<li><code>condX</code>: condition</li>
<li><code>thenX</code>: signal selected if condX is the 1st true condition</li>
<li><code>else</code>: signal selected if all the cond1-condN conditions are false</li>
</ul>
<h4 id="example-test-program_5">Example test program</h4>
<pre><code> process(x,y) = ifNc((x<y,-1, x>y,+1, 0));
or
process(x,y) = ifNc(2, x<y,-1, x>y,+1, 0);
or
process(x,y) = x<y,-1, x>y,+1, 0 : ifNc(2);
</code></pre>
<p>outputs <code>-1</code> if <code>x<y</code>, <code>+1</code> if <code>x>y</code>, <code>0</code> otherwise.</p>
<hr />
<h3 id="baifncno"><code>(ba.)ifNcNo</code></h3>
<p><code>ifNcNo(Nc,No)</code> is similar to <code>ifNc(Nc)</code> above but then/else branches have <code>No</code> outputs.</p>
<h4 id="usage_45">Usage</h4>
<pre><code> ifNcNo(Nc,No, cond1,then1, cond2,then2, ... condN,thenN, else) : sig.bus(No)
</code></pre>
<p>Where:</p>
<ul>
<li><code>Nc</code> : number of branches/conditions (constant numerical expression)</li>
<li><code>No</code> : number of outputs (constant numerical expression)</li>
<li><code>condX</code>: condition</li>
<li><code>thenX</code>: list of No signals selected if condX is the 1st true condition</li>
<li><code>else</code>: list of No signals selected if all the cond1-condN conditions are false</li>
</ul>
<h4 id="example-test-program_6">Example test program</h4>
<pre><code> process(x) = ifNcNo(2,3, x<0, -1,-1,-1, x>0, 1,1,1, 0,0,0);
</code></pre>
<p>outputs <code>-1,-1,-1</code> if <code>x<0</code>, <code>1,1,1</code> if <code>x>0</code>, <code>0,0,0</code> otherwise.</p>
<hr />
<h3 id="baselector"><code>(ba.)selector</code></h3>
<p>Selects the ith input among n at compile time.</p>
<h4 id="usage_46">Usage</h4>
<pre><code>selector(I,N)
_,_,_,_ : selector(2,4) : _ // selects the 3rd input among 4
</code></pre>
<p>Where:</p>
<ul>
<li><code>I</code>: input to select (int, numbered from 0, known at compile time)</li>
<li><code>N</code>: number of inputs (int, known at compile time, N > I)</li>
</ul>
<p>There is also <code>cselector</code> for selecting among complex input signals of the form (real,imag).</p>
<hr />
<h3 id="baselect2stereo"><code>(ba.)select2stereo</code></h3>
<p>Select between 2 stereo signals.</p>
<h4 id="usage_47">Usage</h4>
<pre><code>_,_,_,_ : select2stereo(bpc) : _,_
</code></pre>
<p>Where:</p>
<ul>
<li><code>bpc</code>: the selector switch (0/1)</li>
</ul>
<hr />
<h3 id="baselectn"><code>(ba.)selectn</code></h3>
<p>Selects the ith input among N at run time.</p>
<h4 id="usage_48">Usage</h4>
<pre><code>selectn(N,i)
_,_,_,_ : selectn(4,2) : _ // selects the 3rd input among 4
</code></pre>
<p>Where:</p>
<ul>
<li><code>N</code>: number of inputs (int, known at compile time, N > 0)</li>
<li><code>i</code>: input to select (int, numbered from 0)</li>
</ul>
<h4 id="example-test-program_7">Example test program</h4>
<pre><code>N = 64;
process = par(n, N, (par(i,N,i) : selectn(N,n)));
</code></pre>
<hr />
<h3 id="baselectbus"><code>(ba.)selectbus</code></h3>
<p>Select a bus among <code>NUM_BUSES</code> buses, where each bus has <code>BUS_SIZE</code> outputs.
The order of the signal inputs should be the signals of the first bus, the
signals of the second bus, and so on.</p>
<h4 id="usage_49">Usage</h4>
<pre><code>process = si.bus(BUS_SIZE*NUM_BUSES) : selectbus(BUS_SIZE, NUM_BUSES, id) : si.bus(BUS_SIZE);
</code></pre>
<p>Where:</p>
<ul>
<li><code>BUS_SIZE</code>: number of outputs from each bus (int, known at compile time).</li>
<li><code>NUM_BUSES</code>: number of buses (int, known at compile time).</li>
<li><code>id</code>: index of the bus to select (int, <code>0<=id<NUM_BUSES</code>)</li>
</ul>
<hr />
<h3 id="baselectxbus"><code>(ba.)selectxbus</code></h3>
<p>Like <code>ba.selectbus</code>, but with a cross-fade when selecting the bus using the same
technique than <code>ba.selectmulti</code>.</p>
<h4 id="usage_50">Usage</h4>
<pre><code>process = si.bus(BUS_SIZE*NUM_BUSES) : selectbus(BUS_SIZE, NUM_BUSES, FADE, id) : si.bus(BUS_SIZE);
</code></pre>
<p>Where:</p>
<ul>
<li><code>BUS_SIZE</code>: number of outputs from each bus (int, known at compile time).</li>
<li><code>NUM_BUSES</code>: number of buses (int, known at compile time).</li>
<li><code>fade</code>: number of samples for the crossfade.</li>
<li><code>id</code>: index of the bus to select (int, <code>0<=id<NUM_BUSES</code>)</li>
</ul>
<hr />
<h3 id="baselectmulti"><code>(ba.)selectmulti</code></h3>
<p>Selects the ith circuit among N at run time (all should have the same number of inputs and outputs)
with a crossfade.</p>
<h4 id="usage_51">Usage</h4>
<pre><code>selectmulti(n,lgen,id)
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: crossfade in samples</li>
<li><code>lgen</code>: list of circuits</li>
<li><code>id</code>: circuit to select (int, numbered from 0)</li>
</ul>
<h4 id="example-test-program_8">Example test program</h4>
<pre><code>process = selectmulti(ma.SR/10, ((3,9),(2,8),(5,7)), nentry("choice", 0, 0, 2, 1));
process = selectmulti(ma.SR/10, ((_*3,_*9),(_*2,_*8),(_*5,_*7)), nentry("choice", 0, 0, 2, 1));
</code></pre>
<hr />
<h3 id="baselectoutn"><code>(ba.)selectoutn</code></h3>
<p>Route input to the output among N at run time.</p>
<h4 id="usage_52">Usage</h4>
<pre><code>_ : selectoutn(N, i) : si.bus(N)
</code></pre>
<p>Where:</p>
<ul>
<li><code>N</code>: number of outputs (int, known at compile time, N > 0)</li>
<li><code>i</code>: output number to route to (int, numbered from 0) (i.e. slider)</li>
</ul>
<h4 id="example-test-program_9">Example test program</h4>
<pre><code>process = 1 : selectoutn(3, sel) : par(i, 3, vbargraph("v.bargraph %i", 0, 1));
sel = hslider("volume", 0, 0, 2, 1) : int;
</code></pre>
<h2 id="other">Other</h2>
<hr />
<h3 id="balatch"><code>(ba.)latch</code></h3>
<p>Latch input on positive-going transition of trig: "records" the input when trig
switches from 0 to 1, outputs a frozen values everytime else.</p>
<h4 id="usage_53">Usage</h4>
<pre><code>_ : latch(trig) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>trig</code>: hold trigger (0 for hold, 1 for bypass)</li>
</ul>
<hr />
<h3 id="basandh"><code>(ba.)sAndH</code></h3>
<p>Sample And Hold: "records" the input when trig is 1, outputs a frozen value when trig is 0.
<code>sAndH</code> is a standard Faust function.</p>
<h4 id="usage_54">Usage</h4>
<pre><code>_ : sAndH(trig) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>trig</code>: hold trigger (0 for hold, 1 for bypass)</li>
</ul>
<hr />
<h3 id="batandh"><code>(ba.)tAndH</code></h3>
<p>Test And Hold: "records" the input when pred(input) is true, outputs a frozen value otherwise.</p>
<h4 id="usage_55">Usage</h4>
<pre><code>_ : tAndH(pred) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>pred</code>: predicate to test the input</li>
</ul>
<hr />
<h3 id="badownsample"><code>(ba.)downSample</code></h3>
<p>Down sample a signal. WARNING: this function doesn't change the
rate of a signal, it just holds samples...
<code>downSample</code> is a standard Faust function.</p>
<h4 id="usage_56">Usage</h4>
<pre><code>_ : downSample(freq) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>freq</code>: new rate in Hz</li>
</ul>
<hr />
<h3 id="badownsamplecv"><code>(ba.)downSampleCV</code></h3>
<p>A version of <code>ba.downSample</code> where the frequency parameter has
been replaced by an <code>amount</code> parameter that is in the range zero
to one. WARNING: this function doesn't change the rate of a
signal, it just holds samples...</p>
<h4 id="usage_57">Usage</h4>
<pre><code>_ : downSampleCV(amount) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>amount</code>: The amount of down-sampling to perform [0..1]</li>
</ul>
<hr />
<h3 id="bapeakhold"><code>(ba.)peakhold</code></h3>
<p>Outputs current max value above zero.</p>
<h4 id="usage_58">Usage</h4>
<pre><code>_ : peakhold(mode) : _
</code></pre>
<p>Where:</p>
<p><code>mode</code> means:</p>
<p>0 - Pass through. A single sample 0 trigger will work as a reset.</p>
<p>1 - Track and hold max value.</p>
<hr />
<h3 id="bapeakholder"><code>(ba.)peakholder</code></h3>
<p>While peak-holder functions are scarcely discussed in the literature
(please do send me an email if you know otherwise), common sense
tells that the expected behaviour should be as follows: the absolute
value of the input signal is compared with the output of the peak-holder;
if the input is greater or equal to the output, a new peak is detected
and sent to the output; otherwise, a timer starts and the current peak
is held for N samples; once the timer is out and no new peaks have been
detected, the absolute value of the current input becomes the new peak.</p>
<h4 id="usage_59">Usage</h4>
<pre><code>_ : peakholder(holdTime) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>holdTime</code>: hold time in samples</li>
</ul>
<hr />
<h3 id="bakr2ar"><code>(ba.)kr2ar</code></h3>
<p>Force a control rate signal to be used as an audio rate signal.</p>
<h4 id="usage_60">Usage</h4>
<pre><code>hslider("freq", 200, 200, 2000, 0.1) : kr2ar;
</code></pre>
<hr />
<h3 id="baimpulsify"><code>(ba.)impulsify</code></h3>
<p>Turns a signal into an impulse with the value of the current sample
(0.3,0.2,0.1 becomes 0.3,0.0,0.0). This function is typically used with a
<code>button</code> to turn its output into an impulse. <code>impulsify</code> is a standard Faust
function.</p>
<h4 id="usage_61">Usage</h4>
<pre><code>button("gate") : impulsify;
</code></pre>
<hr />
<h3 id="baautomat"><code>(ba.)automat</code></h3>
<p>Record and replay in a loop the successives values of the input signal.</p>
<h4 id="usage_62">Usage</h4>
<pre><code>hslider(...) : automat(t, size, init) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>t</code>: tempo in BPM</li>
<li><code>size</code>: number of items in the loop</li>
<li><code>init</code>: init value in the loop</li>
</ul>
<hr />
<h3 id="babpf"><code>(ba.)bpf</code></h3>
<p>bpf is an environment (a group of related definitions) that can be used to
create break-point functions. It contains three functions:</p>
<ul>
<li><code>start(x,y)</code> to start a break-point function</li>
<li><code>end(x,y)</code> to end a break-point function</li>
<li><code>point(x,y)</code> to add intermediate points to a break-point function, using linear interpolation</li>
</ul>
<p>A minimal break-point function must contain at least a start and an end point:</p>
<pre><code>f = bpf.start(x0,y0) : bpf.end(x1,y1);
</code></pre>
<p>A more involved break-point function can contains any number of intermediate
points:</p>
<pre><code>f = bpf.start(x0,y0) : bpf.point(x1,y1) : bpf.point(x2,y2) : bpf.end(x3,y3);
</code></pre>
<p>In any case the <code>x_{i}</code> must be in increasing order (for all <code>i</code>, <code>x_{i} < x_{i+1}</code>).
For example the following definition:</p>
<pre><code>f = bpf.start(x0,y0) : ... : bpf.point(xi,yi) : ... : bpf.end(xn,yn);
</code></pre>
<p>implements a break-point function f such that:</p>
<ul>
<li><code>f(x) = y_{0}</code> when <code>x < x_{0}</code></li>
<li><code>f(x) = y_{n}</code> when <code>x > x_{n}</code></li>
<li><code>f(x) = y_{i} + (y_{i+1}-y_{i})*(x-x_{i})/(x_{i+1}-x_{i})</code> when <code>x_{i} <= x</code>
and <code>x < x_{i+1}</code></li>
</ul>
<p>In addition to <code>bpf.point</code>, there are also <code>step</code> and <code>curve</code> functions:</p>
<ul>
<li><code>step(x,y)</code> to add a flat section</li>
<li><code>step_end(x,y)</code> to end with a flat section</li>
<li><code>curve(B,x,y)</code> to add a curved section</li>
<li><code>curve_end(B,x,y)</code> to end with a curved section</li>
</ul>
<p>These functions can be combined with the other <code>bpf</code> functions.</p>
<p>Here's an example using <code>bpf.step</code>:</p>
<p><code>f(x) = x : bpf.start(0,0) : bpf.step(.2,.3) : bpf.step(.4,.6) : bpf.step_end(1,1);</code></p>
<p>For <code>x < 0.0</code>, the output is 0.0.
For <code>0.0 <= x < 0.2</code>, the output is 0.0.
For <code>0.2 <= x < 0.4</code>, the output is 0.3.
For <code>0.4 <= x < 1.0</code>, the output is 0.6.
For <code>1.0 <= x</code>, the output is 1.0</p>
<p>For the <code>curve</code> functions, <code>B</code> (compile-time constant)
is a "bias" value strictly greater than zero and less than or equal to 1. When <code>B</code> is 0.5, the
output curve is exactly linear and equivalent to <code>bpf.point</code>. When <code>B</code> is less than 0.5, the
output is biased towards the <code>y</code> value of the previous breakpoint. When <code>B</code> is greater than 0.5,
the output is biased towards the <code>y</code> value of the curve breakpoint. Here's an example:</p>
<p><code>f = bpf.start(0,0) : bpf.curve(.15,.5,.5) : bpf.curve_end(.85,1,1);</code></p>
<p>In the following example, the output is biased towards zero (the latter y value) instead of
being a linear ramp from 1 to 0.</p>
<p><code>f = bpf.start(0,1) : bpf.curve_end(.9,1,0);</code></p>
<p><code>bpf</code> is a standard Faust function.</p>
<hr />
<h3 id="balistinterp"><code>(ba.)listInterp</code></h3>
<p>Linearly interpolates between the elements of a list.</p>
<h4 id="usage_63">Usage</h4>
<pre><code>index = 1.69; // range is 0-4
process = listInterp((800,400,350,450,325),index);
</code></pre>
<p>Where:</p>
<ul>
<li><code>index</code>: the index (float) to interpolate between the different values.
The range of <code>index</code> depends on the size of the list.</li>
</ul>
<hr />
<h3 id="babypass1"><code>(ba.)bypass1</code></h3>
<p>Takes a mono input signal, route it to <code>e</code> and bypass it if <code>bpc = 1</code>.
When bypassed, <code>e</code> is feed with zeros so that its state is cleanup up.
<code>bypass1</code> is a standard Faust function.</p>
<h4 id="usage_64">Usage</h4>
<pre><code>_ : bypass1(bpc,e) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>bpc</code>: bypass switch (0/1)</li>
<li><code>e</code>: a mono effect</li>
</ul>
<hr />
<h3 id="babypass2"><code>(ba.)bypass2</code></h3>
<p>Takes a stereo input signal, route it to <code>e</code> and bypass it if <code>bpc = 1</code>.
When bypassed, <code>e</code> is feed with zeros so that its state is cleanup up.
<code>bypass2</code> is a standard Faust function.</p>
<h4 id="usage_65">Usage</h4>
<pre><code>_,_ : bypass2(bpc,e) : _,_
</code></pre>
<p>Where:</p>
<ul>
<li><code>bpc</code>: bypass switch (0/1)</li>
<li><code>e</code>: a stereo effect</li>
</ul>
<hr />
<h3 id="babypass1to2"><code>(ba.)bypass1to2</code></h3>
<p>Bypass switch for effect <code>e</code> having mono input signal and stereo output.
Effect <code>e</code> is bypassed if <code>bpc = 1</code>.When bypassed, <code>e</code> is feed with zeros
so that its state is cleanup up.
<code>bypass1to2</code> is a standard Faust function.</p>
<h4 id="usage_66">Usage</h4>
<pre><code>_ : bypass1to2(bpc,e) : _,_
</code></pre>
<p>Where:</p>
<ul>
<li><code>bpc</code>: bypass switch (0/1)</li>
<li><code>e</code>: a mono-to-stereo effect</li>
</ul>
<hr />
<h3 id="babypass_fade"><code>(ba.)bypass_fade</code></h3>
<p>Bypass an arbitrary (N x N) circuit with 'n' samples crossfade.
Inputs and outputs signals are faded out when 'e' is bypassed,
so that 'e' state is cleanup up.
Once bypassed the effect is replaced by <code>par(i,N,_)</code>.
Bypassed circuits can be chained.</p>
<h4 id="usage_67">Usage</h4>
<pre><code>_ : bypass_fade(n,b,e) : _
or
_,_ : bypass_fade(n,b,e) : _,_
</code></pre>
<ul>
<li><code>n</code>: number of samples for the crossfade</li>
<li><code>b</code>: bypass switch (0/1)</li>
<li><code>e</code>: N x N circuit</li>
</ul>
<h4 id="example-test-program_10">Example test program</h4>
<pre><code>process = bypass_fade(ma.SR/10, checkbox("bypass echo"), echo);
process = bypass_fade(ma.SR/10, checkbox("bypass reverb"), freeverb);
</code></pre>
<hr />
<h3 id="batoggle"><code>(ba.)toggle</code></h3>
<p>Triggered by the change of 0 to 1, it toggles the output value
between 0 and 1.</p>
<h4 id="usage_68">Usage</h4>
<pre><code>_ : toggle : _
</code></pre>
<h4 id="example-test-program_11">Example test program</h4>
<pre><code>button("toggle") : toggle : vbargraph("output", 0, 1)
(an.amp_follower(0.1) > 0.01) : toggle : vbargraph("output", 0, 1) // takes audio input
</code></pre>
<hr />
<h3 id="baon_and_off"><code>(ba.)on_and_off</code></h3>
<p>The first channel set the output to 1, the second channel to 0.</p>
<h4 id="usage_69">Usage</h4>
<pre><code>_,_ : on_and_off : _
</code></pre>
<h4 id="example-test-program_12">Example test program</h4>
<pre><code>button("on"), button("off") : on_and_off : vbargraph("output", 0, 1)
</code></pre>
<hr />
<h3 id="babitcrusher"><code>(ba.)bitcrusher</code></h3>
<p>Produce distortion by reduction of the signal resolution.</p>
<h4 id="usage_70">Usage</h4>
<pre><code>_ : bitcrusher(nbits) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>nbits</code>: the number of bits of the wanted resolution</li>
</ul>
<hr />
<h3 id="bamulaw_bitcrusher"><code>(ba.)mulaw_bitcrusher</code></h3>
<p>Produce distortion by reducing the signal resolution using μ-law compression.</p>
<h4 id="usage_71">Usage</h4>
<pre><code>_ : mulaw_bitcrusher(mu,nbits) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>mu</code>: controls the degree of μ-law compression, larger values result in stronger compression</li>
<li><code>nbits</code>: the number of bits of the wanted resolution</li>
</ul>
<h4 id="description">Description</h4>
<p>The <code>mulaw_bitcrusher</code> applies a combination of μ-law compression, quantization, and expansion
to create a non-linear bitcrushed effect. This method retains finer detail in lower-amplitude signals
compared to linear bitcrushing, making it suitable for creative sound design.</p>
<h4 id="theory">Theory</h4>
<ol>
<li><strong>μ-law Compression</strong>:
emphasizes lower-amplitude signals by applying a logarithmic curve to the signal.
The formula used is:
<code>F(x) = ma.signum(x) * log(1 + mu * abs(x)) / log(1 + mu);</code></li>
<li>
<p><strong>Quantization</strong>:
reduces the signal resolution to <code>nbits</code> by rounding values to the nearest step within the specified bit depth.</p>
</li>
<li>
<p><strong>μ-law Expansion</strong>:
reverses the compression applied earlier to restore the signal to its original dynamic range:
<code>F⁻¹(y) = ma.signum(y) * (pow(1 + mu, abs(y)) - 1) / mu;</code></p>
</li>
</ol>
<h4 id="example-test-program_13">Example test program</h4>
<pre><code>process = os.osc(440) : mulaw_bitcrusher(255, 8);
</code></pre>
<p>In this example, a sine wave at 440 Hz is passed through the μ-law bitcrusher, with a compression
parameter <code>mu</code> of 255 and 8-bit quantization. This creates a distorted, "lo-fi" effect.</p>
<h4 id="references_1">References</h4>
<ul>
<li><a href="https://en.wikipedia.org/wiki/Μ-law_algorithm">https://en.wikipedia.org/wiki/Μ-law_algorithm</a></li>
</ul>
<h2 id="sliding-reduce">Sliding Reduce</h2>
<p>Provides various operations on the last n samples using a high order
<code>slidingReduce(op,n,maxN,disabledVal,x)</code> fold-like function:</p>
<ul>
<li><code>slidingSum(n)</code>: the sliding sum of the last n input samples, CPU-light</li>
<li><code>slidingSump(n,maxN)</code>: the sliding sum of the last n input samples, numerically stable "forever"</li>
<li><code>slidingMax(n,maxN)</code>: the sliding max of the last n input samples</li>
<li><code>slidingMin(n,maxN)</code>: the sliding min of the last n input samples</li>
<li><code>slidingMean(n)</code>: the sliding mean of the last n input samples, CPU-light</li>
<li><code>slidingMeanp(n,maxN)</code>: the sliding mean of the last n input samples, numerically stable "forever"</li>
<li><code>slidingRMS(n)</code>: the sliding RMS of the last n input samples, CPU-light</li>
<li><code>slidingRMSp(n,maxN)</code>: the sliding RMS of the last n input samples, numerically stable "forever"</li>
</ul>
<h4 id="working-principle_1">Working Principle</h4>
<p>If we want the maximum of the last 8 values, we can do that as:</p>
<pre><code>simpleMax(x) =
(
(
max(x@0,x@1),
max(x@2,x@3)
) :max
),
(
(
max(x@4,x@5),
max(x@6,x@7)
) :max
)
:max;
</code></pre>
<p><code>max(x@2,x@3)</code> is the same as <code>max(x@0,x@1)@2</code> but the latter re-uses a
value we already computed,so is more efficient. Using the same trick for
values 4 trough 7, we can write:</p>
<pre><code>efficientMax(x)=
(
(
max(x@0,x@1),
max(x@0,x@1)@2
) :max
),
(
(
max(x@0,x@1),
max(x@0,x@1)@2
) :max@4
)
:max;
</code></pre>
<p>We can rewrite it recursively, so it becomes possible to get the maximum at
have any number of values, as long as it's a power of 2.</p>
<pre><code>recursiveMax =
case {
(1,x) => x;
(N,x) => max(recursiveMax(N/2,x), recursiveMax(N/2,x)@(N/2));
};
</code></pre>
<p>What if we want to look at a number of values that's not a power of 2?
For each value, we will have to decide whether to use it or not.
If n is bigger than the index of the value, we use it, otherwise we replace
it with (<code>0-(ma.MAX)</code>):</p>
<pre><code>variableMax(n,x) =
max(
max(
(
(x@0 : useVal(0)),
(x@1 : useVal(1))
):max,
(
(x@2 : useVal(2)),
(x@3 : useVal(3))
):max
),
max(
(
(x@4 : useVal(4)),
(x@5 : useVal(5))
):max,
(
(x@6 : useVal(6)),
(x@7 : useVal(7))
):max
)
)
with {
useVal(i) = select2((n>=i) , (0-(ma.MAX)),_);
};
</code></pre>
<p>Now it becomes impossible to re-use any values. To fix that let's first look
at how we'd implement it using recursiveMax, but with a fixed n that is not
a power of 2. For example, this is how you'd do it with <code>n=3</code>:</p>
<pre><code>binaryMaxThree(x) =
(
recursiveMax(1,x)@0, // the first x
recursiveMax(2,x)@1 // the second and third x
):max;
</code></pre>
<p><code>n=6</code></p>
<pre><code>binaryMaxSix(x) =
(
recursiveMax(2,x)@0, // first two
recursiveMax(4,x)@2 // third trough sixth
):max;
</code></pre>
<p>Note that <code>recursiveMax(2,x)</code> is used at a different delay then in
<code>binaryMaxThree</code>, since it represents 1 and 2, not 2 and 3. Each block is
delayed the combined size of the previous blocks.</p>
<p><code>n=7</code></p>
<pre><code>binaryMaxSeven(x) =
(
(
recursiveMax(1,x)@0, // first x
recursiveMax(2,x)@1 // second and third
):max,
(
recursiveMax(4,x)@3 // fourth trough seventh
)
):max;
</code></pre>
<p>To make a variable version, we need to know which powers of two are used,
and at which delay time.</p>
<p>Then it becomes a matter of:</p>
<ul>
<li>lining up all the different block sizes in parallel: <code>sequentialOperatorParOut()</code></li>
<li>delaying each the appropriate amount: <code>sumOfPrevBlockSizes()</code></li>
<li>turning it on or off: <code>useVal()</code></li>
<li>getting the maximum of all of them: <code>parallelOp()</code></li>
</ul>
<p>In Faust, we can only do that for a fixed maximum number of values: <code>maxN</code>, known at compile time.</p>
<hr />
<h3 id="baslidingreduce"><code>(ba.)slidingReduce</code></h3>
<p>Fold-like high order function. Apply a commutative binary operation <code>op</code> to
the last <code>n</code> consecutive samples of a signal <code>x</code>. For example :
<code>slidingReduce(max,128,128,0-(ma.MAX))</code> will compute the maximum of the last
128 samples. The output is updated each sample, unlike reduce, where the
output is constant for the duration of a block.</p>
<h4 id="usage_72">Usage</h4>
<pre><code>_ : slidingReduce(op,n,maxN,disabledVal) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the number of values to process</li>
<li><code>maxN</code>: the maximum number of values to process (int, known at compile time, maxN > 0)</li>
<li><code>op</code>: the operator. Needs to be a commutative one.</li>
<li><code>disabledVal</code>: the value to use when we want to ignore a value.</li>
</ul>
<p>In other words, <code>op(x,disabledVal)</code> should equal to <code>x</code>. For example,
<code>+(x,0)</code> equals <code>x</code> and <code>min(x,ma.MAX)</code> equals <code>x</code>. So if we want to
calculate the sum, we need to give 0 as <code>disabledVal</code>, and if we want the
minimum, we need to give <code>ma.MAX</code> as <code>disabledVal</code>.</p>
<hr />
<h3 id="baslidingsum"><code>(ba.)slidingSum</code></h3>
<p>The sliding sum of the last n input samples.</p>
<p>It will eventually run into numerical trouble when there is a persistent dc component.
If that matters in your application, use the more CPU-intensive <code>ba.slidingSump</code>.</p>
<h4 id="usage_73">Usage</h4>
<pre><code>_ : slidingSum(n) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the number of values to process</li>
</ul>
<hr />
<h3 id="baslidingsump"><code>(ba.)slidingSump</code></h3>
<p>The sliding sum of the last n input samples.</p>
<p>It uses a lot more CPU than <code>ba.slidingSum</code>, but is numerically stable "forever" in return.</p>
<h4 id="usage_74">Usage</h4>
<pre><code>_ : slidingSump(n,maxN) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the number of values to process</li>
<li><code>maxN</code>: the maximum number of values to process (int, known at compile time, maxN > 0)</li>
</ul>
<hr />
<h3 id="baslidingmax"><code>(ba.)slidingMax</code></h3>
<p>The sliding maximum of the last n input samples.</p>
<h4 id="usage_75">Usage</h4>
<pre><code>_ : slidingMax(n,maxN) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the number of values to process</li>
<li><code>maxN</code>: the maximum number of values to process (int, known at compile time, maxN > 0)</li>
</ul>
<hr />
<h3 id="baslidingmin"><code>(ba.)slidingMin</code></h3>
<p>The sliding minimum of the last n input samples.</p>
<h4 id="usage_76">Usage</h4>
<pre><code>_ : slidingMin(n,maxN) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the number of values to process</li>
<li><code>maxN</code>: the maximum number of values to process (int, known at compile time, maxN > 0)</li>
</ul>
<hr />
<h3 id="baslidingmean"><code>(ba.)slidingMean</code></h3>
<p>The sliding mean of the last n input samples.</p>
<p>It will eventually run into numerical trouble when there is a persistent dc component.
If that matters in your application, use the more CPU-intensive <code>ba.slidingMeanp</code>.</p>
<h4 id="usage_77">Usage</h4>
<pre><code>_ : slidingMean(n) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the number of values to process</li>
</ul>
<hr />
<h3 id="baslidingmeanp"><code>(ba.)slidingMeanp</code></h3>
<p>The sliding mean of the last n input samples.</p>
<p>It uses a lot more CPU than <code>ba.slidingMean</code>, but is numerically stable "forever" in return.</p>
<h4 id="usage_78">Usage</h4>
<pre><code>_ : slidingMeanp(n,maxN) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the number of values to process</li>
<li><code>maxN</code>: the maximum number of values to process (int, known at compile time, maxN > 0)</li>
</ul>
<hr />
<h3 id="baslidingrms"><code>(ba.)slidingRMS</code></h3>
<p>The root mean square of the last n input samples.</p>
<p>It will eventually run into numerical trouble when there is a persistent dc component.
If that matters in your application, use the more CPU-intensive <code>ba.slidingRMSp</code>.</p>
<h4 id="usage_79">Usage</h4>
<pre><code>_ : slidingRMS(n) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the number of values to process</li>
</ul>
<hr />
<h3 id="baslidingrmsp"><code>(ba.)slidingRMSp</code></h3>
<p>The root mean square of the last n input samples.</p>
<p>It uses a lot more CPU than <code>ba.slidingRMS</code>, but is numerically stable "forever" in return.</p>
<h4 id="usage_80">Usage</h4>
<pre><code>_ : slidingRMSp(n,maxN) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>n</code>: the number of values to process</li>
<li><code>maxN</code>: the maximum number of values to process (int, known at compile time, maxN > 0)</li>
</ul>
<h2 id="parallel-operators">Parallel Operators</h2>
<p>Provides various operations on N parallel inputs using a high order
<code>parallelOp(op,N,x)</code> function:</p>
<ul>
<li><code>parallelMax(N)</code>: the max of n parallel inputs</li>
<li><code>parallelMin(N)</code>: the min of n parallel inputs</li>
<li><code>parallelMean(N)</code>: the mean of n parallel inputs</li>
<li><code>parallelRMS(N)</code>: the RMS of n parallel inputs</li>
</ul>
<hr />
<h3 id="baparallelop"><code>(ba.)parallelOp</code></h3>
<p>Apply a commutative binary operation <code>op</code> to N parallel inputs.</p>
<h4 id="usage_81">usage</h4>
<pre><code>si.bus(N) : parallelOp(op,N) : _
</code></pre>
<p>where:</p>
<ul>
<li><code>N</code>: the number of parallel inputs known at compile time</li>
<li><code>op</code>: the operator which needs to be commutative</li>
</ul>
<hr />
<h3 id="baparallelmax"><code>(ba.)parallelMax</code></h3>
<p>The maximum of N parallel inputs.</p>
<h4 id="usage_82">Usage</h4>
<pre><code>si.bus(N) : parallelMax(N) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>N</code>: the number of parallel inputs known at compile time</li>
</ul>
<hr />
<h3 id="baparallelmin"><code>(ba.)parallelMin</code></h3>
<p>The minimum of N parallel inputs.</p>
<h4 id="usage_83">Usage</h4>
<pre><code>si.bus(N) : parallelMin(N) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>N</code>: the number of parallel inputs known at compile time</li>
</ul>
<hr />
<h3 id="baparallelmean"><code>(ba.)parallelMean</code></h3>
<p>The mean of N parallel inputs.</p>
<h4 id="usage_84">Usage</h4>
<pre><code>si.bus(N) : parallelMean(N) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>N</code>: the number of parallel inputs known at compile time</li>
</ul>
<hr />
<h3 id="baparallelrms"><code>(ba.)parallelRMS</code></h3>
<p>The RMS of N parallel inputs.</p>
<h4 id="usage_85">Usage</h4>
<pre><code>si.bus(N) : parallelRMS(N) : _
</code></pre>
<p>Where:</p>
<ul>
<li><code>N</code>: the number of parallel inputs known at compile time</li>
</ul></div>
</div>
</div>
<footer class="col-md-12">
<hr>
<p>Copyright © 2019-2025 <a href="https://www.grame.fr">Grame-CNCM</a></p>
</footer>
<script>
var base_url = "../..",
shortcuts = {"help": 191, "next": 78, "previous": 80, "search": 83};
</script>
<script src="../../js/base.js" defer></script>
<script src="/usr/share/javascript/mathjax/MathJax.js" defer></script>
<script src="../../search/main.js" defer></script>
<div class="modal" id="mkdocs_search_modal" tabindex="-1" role="dialog" aria-labelledby="searchModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="searchModalLabel">Search</h4>
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
</div>
<div class="modal-body">
<p>From here you can search these documents. Enter your search terms below.</p>
<form>
<div class="form-group">
<input type="search" class="form-control" placeholder="Search..." id="mkdocs-search-query" title="Type search term here">
</div>
</form>
<div id="mkdocs-search-results" data-no-results-text="No results found"></div>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div><div class="modal" id="mkdocs_keyboard_modal" tabindex="-1" role="dialog" aria-labelledby="keyboardModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="keyboardModalLabel">Keyboard Shortcuts</h4>
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
</div>
<div class="modal-body">
<table class="table">
<thead>
<tr>
<th style="width: 20%;">Keys</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td class="help shortcut"><kbd>?</kbd></td>
<td>Open this help</td>
</tr>
<tr>
<td class="next shortcut"><kbd>n</kbd></td>
<td>Next page</td>
</tr>
<tr>
<td class="prev shortcut"><kbd>p</kbd></td>
<td>Previous page</td>
</tr>
<tr>
<td class="search shortcut"><kbd>s</kbd></td>
<td>Search</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
</body>
</html>
|