23#define clamp(v, m, x) min(max(v, m), x)
33double EMAvg(
double lastVal,
double newVal,
int memCount);
45template <
class T,
class A,
class B,
class C,
class D>
46T
cMap(T x, A inMin, B inMax, C outMin, D outMax) {
47 T mapped = map(x, inMin, inMax, outMin, outMax);
75 this->samples = samples;
83 operator T()
const {
return (T)avg; }
92 avg =
EMAvg(avg, val, samples);
119 this->pointer = pointer;
120 this->samples = samples;
129 avg =
EMAvg(avg, *pointer, samples);
T cMap(T x, A inMin, B inMax, C outMin, D outMax)
Map a value from one range to another while clamping the value to boundaries.
double EMAvg(double lastVal, double newVal, int memCount)
Exponential moving average.
Variable that automaticaly averages itself out when it is set to a value.
AvgVar(int samples)
Construct a new AvgVar given the number of samples to average the value over.
T operator=(T val)
Update the internal average value given the next value.
Variable that automaticaly averages itself out when it is called, that is, it only updates it's avera...
AvgVarRef(T *pointer, int samples)
Construct a new AvgVar Ref given the number of samples to average the value over and the pointer to t...