// ----
// ---- file   : stereo_waveshaper_1.cpp
// ---- author : bsp
// ---- legal  : Distributed under terms of the MIT license (https://opensource.org/licenses/MIT)
// ----
// ----          Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
// ----          associated documentation files (the "Software"), to deal in the Software without restriction, including
// ----          without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// ----          copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
// ----          the following conditions:
// ----
// ----          The above copyright notice and this permission notice shall be included in all copies or substantial
// ----          portions of the Software.
// ----
// ----          THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
// ----          NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// ----          IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// ----          WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// ----          SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ----
// ---- info   : auto-generated by "Cycle"
// ----           $ g++ -Wall -Wno-unused-function -Wno-unused-variable -I../../tksampler -c stereo_waveshaper_1.cpp -o stereo_waveshaper_1.o
// ---- created: 14Jan2025 00:15:52
// ----
// ----
// ----

// (note) pre-define CYCLE_SKIP_UI to skip all code used only for UI/editing purposes (e.g. when compiling for standalone replay)
// #define CYCLE_SKIP_UI  defined

#include <plugin.h>

#include <stdlib.h>
#include <math.h>
#include <string.h>

#define STEREO  defined

#define PARAM_DRYWET             0
#define PARAM_IOGAIN             1
#define PARAM_PAN                2
#define PARAM_VOL                3
#define NUM_PARAMS               4
#ifndef CYCLE_SKIP_UI
static const char *loc_param_names[NUM_PARAMS
#if defined(_MSC_VER) && 0 == NUM_PARAMS
                                   +1
#endif
                                   ] = {
#if defined(_MSC_VER) && 0 == NUM_PARAMS
                                   ""
#else
   "drywet",                  // 0: DRYWET
   "iogain",                  // 1: IOGAIN
   "pan",                     // 2: PAN
   "vol",                     // 3: VOL

#endif
};
#endif // CYCLE_SKIP_UI
static float loc_param_resets[NUM_PARAMS
#if defined(_MSC_VER) && 0 == NUM_PARAMS
                                   +1
#endif
                              ] = {
#if defined(_MSC_VER) && 0 == NUM_PARAMS
   0.0f
#else
   0.7f,                      // 0: DRYWET
   0.5f,                      // 1: IOGAIN
   0.5f,                      // 2: PAN
   0.5f,                      // 3: VOL

#endif
};

#define MOD_DRYWET               0
#define MOD_IOGAIN               1
#define MOD_PAN                  2
#define MOD_VOL                  3
#define NUM_MODS                 4
#ifndef CYCLE_SKIP_UI
static const char *loc_mod_names[NUM_MODS
#if defined(_MSC_VER) && 0 == NUM_MODS
   +1
#endif
                                 ] = {
#if defined(_MSC_VER) && 0 == NUM_MODS
   ""
#else
   "drywet",               // 0: DRYWET
   "iogain",               // 1: IOGAIN
   "pan",                  // 2: PAN
   "vol",                  // 3: VOL

#endif
};
#endif // CYCLE_SKIP_UI

typedef struct stereo_waveshaper_1_info_s {
   st_plugin_info_t base;
} stereo_waveshaper_1_info_t;

typedef struct stereo_waveshaper_1_shared_s {
   st_plugin_shared_t base;
   float params[NUM_PARAMS
#if defined(_MSC_VER) && 0 == NUM_PARAMS
                +1
#endif
                ];

} stereo_waveshaper_1_shared_t;

typedef struct stereo_waveshaper_1_voice_s {
   st_plugin_voice_t base;
   float             sample_rate;
   float             bpm;
   float             velocity;
   float             note_speed_fixed;
   float             note_speed_cur;
   float             note_speed_inc;
   float             note_cur;
   float             note_inc;
   float             mods[NUM_MODS
#if defined(_MSC_VER) && 0 == NUM_MODS
                          +1
#endif
                          ];
   float mod_drywet_cur;
   float mod_drywet_inc;
   float mod_iogain_cur;
   float mod_iogain_inc;
   float mod_pan_cur;
   float mod_pan_inc;
   float mod_vol_cur;
   float mod_vol_inc;

   float tmp1;
   float tmp2;
   float tmp3;
   float tmp4;
   float tmp5;
   short tmp6;
   short tmp7;
   short tmp8;
   float tmp9;
   float tmp10;
   float tmp11;
   float var_x;
   float var_v_i;
   float var_v_o_l;
   float var_v_o_r;
   float var_prepare__vpan;
   float sr_factor;

} stereo_waveshaper_1_voice_t;

#define loop(X)  for(unsigned int i = 0u; i < (X); i++)
#define clamp(a,b,c) (((a)<(b))?(b):(((a)>(c))?(c):(a)))

static inline float mathLerpf(float _a, float _b, float _t) { return _a + (_b - _a) * _t; }
static inline float mathClampf(float a, float b, float c) { return (((a)<(b))?(b):(((a)>(c))?(c):(a))); }
static inline float mathMinf(float a, float b) { return (a<b)?a:b; }
static inline float mathMaxf(float a, float b) { return (a>b)?a:b; }
static inline float mathAbsMaxf(float _x, float _y) { return ( ( (_x<0.0f)?-_x:_x)>((_y<0.0f)?-_y:_y)?_x:_y ); }
static inline float mathAbsMinf(float _x, float _y) { return ( ((_x<0.0f)?-_x:_x)<((_y<0.0f)?-_y:_y)?_x:_y ); }
static inline float frac(float _x) { return _x - ((int)_x); }

static inline float winLinear(const float *_s, float _index) {
   int idx = (int)_index;
   float r = _index - (float)idx;
   return mathLerpf(_s[idx], _s[idx+1], r);
}

