#ifndef __LUT_H__
#define __LUT_H__
template <int LBound = -128, int UBound = 127, class TResult = double, int ScaleFactor = 1>
class LUT_number
{
public:
explicit LUT_number (double val = 0)
{
lut = lut_array - LBound;
for (int i = LBound; i <= UBound; i++)
{
lut[i] = i * ScaleFactor * val;
}
}
const TResult & operator* (int val) const
{
return lut[val];
}
private:
TResult lut_array[UBound - LBound + 1];
TResult * lut;
};
template <int LBound, int UBound, class TResult, int ScaleFactor>
inline const TResult & operator* (int val, const LUT_number<LBound, UBound,
TResult, ScaleFactor> & coeff)
{
return coeff * val;
}
template <int LBound = -128, int UBound = 127, class TResult = double, class TArg = double>
class LUT_function
{
public:
explicit LUT_function (TResult (*f) (TArg), double coeff = 1)
{
lut = lut_array - LBound;
for (int i = LBound; i <= UBound; i++)
{
lut[i] = f(coeff * i);
}
}
const TResult & operator() (int i) const
{
return lut[i];
}
private:
TResult lut_array[UBound - LBound + 1];
TResult * lut;
};
#endif
Return to article