1
1

curve.h 900 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include "settings.h"
  3. inline byte calcCurve(CurveSettings curveSettings, int Value)
  4. {
  5. int ret = 0;
  6. float x = Value * 8.0;
  7. float f = ((float)curveSettings.value) / 64.0; //[1;127]->[0.;2.0]
  8. switch(curveSettings.type) {
  9. //[0-1023]x[0-127]
  10. case 0:
  11. ret = x * f / 16.0;
  12. break;
  13. case 1:
  14. ret = (127.0 / (exp(2.0 * f) - 1)) * (exp(f * x / 512.0) - 1.0);
  15. break; //Exp 4*(exp(x/256)-1)
  16. case 2:
  17. ret = log(1.0 + (f * x / 128.0)) * (127.0 / log((8 * f) + 1));
  18. break; //Log 64*log(1+x/128)
  19. case 3:
  20. ret = (127.0 / (1.0 + exp(f * (512.0 - x) / 64.0)));
  21. break; //Sigma
  22. case 4:
  23. ret = (64.0 - ((8.0 / f) * log((1024 / (1 + x)) - 1)));
  24. break; //Flat
  25. case eXTRA:
  26. ret = (x + 0x20) * f / 16.0;
  27. }
  28. ret = ret * (curveSettings.factor / 127.0) + curveSettings.offset;
  29. if(ret <= 0) { return 0; }
  30. if(ret >= 127) { return 127; } //127
  31. return ret;
  32. }