static float ffrac_s(float _f) { int i; if(_f >= 0.0f) { i = (int)_f; return _f - (float)i; } else { i = (int)-_f; return 1.0f - (-_f - (float)i); } }
static short curve_0[512] = {
0, 8, 17, 26, 35, 44, 53, 62, 71, 80, 89, 97, 106, 115, 124, 132, 141, 150, 159, 167, 176, 184, 193, 201, 210, 219, 227, 235, 244, 252, 261, 269, 
277, 286, 294, 302, 311, 319, 327, 335, 343, 352, 360, 368, 376, 384, 392, 400, 408, 416, 424, 432, 440, 448, 456, 463, 471, 479, 487, 494, 502, 510, 518, 525, 
533, 540, 548, 555, 563, 570, 578, 585, 593, 600, 608, 615, 622, 630, 637, 644, 651, 659, 666, 673, 680, 687, 694, 701, 708, 715, 722, 729, 736, 743, 750, 757, 
764, 770, 777, 784, 791, 797, 804, 811, 817, 824, 831, 837, 844, 850, 857, 863, 869, 876, 882, 889, 895, 901, 907, 914, 920, 926, 932, 938, 944, 950, 956, 963, 
968, 974, 980, 986, 992, 998, 1004, 1010, 1015, 1021, 1027, 1033, 1038, 1044, 1050, 1055, 1061, 1066, 1072, 1077, 1083, 1088, 1093, 1099, 1104, 1109, 1115, 1120, 1125, 1130, 1136, 1141, 
1146, 1151, 1156, 1161, 1166, 1171, 1176, 1181, 1186, 1191, 1195, 1200, 1205, 1210, 1215, 1219, 1224, 1229, 1233, 1238, 1242, 1247, 1251, 1256, 1260, 1265, 1269, 1274, 1278, 1282, 1286, 1291, 
1295, 1299, 1303, 1307, 1312, 1316, 1320, 1324, 1328, 1332, 1336, 1340, 1344, 1347, 1351, 1355, 1359, 1363, 1366, 1370, 1374, 1377, 1381, 1385, 1388, 1392, 1395, 1399, 1402, 1406, 1409, 1413, 
1416, 1419, 1423, 1426, 1429, 1432, 1436, 1439, 1442, 1445, 1448, 1451, 1454, 1457, 1460, 1463, 1466, 1469, 1472, 1475, 1478, 1481, 1484, 1487, 1489, 1492, 1495, 1497, 1500, 1503, 1505, 1508, 
1511, 1513, 1516, 1518, 1521, 1523, 1526, 1528, 1531, 1533, 1535, 1538, 1540, 1542, 1545, 1547, 1549, 1551, 1554, 1556, 1558, 1560, 1562, 1564, 1566, 1568, 1571, 1573, 1575, 1577, 1579, 1581, 
1582, 1584, 1586, 1588, 1590, 1592, 1594, 1596, 1598, 1599, 1601, 1603, 1605, 1606, 1608, 1610, 1612, 1613, 1615, 1617, 1618, 1620, 1621, 1623, 1625, 1626, 1628, 1629, 1631, 1633, 1634, 1636, 
1637, 1639, 1640, 1642, 1643, 1645, 1646, 1648, 1649, 1650, 1652, 1653, 1655, 1656, 1658, 1659, 1660, 1662, 1663, 1664, 1666, 1667, 1669, 1670, 1671, 1673, 1674, 1675, 1677, 1678, 1679, 1681, 
1682, 1683, 1685, 1686, 1688, 1689, 1690, 1692, 1693, 1694, 1696, 1697, 1698, 1700, 1701, 1702, 1704, 1705, 1706, 1708, 1709, 1711, 1712, 1713, 1715, 1716, 1718, 1719, 1721, 1722, 1723, 1725, 
1726, 1728, 1729, 1731, 1732, 1734, 1735, 1737, 1738, 1740, 1741, 1743, 1744, 1746, 1748, 1749, 1751, 1752, 1754, 1756, 1757, 1759, 1761, 1762, 1764, 1766, 1768, 1769, 1771, 1773, 1775, 1777, 
1778, 1780, 1782, 1784, 1786, 1788, 1790, 1792, 1794, 1796, 1798, 1800, 1802, 1804, 1806, 1808, 1810, 1812, 1814, 1816, 1819, 1821, 1823, 1825, 1827, 1830, 1832, 1834, 1837, 1839, 1841, 1844, 
1846, 1849, 1851, 1854, 1856, 1859, 1861, 1864, 1867, 1869, 1872, 1874, 1877, 1880, 1883, 1885, 1888, 1891, 1894, 1897, 1900, 1902, 1905, 1908, 1911, 1914, 1917, 1920, 1923, 1927, 1930, 1933, 
1936, 1939, 1942, 1946, 1949, 1952, 1956, 1959, 1962, 1966, 1969, 1973, 1976, 1980, 1983, 1987, 1990, 1994, 1998, 2001, 2005, 2009, 2013, 2016, 2020, 2024, 2028, 2032, 2036, 2040, 2044, 2047, 
};
static short curve_1[512] = {
0, 4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69, 74, 79, 84, 89, 94, 99, 104, 109, 114, 119, 124, 129, 134, 139, 144, 149, 154, 
159, 164, 169, 174, 180, 185, 190, 195, 200, 205, 210, 215, 220, 226, 231, 236, 241, 246, 251, 256, 262, 267, 272, 277, 282, 288, 293, 298, 303, 308, 313, 319, 
324, 329, 334, 340, 345, 350, 355, 360, 366, 371, 376, 381, 387, 392, 397, 402, 408, 413, 418, 423, 429, 434, 439, 444, 450, 455, 460, 465, 471, 476, 481, 486, 
492, 497, 502, 507, 513, 518, 523, 528, 534, 539, 544, 549, 555, 560, 565, 570, 575, 581, 586, 591, 596, 601, 607, 612, 617, 622, 627, 633, 638, 643, 648, 653, 
658, 664, 669, 674, 679, 684, 689, 694, 699, 704, 710, 715, 720, 725, 730, 735, 740, 745, 750, 755, 760, 765, 770, 775, 780, 785, 790, 795, 800, 805, 810, 814, 
819, 824, 829, 834, 839, 844, 848, 853, 858, 863, 868, 872, 877, 882, 887, 891, 896, 901, 906, 910, 915, 920, 924, 929, 934, 938, 943, 947, 952, 957, 961, 966, 
970, 975, 979, 984, 988, 993, 997, 1002, 1006, 1011, 1015, 1020, 1024, 1028, 1033, 1037, 1042, 1046, 1050, 1055, 1059, 1063, 1068, 1072, 1076, 1080, 1085, 1089, 1093, 1097, 1102, 1106, 
1110, 1114, 1118, 1122, 1127, 1131, 1135, 1139, 1143, 1147, 1151, 1155, 1159, 1163, 1168, 1172, 1176, 1180, 1184, 1188, 1192, 1196, 1200, 1204, 1207, 1211, 1215, 1219, 1223, 1227, 1231, 1235, 
1239, 1243, 1246, 1250, 1254, 1258, 1262, 1266, 1269, 1273, 1277, 1281, 1285, 1288, 1292, 1296, 1300, 1303, 1307, 1311, 1315, 1318, 1322, 1326, 1329, 1333, 1337, 1340, 1344, 1348, 1351, 1355, 
1358, 1362, 1366, 1369, 1373, 1376, 1380, 1384, 1387, 1391, 1394, 1398, 1401, 1405, 1408, 1412, 1415, 1419, 1422, 1426, 1429, 1433, 1436, 1440, 1443, 1447, 1450, 1454, 1457, 1460, 1464, 1467, 
1471, 1474, 1477, 1481, 1484, 1488, 1491, 1494, 1498, 1501, 1504, 1508, 1511, 1514, 1518, 1521, 1524, 1528, 1531, 1534, 1538, 1541, 1544, 1547, 1551, 1554, 1557, 1561, 1564, 1567, 1570, 1574, 
1577, 1580, 1583, 1586, 1590, 1593, 1596, 1599, 1603, 1606, 1609, 1612, 1615, 1618, 1622, 1625, 1628, 1631, 1634, 1637, 1641, 1644, 1647, 1650, 1653, 1656, 1659, 1663, 1666, 1669, 1672, 1675, 
1678, 1681, 1684, 1687, 1690, 1694, 1697, 1700, 1703, 1706, 1709, 1712, 1715, 1718, 1721, 1724, 1727, 1730, 1733, 1736, 1739, 1742, 1745, 1748, 1751, 1754, 1757, 1760, 1763, 1766, 1769, 1772, 
1775, 1778, 1781, 1784, 1787, 1790, 1793, 1796, 1799, 1802, 1805, 1808, 1811, 1814, 1817, 1820, 1823, 1826, 1829, 1832, 1835, 1838, 1841, 1843, 1846, 1849, 1852, 1855, 1858, 1861, 1864, 1867, 
1870, 1873, 1875, 1878, 1881, 1884, 1887, 1890, 1893, 1896, 1898, 1901, 1904, 1907, 1910, 1913, 1916, 1919, 1921, 1924, 1927, 1930, 1933, 1936, 1938, 1941, 1944, 1947, 1950, 1953, 1955, 1958, 
1961, 1964, 1967, 1970, 1972, 1975, 1978, 1981, 1984, 1986, 1989, 1992, 1995, 1998, 2000, 2003, 2006, 2009, 2011, 2014, 2017, 2020, 2023, 2025, 2028, 2031, 2034, 2036, 2039, 2042, 2045, 2047, 
};

