56 template <
typename FloatType>
75 LookupTable (
const std::function<FloatType(
size_t)>& functionToApproximate,
size_t numPointsToUse);
87 void initialise (
const std::function<FloatType(
size_t)>& functionToApproximate,
size_t numPointsToUse);
103 jassert (isPositiveAndBelow (index, FloatType (
getNumPoints())));
105 auto i = truncatePositiveToUnsignedInt (index);
106 auto f = index - FloatType (i);
107 jassert (isPositiveAndBelow (f, FloatType (1)));
112 return jmap (f, x0, x1);
128 FloatType
get (FloatType index)
const noexcept
131 index = static_cast<FloatType> (getGuardIndex());
152 void prepare() noexcept;
153 static size_t getRequiredBufferSize (
size_t numPointsToUse) noexcept {
return numPointsToUse + 1; }
154 size_t getGuardIndex()
const noexcept {
return getRequiredBufferSize (
getNumPoints()) - 1; }
156 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (
LookupTable)
178 template <
typename FloatType>
204 FloatType minInputValueToUse,
205 FloatType maxInputValueToUse,
208 initialise (functionToApproximate, minInputValueToUse, maxInputValueToUse, numPoints);
222 void initialise (
const std::function<FloatType(FloatType)>& functionToApproximate,
223 FloatType minInputValueToUse,
224 FloatType maxInputValueToUse,
240 jassert (value >= minInputValue && value <= maxInputValue);
241 return lookupTable[scaler * value + offset];
260 auto index = scaler * jlimit (minInputValue, maxInputValue, value) + offset;
261 jassert (isPositiveAndBelow (index, FloatType (lookupTable.getNumPoints())));
263 return lookupTable[index];
268 FloatType
operator[] (FloatType index)
const noexcept {
return processSampleUnchecked (index); }
271 FloatType operator() (FloatType index)
const noexcept {
return processSample (index); }
277 void processUnchecked (
const FloatType* input, FloatType* output,
size_t numSamples)
const noexcept
279 for (
size_t i = 0; i < numSamples; ++i)
280 output[i] = processSampleUnchecked (input[i]);
287 void process (
const FloatType* input, FloatType* output,
size_t numSamples)
const noexcept
289 for (
size_t i = 0; i < numSamples; ++i)
290 output[i] = processSample (input[i]);
316 static double calculateMaxRelativeError (
const std::function<FloatType(FloatType)>& functionToApproximate,
317 FloatType minInputValue,
318 FloatType maxInputValue,
320 size_t numTestPoints = 0);
323 static double calculateRelativeDifference (
double,
double) noexcept;
328 FloatType minInputValue, maxInputValue;
329 FloatType scaler, offset;
void initialise(const std::function< FloatType(size_t)> &functionToApproximate, size_t numPointsToUse)
Initialises or changes the parameters of a LookupTable object.
size_t getNumPoints() const noexcept
Returns the size of the LookupTable, i.e., the number of pre-calculated data points.
FloatType getUnchecked(FloatType index) const noexcept
Calculates the approximated value for the given index without range checking.
ElementType getUnchecked(int index) const
Returns one of the elements in the array, without checking the index passed in.
FloatType operator[](FloatType index) const noexcept
LookupTable()
Creates an uninitialised LookupTable object.
Class for efficiently approximating expensive arithmetic operations.
bool isInitialised() const noexcept
Returns true if the LookupTable is initialised and ready to be used.
int size() const noexcept
Returns the current number of elements in the array.