/*
  !MidiPlay   A MIDI synthesiser and file player.

  exp.h - Trackbar law conversion tables

  created  13/04/12
  1.0      14/06/14
  2.0      07/01/21 added e4kg table for generator gain adjust (Q10 -12dB to + 12dB)
*/

#ifndef exp_h
#define exp_h

#define LEN 101

// 32k table
static const unsigned short int e32k[LEN] =
{
  0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,19,21,23,25,27,30,32,35,39,42,46,51,55,
  61,66,73,79,87,95,104,114,124,136,149,163,178,195,213,233,255,279,306,334,366,
  400,438,479,524,573,627,686,751,822,899,983,1076,1177,1288,1409,1541,1686,1845,
  2019,2209,2416,2644,2892,3164,3462,3788,4144,4534,4960,5427,5938,6496,7107,7776,
  8507,9307,10183,11141,12189,13335,14590,15962,17464,19107,20904,22870,25022,27375,
  29951,32767
};

// 32k table, inverse law
static const unsigned short int e32ki[LEN] =
{
  0,1963,3808,5542,7173,8706,10147,11502,12776,13974,15099,16158,17152,18088,18967,
  19794,20571,21301,21988,22634,23241,23812,24348,24852,25326,25772,26191,26585,
  26955,27304,27631,27939,28228,28500,28755,28996,29222,29434,29634,29822,29998,
  30164,30320,30467,30604,30734,30856,30970,31078,31179,31274,31364,31448,31527,
  31601,31671,31737,31799,31857,31911,31963,32011,32056,32099,32139,32177,32212,
  32245,32277,32306,32334,32360,32384,32407,32429,32449,32468,32486,32503,32519,
  32534,32548,32561,32573,32585,32596,32606,32616,32625,32634,32642,32649,32656,
  32663,32669,32675,32681,32686,32691,32696,32700
};

// 8k table
static const unsigned short int e8k[LEN] =
{
  0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,22,23,25,27,29,32,34,37,39,
  42,46,49,53,57,62,66,71,77,83,89,96,103,111,120,129,139,150,161,174,187,201,217,
  234,251,271,292,314,338,364,392,422,455,490,528,568,612,659,710,764,823,887,955,
  1028,1107,1193,1284,1383,1489,1604,1727,1860,2004,2158,2324,2502,2695,2902,3126,
  3366,3625,3904,4204,4528,4876,5251,5655,6090,6559,7063,7607,8191
};

// 4k table
static const unsigned short int e4k[LEN] =
{
  0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,21,22,24,26,27,29,31,33,36,
  38,41,43,46,50,53,57,60,65,69,74,79,84,90,96,102,109,117,125,133,142,152,162,173,
  185,198,211,226,241,257,275,294,314,335,358,382,408,436,466,497,531,568,606,647,
  692,739,789,843,900,961,1027,1097,1171,1251,1336,1427,1525,1628,1739,1858,1984,
  2119,2264,2418,2583,2759,2946,3147,3361,3590,3835,4095
};

// 1k table
static const unsigned short int e1k[LEN] =
{
  0,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,28,
  29,31,32,34,36,37,39,41,43,46,48,50,53,55,58,61,64,68,71,75,78,82,87,91,96,100,
  105,111,116,122,129,135,142,149,157,165,173,182,191,201,211,221,233,244,257,270,
  283,298,313,329,345,363,381,400,421,442,464,488,513,539,566,595,625,656,690,725,
  761,800,840,883,928,975,1023
};

// 1k table, inverse law
static const unsigned short int e1ki[LEN] =
{
  1,49,96,141,184,224,263,299,334,368,399,429,458,485,511,536,560,582,603,624,643,
  661,679,695,711,726,741,754,767,780,791,803,813,823,833,842,851,859,867,875,882,
  889,895,902,908,913,919,924,928,933,937,942,946,949,953,956,960,963,966,969,971,
  974,976,978,981,983,985,987,988,990,992,993,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
};

// 10k table (16384)
static const unsigned short int e10k[LEN] =
{
  200,210,220,230,240,251,262,274,286,299,313,327,341,357,373,389,407,425,444,464,
  485,507,530,554,579,605,632,660,690,721,753,787,823,860,898,939,981,1025,1071,
  1119,1170,1222,1277,1335,1395,1458,1523,1592,1663,1738,1816,1898,1983,2072,2166,
  2263,2365,2471,2582,2698,2820,2947,3079,3218,3362,3514,3672,3837,4009,4190,4378,
  4575,4781,4996,5220,5455,5700,5957,6225,6505,6797,7103,7422,7756,8105,8469,8850,
  9248,9664,10099,10553,11027,11523,12042,12583,13149,13740,14358,15004,15679,16383
};

// 4k table, +- 12dB gain range (Q10)
static const unsigned short int e4k12db[LEN] =
{
  255,263,270,278,286,294,302,310,319,328,337,347,357,367,377,388,398,410,421,433,
  445,458,471,484,497,511,526,541,556,572,588,604,621,639,657,675,694,714,734,754,
  776,797,820,843,867,891,916,942,968,995,1024,1052,1082,1112,1144,1176,1209,1243,
  1278,1314,1351,1389,1428,1468,1509,1552,1595,1640,1686,1734,1782,1833,1884,1937,
  1991,2048,2105,2164,2225,2288,2352,2418,2486,2556,2628,2702,2778,2856,2936,3019,
  3104,3191,3281,3373,3468,3565,3666,3769,3875,3983,4096
};

// 4k table, +- 20dB gain range (Q10)
static const unsigned short int e4k20db[LEN] =
{
  102,107,112,117,123,128,134,141,148,154,162,169,177,186,195,204,213,224,234,245,
  257,269,282,295,309,323,339,355,371,389,407,426,446,468,490,513,537,562,589,617,
  646,676,708,741,776,813,851,891,933,977,1024,1072,1122,1175,1231,1289,1349,1413,
  1480,1549,1622,1699,1779,1863,1951,2043,2139,2240,2345,2456,2572,2693,2820,2953,
  3092,3238,3390,3550,3717,3893,4076,4268,4469,4680,4901,5132,5374,5627,5892,6170,
  6461,6765,7084,7418,7767,8133,8517,8918,9338,9779,10240
};

#endif