static float loc_bipolar_to_scale(const float _t, const float _div, const float _mul) {
   // t (-1..1) => /_div .. *_mul
   
   float s;

   if(_t < 0.0f)
   {
      s = (1.0f / _div);
      s = 1.0f + (s - 1.0f) * -_t;
      if(s < 0.0f)
         s = 0.0f;
   }
   else
   {
      s = _mul;
      s = 1.0f + (s - 1.0f) * _t;
   }
   
   return s;
}

static void loc_prepare(st_plugin_voice_t *_voice);

void loc_prepare(st_plugin_voice_t *_voice) {
   ST_PLUGIN_VOICE_CAST(stereo_waveshaper_1_voice_t);
   ST_PLUGIN_VOICE_SHARED_CAST(stereo_waveshaper_1_shared_t);

   float out = 0.0f;
   (void)out;
   // -------- lane "prepare" modIdx=0 modString=$m_pan
   
   // -- mod="$m_pan" dstVar=out
   out = voice->mod_pan_cur;
   
   // -- mod="fma" dstVar=out
   out = (out * 2.0f) + -1.0f;
   
   // -- mod="set prepare__vpan" dstVar=out
   voice->var_prepare__vpan = out;
   
   // -- mod="$m_iogain" dstVar=out
   out = voice->mod_iogain_cur;
   
   // -- mod="fma" dstVar=out
   out = (out * 2.0f) + -1.0f;
   
   // -- mod="bts" dstVar=out
   out = loc_bipolar_to_scale(out, 2.0f, 2.0f);
   
   // -- mod="sto v_i" dstVar=out
   voice->var_v_i = out;
   
   // -- mod="rcp" dstVar=out
   if(0.0f != out)
      out = 1.0f / out;
   
   // -- mod="$m_vol" dstVar=out
   voice->tmp1/*seq*/ = out;
   voice->tmp1/*seq*/ = voice->mod_vol_cur;
   
   // -- mod="fma" dstVar=voice->tmp1/*seq*/
   voice->tmp1/*seq*/ = (voice->tmp1/*seq*/ * 2.0f) + -1.0f;
   
   // -- mod="bts" dstVar=voice->tmp1/*seq*/
   voice->tmp1/*seq*/ = loc_bipolar_to_scale(voice->tmp1/*seq*/, 4.0f, 4.0f);
   out *= voice->tmp1/*seq*/;
   
   // -- mod="pre" dstVar=out
   voice->tmp1/*seq*/ = out;
   
   // -- mod="pan" dstVar=voice->tmp1/*seq*/
   voice->tmp2/*seq*/ = voice->tmp1/*seq*/;
   
   // ---- mod="pan" input "pos" seq 1/1
   
   // -- mod="$prepare__vpan" dstVar=voice->tmp3/*pan_pos*/
   voice->tmp3/*pan_pos*/ = voice->var_prepare__vpan;
   voice->tmp2/*seq*/ = (voice->tmp3/*pan_pos*/ < 0.0f) ? 1.0f : (1.0f - voice->tmp3/*pan_pos*/);
   voice->tmp1/*seq*/ *= voice->tmp2/*seq*/;
   
   // -- mod="sto v_o_l" dstVar=voice->tmp1/*seq*/
   voice->var_v_o_l = voice->tmp1/*seq*/;
   // (ignore last output via '.')
   
   // -- mod="pan" dstVar=out
   voice->tmp1/*seq*/ = out;
   
   // ---- mod="pan" input "pos" seq 1/1
   
   // -- mod="$prepare__vpan" dstVar=voice->tmp2/*pan_pos*/
   voice->tmp2/*pan_pos*/ = voice->var_prepare__vpan;
   voice->tmp1/*seq*/ = (voice->tmp2/*pan_pos*/ > 0.0f) ? 1.0f : (1.0f + voice->tmp2/*pan_pos*/);
   out *= voice->tmp1/*seq*/;
   
   // -- mod="sto v_o_r" dstVar=out
   voice->var_v_o_r = out;
} /* end prepare */


