amuse/lib/VolumeTable.cpp

296 lines
4.3 KiB
C++
Raw Normal View History

2018-08-16 06:26:44 +00:00
#include "amuse/VolumeTable.hpp"
#include "amuse/Common.hpp"
namespace amuse
{
static const float VolumeTable[] =
{
0.000000,
0.000031,
0.000153,
0.000397,
0.000702,
0.001129,
0.001648,
0.002228,
0.002930,
0.003723,
0.004608,
0.005585,
0.006653,
0.007843,
0.009125,
0.010498,
0.011963,
0.013550,
0.015198,
0.016999,
0.018860,
0.020844,
0.022919,
0.025117,
0.027406,
0.029817,
0.032319,
0.034944,
0.037660,
0.040468,
0.043428,
0.046480,
0.049623,
0.052889,
0.056276,
0.059786,
0.063387,
0.067110,
0.070956,
0.074923,
0.078982,
0.083163,
0.087466,
0.091922,
0.096469,
0.101138,
0.105930,
0.110843,
0.115879,
0.121036,
0.126347,
0.131748,
0.137303,
0.142979,
0.148778,
0.154729,
0.160772,
0.166997,
0.173315,
0.179785,
0.186407,
0.193121,
0.200018,
0.207007,
0.214179,
0.221473,
0.228919,
0.236488,
0.244209,
0.252083,
0.260079,
0.268258,
0.276559,
0.285012,
0.293649,
0.302408,
0.311319,
0.320383,
0.329600,
0.339000,
0.348521,
0.358226,
0.368084,
0.378094,
0.388287,
0.398633,
0.409131,
0.419813,
0.430647,
0.441664,
0.452864,
0.464217,
0.475753,
0.487442,
0.499313,
0.511399,
0.523606,
0.536027,
0.548631,
0.561419,
0.574389,
0.587542,
0.600879,
0.614399,
0.628132,
0.642018,
0.656148,
0.670431,
0.684927,
0.699637,
0.714530,
0.729637,
0.744926,
0.760430,
0.776147,
0.792077,
0.808191,
0.824549,
0.841090,
0.857845,
0.874844,
0.892056,
0.909452,
0.927122,
0.945006,
0.963073,
0.981414,
1.000000,
1.000000
};
static const float DLSVolumeTable[] =
{
0.000000,
0.000062,
0.000248,
0.000558,
0.000992,
0.001550,
0.002232,
0.003038,
0.003968,
0.005022,
0.006200,
0.007502,
0.008928,
0.010478,
0.012152,
0.013950,
0.015872,
0.017918,
0.020088,
0.022382,
0.024800,
0.027342,
0.030008,
0.032798,
0.035712,
0.038750,
0.041912,
0.045198,
0.048608,
0.052142,
0.055800,
0.059582,
0.063488,
0.067518,
0.071672,
0.075950,
0.080352,
0.084878,
0.089528,
0.094302,
0.099200,
0.104222,
0.109368,
0.114638,
0.120032,
0.125550,
0.131192,
0.136958,
0.142848,
0.148862,
0.155000,
0.161262,
0.167648,
0.174158,
0.180792,
0.187550,
0.194432,
0.201438,
0.208568,
0.215822,
0.223200,
0.230702,
0.238328,
0.246078,
0.253953,
0.261951,
0.270073,
0.278319,
0.286689,
0.295183,
0.303801,
0.312543,
0.321409,
0.330399,
0.339513,
0.348751,
0.358113,
0.367599,
0.377209,
0.386943,
0.396801,
0.406783,
0.416889,
0.427119,
0.437473,
0.447951,
0.458553,
0.469279,
0.480129,
0.491103,
0.502201,
0.513423,
0.524769,
0.536239,
0.547833,
0.559551,
0.571393,
0.583359,
0.595449,
0.607663,
0.620001,
0.632463,
0.645049,
0.657759,
0.670593,
0.683551,
0.696633,
0.709839,
0.723169,
0.736623,
0.750202,
0.763904,
0.777730,
0.791680,
0.805754,
0.819952,
0.834274,
0.848720,
0.863290,
0.877984,
0.892802,
0.907744,
0.922810,
0.938000,
0.953314,
0.968752,
0.984314,
1.000000,
1.000000
};
float LookupVolume(float vol)
{
vol = amuse::clamp(0.f, vol * 127.f, 127.f);
float f = std::floor(vol);
float c = std::ceil(vol);
if (f == c)
return VolumeTable[int(f)];
float t = vol - f;
return (1.f - t) * VolumeTable[int(f)] + t * VolumeTable[int(c)];
}
float LookupDLSVolume(float vol)
{
vol = amuse::clamp(0.f, vol * 127.f, 127.f);
float f = std::floor(vol);
float c = std::ceil(vol);
if (f == c)
return DLSVolumeTable[int(f)];
float t = vol - f;
return (1.f - t) * DLSVolumeTable[int(f)] + t * DLSVolumeTable[int(c)];
}
}