29template <
typename FloatType>
35template <
typename FloatType>
37 size_t numPointsToUse)
39 initialise (functionToApproximate, numPointsToUse);
43template <
typename FloatType>
45 size_t numPointsToUse)
47 data.resize (
static_cast<int> (getRequiredBufferSize (numPointsToUse)));
49 for (
size_t i = 0; i < numPointsToUse; ++i)
51 auto value = functionToApproximate (i);
53 jassert (! std::isnan (value));
54 jassert (! std::isinf (value));
58 data.getReference (
static_cast<int> (i)) = value;
64template <
typename FloatType>
67 auto guardIndex =
static_cast<int> (getGuardIndex());
68 data.getReference (guardIndex) = data.
getUnchecked (guardIndex - 1);
71template <
typename FloatType>
73 FloatType minInputValueToUse,
74 FloatType maxInputValueToUse,
77 jassert (maxInputValueToUse > minInputValueToUse);
79 minInputValue = minInputValueToUse;
80 maxInputValue = maxInputValueToUse;
81 scaler = FloatType (numPoints - 1) / (maxInputValueToUse - minInputValueToUse);
82 offset = -minInputValueToUse * scaler;
84 const auto initFn = [functionToApproximate, minInputValueToUse, maxInputValueToUse, numPoints] (
size_t i)
86 return functionToApproximate (
88 minInputValueToUse, maxInputValueToUse,
89 jmap (FloatType (i), FloatType (0), FloatType (numPoints - 1), minInputValueToUse, maxInputValueToUse))
93 lookupTable.initialise (initFn, numPoints);
97template <
typename FloatType>
99 FloatType minInputValue,
100 FloatType maxInputValue,
102 size_t numTestPoints)
104 jassert (maxInputValue > minInputValue);
106 if (numTestPoints == 0)
107 numTestPoints = 100 * numPoints;
109 LookupTableTransform transform (functionToApproximate, minInputValue, maxInputValue, numPoints);
113 for (
size_t i = 0; i < numTestPoints; ++i)
115 auto inputValue = jmap (FloatType (i), FloatType (0), FloatType (numTestPoints - 1), minInputValue, maxInputValue);
116 auto approximatedOutputValue = transform.
processSample (inputValue);
117 auto referenceOutputValue = functionToApproximate (inputValue);
119 maxError = jmax (maxError, calculateRelativeDifference ((
double) referenceOutputValue, (
double) approximatedOutputValue));
126template <
typename FloatType>
129 static const auto eps = std::numeric_limits<double>::min();
131 auto absX = std::abs (x);
132 auto absY = std::abs (y);
133 auto absDiff = std::abs (x - y);
138 return absDiff / absY;
143 return absDiff / std::min (absX, absY);
147template class LookupTable<float>;
148template class LookupTable<double>;
150template class LookupTableTransform<float>;
151template class LookupTableTransform<double>;
FloatType getUnchecked(FloatType index) const noexcept
void initialise(const std::function< FloatType(size_t)> &functionToApproximate, size_t numPointsToUse)