#ifndef CYCLE_SKIP_UI
static unsigned int loc_copy_chars(char *_d, const unsigned int _dSize, const char *_s) {
   unsigned int r = 0u;
   if(NULL != _d)
   {
      // Write min(dSize,len(s)) characters to 'd'
      char *d = _d;
      if(NULL != _s)
      {
         const char *s = _s;
         for(;;)
         {
            if(r < _dSize)
            {
               char c = s[r++];
               *d++ = c;
               if(0 == c)
                  break;
            }
            else
            {
               if(r > 0u)
                  d[-1] = 0;  // force ASCIIZ
               break;
            }
         }
      }
      else
      {
         if(_dSize > 0u)
         {
            _d[0] = 0;
            r = 1u;
         }
      }
   }
   else
   {
      // Return total length of source string
      if(NULL != _s)
      {
         const char *s = _s;
         for(;;)
         {
            char c = s[r++];
            if(0 == c)
               break;
         }
      }
   }
   return r;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static unsigned int loc_copy_floats(float              *_d,
                                    const unsigned int  _dSize,
                                    const float        *_s,
                                    const unsigned int  _sNum
                                    ) {
   unsigned int r = 0u;
   if(NULL != _d)
   {
      // Write min(dSize,sNum) characters to 'd'
      if(NULL != _s)
      {
         unsigned int num = (_sNum > _dSize) ? _dSize : _sNum;
         memcpy((void*)_d, (const void*)_s, num * sizeof(float));
         r = num;
      }
   }
   else
   {
      // Query total number of presets
      r = _sNum;
   }
   return r;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static const char *ST_PLUGIN_API loc_get_param_name(st_plugin_info_t *_info,
                                                    unsigned int      _paramIdx
                                                    ) {
   (void)_info;
   return loc_param_names[_paramIdx];
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static const char *ST_PLUGIN_API loc_get_param_group_name(st_plugin_info_t *_info,
                                                          unsigned int      _paramGroupIdx
                                                          ) {
   (void)_info;
   const char *r = NULL;
   return r;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static unsigned int ST_PLUGIN_API loc_get_param_group_idx(st_plugin_info_t *_info,
                                                          unsigned int      _paramIdx
                                                          ) {
   (void)_info;
   unsigned int r = ~0u;
   return r;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static const char *ST_PLUGIN_API loc_get_param_section_name(st_plugin_info_t *_info,
                                                            unsigned int      _paramSectionIdx
                                                            ) {
   (void)_info;
   const char *r = NULL;
   return r;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static unsigned int ST_PLUGIN_API loc_get_param_section_idx(st_plugin_info_t *_info,
                                                            unsigned int      _paramIdx
                                                            ) {
   (void)_info;
   unsigned int r = ~0u;
   return r;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static float ST_PLUGIN_API loc_get_param_reset(st_plugin_info_t *_info,
                                               unsigned int      _paramIdx
                                               ) {
   (void)_info;
   return loc_param_resets[_paramIdx];
}
#endif // CYCLE_SKIP_UI

static float ST_PLUGIN_API loc_get_param_value(st_plugin_shared_t *_shared,
                                               unsigned int        _paramIdx
                                               ) {
   ST_PLUGIN_SHARED_CAST(stereo_waveshaper_1_shared_t);
   return shared->params[_paramIdx];
}

static void ST_PLUGIN_API loc_set_param_value(st_plugin_shared_t *_shared,
                                              unsigned int        _paramIdx,
                                              float               _value
                                              ) {
   ST_PLUGIN_SHARED_CAST(stereo_waveshaper_1_shared_t);
   shared->params[_paramIdx] = _value;
}

#ifndef CYCLE_SKIP_UI
static unsigned int ST_PLUGIN_API loc_query_dynamic_param_preset_values(st_plugin_shared_t *_shared,
                                                                        const unsigned int  _paramIdx,
                                                                        float              *_retValues,
                                                                        const unsigned int  _retValuesSize
                                                                        ) {
   ST_PLUGIN_SHARED_CAST(stereo_waveshaper_1_shared_t);
   unsigned int r = 0u;
   return r;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static unsigned int ST_PLUGIN_API loc_query_dynamic_param_preset_name(st_plugin_shared_t *_shared,
                                                                      const unsigned int  _paramIdx,
                                                                      const unsigned int  _presetIdx,
                                                                      char               *_retBuf,
                                                                      const unsigned int  _retBufSize
                                                                      ) {
   ST_PLUGIN_SHARED_CAST(stereo_waveshaper_1_shared_t);
   unsigned int r = 0u;
   return r;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static unsigned int ST_PLUGIN_API loc_get_array_param_size(st_plugin_info_t   *_info,
                                                           const unsigned int  _paramIdx
                                                           ) {
   unsigned int r = 0u;
   switch(_paramIdx)
   {
      default:
         break;
   }
   return r;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static unsigned int ST_PLUGIN_API loc_get_array_param_num_variations(st_plugin_info_t   *_info,
                                                                     const unsigned int  _paramIdx
                                                                     ) {
   unsigned int r = 0u;
   switch(_paramIdx)
   {
      default:
         break;
   }
   return r;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static float * ST_PLUGIN_API loc_get_array_param_variation_ptr(st_plugin_shared_t *_shared,
                                                               const unsigned int  _paramIdx,
                                                               const unsigned int  _variationIdx
                                                               ) {
   ST_PLUGIN_SHARED_CAST(stereo_waveshaper_1_shared_t);
   float *r = NULL;
   switch(_paramIdx)
   {
      default:
         break;
   }
   return r;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static void ST_PLUGIN_API loc_set_array_param_edit_variation_idx(st_plugin_shared_t *_shared,
                                                                 const unsigned int  _paramIdx,
                                                                 const int           _variationIdx
                                                                 ) {
   ST_PLUGIN_SHARED_CAST(stereo_waveshaper_1_shared_t);
   switch(_paramIdx)
   {
      default:
         break;
   }
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static const char *ST_PLUGIN_API loc_get_array_param_element_name(st_plugin_info_t   *_info,
                                                                  const unsigned int  _paramIdx,
                                                                  const unsigned int  _elementIdx
                                                                  ) {
   ST_PLUGIN_INFO_CAST(stereo_waveshaper_1_info_t);
   const char *r = NULL;
   switch(_paramIdx)
   {
      default:
         break;
   }
   return r;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static int ST_PLUGIN_API loc_get_array_param_element_value_range(st_plugin_info_t   *_info,
                                                                 const unsigned int  _paramIdx,
                                                                 const unsigned int  _elementIdx,
                                                                 float              *_retStorageMin,
                                                                 float              *_retStorageMax,
                                                                 float              *_retDisplayMin,
                                                                 float              *_retDisplayMax,
                                                                 unsigned int       *_retDisplayPrecision
                                                                 ) {
   (void)_elementIdx;
   switch(_paramIdx)
   {
      default:
         break;
   }
   return 0;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static float ST_PLUGIN_API loc_get_array_param_element_reset(st_plugin_info_t   *_info,
                                                             const unsigned int  _paramIdx,
                                                             const unsigned int  _elementIdx
                                                             ) {
   ST_PLUGIN_INFO_CAST(stereo_waveshaper_1_info_t);
   float r = -999999.0f/*INVALID_VALUE*/;
   switch(_paramIdx)
   {
      default:
         break;
   }
   return r;
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static void ST_PLUGIN_API loc_update_lut(st_plugin_info_t   *_info,
                                         unsigned int        _idx,
                                         const float        *_src,
                                         const unsigned int  _srcNumElements
                                         ) {
   (void)_info;
   unsigned int copySz = 0u;
   (void)copySz;
   switch(_idx)
   {
      default:
         break;
      case 0: // "ws_left"
         copySz = Dstplugin_min(_srcNumElements, 512);
         for(unsigned int i = 0u; i < copySz; i++)
            curve_0[i] = (short)(_src[i] * 2048);
         break;
      case 1: // "ws_right"
         copySz = Dstplugin_min(_srcNumElements, 512);
         for(unsigned int i = 0u; i < copySz; i++)
            curve_1[i] = (short)(_src[i] * 2048);
         break;
   }
}
#endif // CYCLE_SKIP_UI

#ifndef CYCLE_SKIP_UI
static const char *ST_PLUGIN_API loc_get_mod_name(st_plugin_info_t *_info,
                                                  unsigned int      _modIdx
                                                  ) {
   (void)_info;
   return loc_mod_names[_modIdx];
}
#endif // CYCLE_SKIP_UI

static void ST_PLUGIN_API loc_set_sample_rate(st_plugin_voice_t *_voice,
                                              float              _sampleRate
                                              ) {
   ST_PLUGIN_VOICE_CAST(stereo_waveshaper_1_voice_t);
   if(_sampleRate != voice->sample_rate)
   {
      voice->sr_factor = 48000.0f / _sampleRate;
   }
   voice->sample_rate = _sampleRate;
}

static void ST_PLUGIN_API loc_set_bpm(st_plugin_voice_t *_voice,
                                      float              _bpm
                                      ) {
   ST_PLUGIN_VOICE_CAST(stereo_waveshaper_1_voice_t);
   voice->bpm = _bpm;
}

static void ST_PLUGIN_API loc_note_on(st_plugin_voice_t  *_voice,
                                      int                 _bGlide,
                                      unsigned char       _note,
                                      float               _vel
                                      ) {
   ST_PLUGIN_VOICE_CAST(stereo_waveshaper_1_voice_t);
   ST_PLUGIN_VOICE_SHARED_CAST(stereo_waveshaper_1_shared_t);
   (void)_bGlide;
   (void)_note;
   (void)_vel;
   if(!_bGlide)
   {
      memset((void*)voice->mods, 0, sizeof(voice->mods));
#ifdef OVERSAMPLE_FACTOR
      voice->note_speed_fixed = (261.63f/*C-5*/ / (voice->sample_rate * OVERSAMPLE_FACTOR));
#else
      voice->note_speed_fixed = (261.63f/*C-5*/ / voice->sample_rate);
#endif // OVERSAMPLE_FACTOR
      voice->velocity = _vel;
      voice->var_x = 0.0f;
      voice->var_v_i = 0.0f;
      voice->var_v_o_l = 0.0f;
      voice->var_v_o_r = 0.0f;
      voice->var_prepare__vpan = 0.0f;
   }
}

static void ST_PLUGIN_API loc_set_mod_value(st_plugin_voice_t *_voice,
                                            unsigned int       _modIdx,
                                            float              _value,
                                            unsigned           _frameOffset
                                            ) {
   ST_PLUGIN_VOICE_CAST(stereo_waveshaper_1_voice_t);
   (void)_frameOffset;
   voice->mods[_modIdx] = _value;
}

static void ST_PLUGIN_API loc_prepare_block(st_plugin_voice_t *_voice,
                                            unsigned int       _numFrames,
                                            float              _freqHz,
                                            float              _note,
                                            float              _vol,
                                            float              _pan
                                            ) {
   ST_PLUGIN_VOICE_CAST(stereo_waveshaper_1_voice_t);
   ST_PLUGIN_VOICE_SHARED_CAST(stereo_waveshaper_1_shared_t);
   (void)_note;
   (void)_vol;
   (void)_pan;

#ifdef OVERSAMPLE_FACTOR
   float noteSpeed = _freqHz / (voice->sample_rate * OVERSAMPLE_FACTOR);
#else
   float noteSpeed = _freqHz / voice->sample_rate;
#endif // OVERSAMPLE_FACTOR

   float moddrywet       = shared->params[PARAM_DRYWET      ]                       + voice->mods[MOD_DRYWET       ];
   float modiogain       = shared->params[PARAM_IOGAIN      ]                       + voice->mods[MOD_IOGAIN       ];
   float modpan          = shared->params[PARAM_PAN         ]                       + voice->mods[MOD_PAN          ];
   float modvol          = shared->params[PARAM_VOL         ]                       + voice->mods[MOD_VOL          ];

   if(_numFrames > 0u)
   {
      // lerp
#ifdef OVERSAMPLE_FACTOR
      float recBlockSize = (1.0f / (_numFrames * OVERSAMPLE_FACTOR));
#else
      float recBlockSize = (1.0f / _numFrames);
#endif // OVERSAMPLE_FACTOR
      voice->note_speed_inc = (noteSpeed - voice->note_speed_cur) * recBlockSize;
      voice->note_inc       = (_note - voice->note_cur) * recBlockSize;
      voice->mod_drywet_inc       = (moddrywet          - voice->mod_drywet_cur        ) * recBlockSize;
      voice->mod_iogain_inc       = (modiogain          - voice->mod_iogain_cur        ) * recBlockSize;
      voice->mod_pan_inc          = (modpan             - voice->mod_pan_cur           ) * recBlockSize;
      voice->mod_vol_inc          = (modvol             - voice->mod_vol_cur           ) * recBlockSize;
      loc_prepare(&voice->base);
   }
   else
   {
      // initial params/modulation (first block, not rendered)
      voice->note_speed_cur = noteSpeed;
      voice->note_speed_inc = 0.0f;
      voice->note_cur       = _note;
      voice->note_inc       = 0.0f;
      voice->mod_drywet_cur       = moddrywet;
      voice->mod_drywet_inc       = 0.0f;
      voice->mod_iogain_cur       = modiogain;
      voice->mod_iogain_inc       = 0.0f;
      voice->mod_pan_cur          = modpan;
      voice->mod_pan_inc          = 0.0f;
      voice->mod_vol_cur          = modvol;
      voice->mod_vol_inc          = 0.0f;
      loc_prepare(&voice->base);
   }

   // printf("xxx note_cur=%f\n", voice->note_cur);
   // printf("xxx prepare_block: numFrames=%u moda=%f\n", _numFrames, moda);
   // printf("xxx voice->voicebus_idx_0=%u voice->base.voice_bus_read_offset=%u\n", voice->voicebus_idx_0, voice->base.voice_bus_read_offset);
}

static void ST_PLUGIN_API loc_process_replace(st_plugin_voice_t  *_voice,
                                              int                 _bMonoIn,
                                              const float        *_samplesIn,
                                              float              *_samplesOut,
                                              unsigned int        _numFrames
                                              ) {
   (void)_bMonoIn;
   (void)_samplesIn;

   ST_PLUGIN_VOICE_CAST(stereo_waveshaper_1_voice_t);
   ST_PLUGIN_VOICE_SHARED_CAST(stereo_waveshaper_1_shared_t);

   // Mono output (replicate left to right channel)
   unsigned int j = 0u;
#ifndef STEREO
   unsigned int jStep = _bMonoIn ? 1u : 2u;
#endif // STEREO
   unsigned int k = 0u;
   for(unsigned int i = 0u; i < _numFrames; i++)
   {
      const float inL = _samplesIn[j];
#ifdef STEREO
      float outL;
      float outR;
      const float inR = _samplesIn[j + 1u];
#endif // STEREO
      float out;
#ifdef OVERSAMPLE_FACTOR
#ifdef STEREO
      float outOSL = 0.0f;
      float outOSR = 0.0f;
#else
      float outOS = 0.0f;
#endif // STEREO
#endif // OVERSAMPLE_FACTOR

#ifdef OVERSAMPLE_FACTOR
      for(unsigned int osi = 0u; osi < OVERSAMPLE_FACTOR; osi++)
#endif // OVERSAMPLE_FACTOR
      {
#ifdef STEREO
         out = outL = inL;
         outR = inR;
#else
         out = inL;
#endif // STEREO
      float tmp_f; (void)tmp_f;
      float tmp2_f; (void)tmp2_f;
      
      // ========
      // ======== lane "out" modIdx=0 modString=rdl
      // ========
      
      // -- mod="rdl" dstVar=out
      out = inL;
      
      // -- mod="ipl" dstVar=out
      voice->tmp4/*b*/ = out;
      
      // ---- mod="ipl" input "b" seq 1/1
      
      // -- mod="$v_i" dstVar=voice->tmp4/*b*/
      voice->tmp5/*seq*/ = voice->tmp4/*b*/;
      voice->tmp5/*seq*/ = voice->var_v_i;
      voice->tmp4/*b*/ *= voice->tmp5/*seq*/;
      
      // -- mod="lut" dstVar=voice->tmp4/*b*/
      voice->tmp6/*lut_bip_sign*/ = (voice->tmp4/*b*/ < 0.0f);
      if(voice->tmp6/*lut_bip_sign*/) voice->tmp4/*b*/ = -voice->tmp4/*b*/;
      voice->tmp5/*lut_f*/ = (voice->tmp4/*b*/ * 512);
      voice->tmp9/*lut_frac*/ = voice->tmp5/*lut_f*/ - (int)voice->tmp5/*lut_f*/;
      voice->tmp7/*lut_idx_a*/ = (int)voice->tmp5/*lut_f*/;
      if(voice->tmp7/*lut_idx_a*/ < 0)
      {
         voice->tmp7/*lut_idx_a*/ = 0;
         voice->tmp8/*lut_idx_b*/ = 0;
         voice->tmp9/*lut_frac*/ = 0.0f;
      }
      else if(voice->tmp7/*lut_idx_a*/ > 511)
      {
         voice->tmp7/*lut_idx_a*/ = 511;
         voice->tmp8/*lut_idx_b*/ = 511;
      }
      else
      {
         voice->tmp8/*lut_idx_b*/ = voice->tmp7/*lut_idx_a*/ + 1;
         if(voice->tmp8/*lut_idx_b*/ > 511)
            voice->tmp8/*lut_idx_b*/ = 511;
      }
      voice->tmp10/*lut_a*/ = curve_0[(unsigned int)voice->tmp7/*lut_idx_a*/] * (1.0f / 2048);
      voice->tmp11/*lut_b*/ = curve_0[(unsigned int)voice->tmp8/*lut_idx_b*/] * (1.0f / 2048);
      voice->tmp4/*b*/ = voice->tmp10/*lut_a*/ + (voice->tmp11/*lut_b*/ - voice->tmp10/*lut_a*/) * voice->tmp9/*lut_frac*/;
      if(voice->tmp6/*lut_bip_sign*/) voice->tmp4/*b*/ = -voice->tmp4/*b*/;
      
      // -- mod="$v_o_l" dstVar=voice->tmp4/*b*/
      voice->tmp5/*seq*/ = voice->tmp4/*b*/;
      voice->tmp5/*seq*/ = voice->var_v_o_l;
      voice->tmp4/*b*/ *= voice->tmp5/*seq*/;
      voice->tmp5/*t*/ = out;
      
      // ---- mod="ipl" input "t" seq 1/1
      
      // -- mod="$m_drywet" dstVar=voice->tmp5/*t*/
      voice->tmp5/*t*/ = voice->mod_drywet_cur;
      out = out + (voice->tmp4/*b*/ - out) * voice->tmp5/*t*/;
      
      // -- mod="wrl" dstVar=out
      outL = out;
      
      // -- mod="rdr" dstVar=out
      out = inR;
      
      // -- mod="ipl" dstVar=out
      voice->tmp4/*b*/ = out;
      
      // ---- mod="ipl" input "b" seq 1/1
      
      // -- mod="$v_i" dstVar=voice->tmp4/*b*/
      voice->tmp5/*seq*/ = voice->tmp4/*b*/;
      voice->tmp5/*seq*/ = voice->var_v_i;
      voice->tmp4/*b*/ *= voice->tmp5/*seq*/;
      
      // -- mod="lut" dstVar=voice->tmp4/*b*/
      voice->tmp6/*lut_bip_sign*/ = (voice->tmp4/*b*/ < 0.0f);
      if(voice->tmp6/*lut_bip_sign*/) voice->tmp4/*b*/ = -voice->tmp4/*b*/;
      voice->tmp5/*lut_f*/ = (voice->tmp4/*b*/ * 512);
      voice->tmp9/*lut_frac*/ = voice->tmp5/*lut_f*/ - (int)voice->tmp5/*lut_f*/;
      voice->tmp7/*lut_idx_a*/ = (int)voice->tmp5/*lut_f*/;
      if(voice->tmp7/*lut_idx_a*/ < 0)
      {
         voice->tmp7/*lut_idx_a*/ = 0;
         voice->tmp8/*lut_idx_b*/ = 0;
         voice->tmp9/*lut_frac*/ = 0.0f;
      }
      else if(voice->tmp7/*lut_idx_a*/ > 511)
      {
         voice->tmp7/*lut_idx_a*/ = 511;
         voice->tmp8/*lut_idx_b*/ = 511;
      }
      else
      {
         voice->tmp8/*lut_idx_b*/ = voice->tmp7/*lut_idx_a*/ + 1;
         if(voice->tmp8/*lut_idx_b*/ > 511)
            voice->tmp8/*lut_idx_b*/ = 511;
      }
      voice->tmp10/*lut_a*/ = curve_1[(unsigned int)voice->tmp7/*lut_idx_a*/] * (1.0f / 2048);
      voice->tmp11/*lut_b*/ = curve_1[(unsigned int)voice->tmp8/*lut_idx_b*/] * (1.0f / 2048);
      voice->tmp4/*b*/ = voice->tmp10/*lut_a*/ + (voice->tmp11/*lut_b*/ - voice->tmp10/*lut_a*/) * voice->tmp9/*lut_frac*/;
      if(voice->tmp6/*lut_bip_sign*/) voice->tmp4/*b*/ = -voice->tmp4/*b*/;
      
      // -- mod="$v_o_r" dstVar=voice->tmp4/*b*/
      voice->tmp5/*seq*/ = voice->tmp4/*b*/;
      voice->tmp5/*seq*/ = voice->var_v_o_r;
      voice->tmp4/*b*/ *= voice->tmp5/*seq*/;
      voice->tmp5/*t*/ = out;
      
      // ---- mod="ipl" input "t" seq 1/1
      
      // -- mod="$m_drywet" dstVar=voice->tmp5/*t*/
      voice->tmp5/*t*/ = voice->mod_drywet_cur;
      out = out + (voice->tmp4/*b*/ - out) * voice->tmp5/*t*/;
      
      // -- mod="wrr" dstVar=out
      outR = out;

      /* end calc */

#ifdef OVERSAMPLE_FACTOR
#ifdef STEREO
         outOSL += outL;
         outOSR += outR;
#else
         outOS += out;
#endif // STEREO
#endif // OVERSAMPLE_FACTOR
         voice->note_speed_cur += voice->note_speed_inc;
         voice->note_cur       += voice->note_inc;
         voice->mod_drywet_cur     += voice->mod_drywet_inc;
         voice->mod_iogain_cur     += voice->mod_iogain_inc;
         voice->mod_pan_cur        += voice->mod_pan_inc;
         voice->mod_vol_cur        += voice->mod_vol_inc;
      }
#ifdef OVERSAMPLE_FACTOR
      // Apply lowpass filter before downsampling
      //   (note) normalized Fc = F/Fs = 0.442947 / sqrt(oversample_factor^2 - 1)
#ifdef STEREO
      outL = outOSL * (1.0f / OVERSAMPLE_FACTOR);
      outR = outOSR * (1.0f / OVERSAMPLE_FACTOR);
#else
      out = outOS * (1.0f / OVERSAMPLE_FACTOR);
#endif // STEREO
#endif // OVERSAMPLE_FACTOR
#ifdef STEREO
      outL = Dstplugin_fix_denorm_32(outL);
      outR = Dstplugin_fix_denorm_32(outR);
#else
      out = Dstplugin_fix_denorm_32(out);
#endif // STEREO
#ifdef STEREO
      _samplesOut[k]      = outL;
      _samplesOut[k + 1u] = outR;
#else
      _samplesOut[k]      = out;
      _samplesOut[k + 1u] = out;
#endif // STEREO

      // Next frame
      k += 2u;
#ifdef STEREO
      j += 2u;
#else
      j += jStep;
#endif // STEREO
   } /* loop numFrames */
}

static st_plugin_shared_t *ST_PLUGIN_API loc_shared_new(st_plugin_info_t *_info) {
   stereo_waveshaper_1_shared_t *ret = (stereo_waveshaper_1_shared_t *)malloc(sizeof(stereo_waveshaper_1_shared_t));
   if(NULL != ret)
   {
      memset((void*)ret, 0, sizeof(*ret));
      ret->base.info  = _info;
      memcpy((void*)ret->params, (void*)loc_param_resets, NUM_PARAMS * sizeof(float));
   }
   return &ret->base;
}

static void ST_PLUGIN_API loc_shared_delete(st_plugin_shared_t *_shared) {
   free((void*)_shared);
}

static st_plugin_voice_t *ST_PLUGIN_API loc_voice_new(st_plugin_info_t *_info, unsigned int _voiceIdx) {
   stereo_waveshaper_1_voice_t *voice = (stereo_waveshaper_1_voice_t *)malloc(sizeof(stereo_waveshaper_1_voice_t));
   if(NULL != voice)
   {
      memset((void*)voice, 0, sizeof(*voice));
      voice->base.info = _info;
   }
   return &voice->base;
}

static void ST_PLUGIN_API loc_voice_delete(st_plugin_voice_t *_voice) {
   ST_PLUGIN_VOICE_CAST(stereo_waveshaper_1_voice_t);

   free((void*)_voice);
   }

static void ST_PLUGIN_API loc_plugin_exit(st_plugin_info_t *_info) {
   free((void*)_info);
}

#ifdef USE_CYCLE_SINE_TBL
static void loc_calc_sine_tbl(void) {
#define QCOS_BITS 16
#define QCOS_ONE  (1 << QCOS_BITS)
#define QCOS_MASK (QCOS_ONE - 1)
   // (note) same as in TSR "C" implementation
   float *qcos = cycle_sine_tbl_f + 4096; // quarter cos tbl

   // calc quarter cos tbl
   int k = 0;
   for(int a = 0; a < (QCOS_ONE/4); a += (QCOS_ONE/16384)/*4*/)  // 4096 elements
   {
      int x = a - ((int)(QCOS_ONE * 0.25 + 0.5)) + ((a + ((int)(QCOS_ONE * 0.25 + 0.5)))&~QCOS_MASK);
      x = ((x * ((x<0?-x:x) - ((int)(QCOS_ONE * 0.5 + 0.5)))) >> QCOS_BITS) << 4;
      x += (((((int)(QCOS_ONE * 0.225 + 0.5)) * x) >> QCOS_BITS) * ((x<0?-x:x) - QCOS_ONE)) >> QCOS_BITS;
      qcos[k++] = x / float(QCOS_ONE);
   }

   // 0..90deg (rev qtbl)
   int j = 4096;
   k = 0;
   loop(4096)
      cycle_sine_tbl_f[k++] = qcos[--j];

   // 90..180deg = cos tbl
   k += 4096;

   // 180..360deg (y-flip first half of tbl)
   j = 0;
   loop(8192)
      cycle_sine_tbl_f[k++] = -cycle_sine_tbl_f[j++];

#ifdef USE_CYCLE_SINE_TBL_I
   loop(16384)
      cycle_sine_tbl_i[i] = (short)(cycle_sine_tbl_f[i] * 2048.0f/*FX_ONE*/);
#endif // USE_CYCLE_SINE_TBL_I
}
#endif // USE_CYCLE_SINE_TBL

#ifdef USE_CYCLE_HSE_TBL
#endif // USE_CYCLE_HSE_TBL

extern "C" {
st_plugin_info_t *stereo_waveshaper_1_init(void) {
   stereo_waveshaper_1_info_t *ret = (stereo_waveshaper_1_info_t *)malloc(sizeof(stereo_waveshaper_1_info_t));

   if(NULL != ret)
   {
      memset(ret, 0, sizeof(*ret));

      ret->base.api_version = ST_PLUGIN_API_VERSION;
      ret->base.id          = "stereo_waveshaper_1";  // unique id. don't change this in future builds.
      ret->base.author      = "bsp";
      ret->base.name        = "stereo_waveshaper_1";
      ret->base.short_name  = "stereo_waveshaper_1";
      ret->base.flags       = ST_PLUGIN_FLAG_FX;
      ret->base.category    = ST_PLUGIN_CAT_WAVESHAPER;
      ret->base.num_params  = NUM_PARAMS;
      ret->base.num_mods    = NUM_MODS;

      ret->base.shared_new                          = &loc_shared_new;
      ret->base.shared_delete                       = &loc_shared_delete;
      ret->base.voice_new                           = &loc_voice_new;
      ret->base.voice_delete                        = &loc_voice_delete;
#ifndef CYCLE_SKIP_UI
      ret->base.get_param_name                      = &loc_get_param_name;
      ret->base.get_param_group_name                = &loc_get_param_group_name;
      ret->base.get_param_group_idx                 = &loc_get_param_group_idx;
      ret->base.get_param_section_name              = &loc_get_param_section_name;
      ret->base.get_param_section_idx               = &loc_get_param_section_idx;
      ret->base.get_param_reset                     = &loc_get_param_reset;
      ret->base.query_dynamic_param_preset_values   = &loc_query_dynamic_param_preset_values;
      ret->base.query_dynamic_param_preset_name     = &loc_query_dynamic_param_preset_name;
      ret->base.get_array_param_size                = &loc_get_array_param_size;
      ret->base.get_array_param_num_variations      = &loc_get_array_param_num_variations;
      ret->base.get_array_param_variation_ptr       = &loc_get_array_param_variation_ptr;
      ret->base.set_array_param_edit_variation_idx  = &loc_set_array_param_edit_variation_idx;
      ret->base.get_array_param_element_name        = &loc_get_array_param_element_name;
      ret->base.get_array_param_element_value_range = &loc_get_array_param_element_value_range;
      ret->base.get_array_param_element_reset       = &loc_get_array_param_element_reset;
      ret->base.update_lut                          = &loc_update_lut;
#endif // CYCLE_SKIP_UI
      ret->base.get_param_value                     = &loc_get_param_value;
      ret->base.set_param_value                     = &loc_set_param_value;
#ifndef CYCLE_SKIP_UI
      ret->base.get_mod_name                        = &loc_get_mod_name;
#endif // CYCLE_SKIP_UI
      ret->base.set_sample_rate                     = &loc_set_sample_rate;
      ret->base.set_bpm                             = &loc_set_bpm;
      ret->base.note_on                             = &loc_note_on;
      ret->base.set_mod_value                       = &loc_set_mod_value;
      ret->base.prepare_block                       = &loc_prepare_block;
      ret->base.process_replace                     = &loc_process_replace;
      ret->base.plugin_exit                         = &loc_plugin_exit;

#ifdef USE_CYCLE_SINE_TBL
      loc_calc_sine_tbl();
#endif // USE_CYCLE_SINE_TBL
   }

   return &ret->base;
}

#ifndef STFX_SKIP_MAIN_INIT
ST_PLUGIN_APICALL st_plugin_info_t *ST_PLUGIN_API st_plugin_init(unsigned int _pluginIdx) {
   switch(_pluginIdx)
   {
      case 0u:
         return stereo_waveshaper_1_init();
   }
   return NULL;
}
#endif // STFX_SKIP_MAIN_INIT

} // extern "C"
