56template <
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)
178template <
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];
277 void processUnchecked (
const FloatType* input, FloatType* output,
size_t numSamples)
const noexcept
279 for (
size_t i = 0; i < numSamples; ++i)
287 void process (
const FloatType* input, FloatType* output,
size_t numSamples)
const noexcept
289 for (
size_t i = 0; i < numSamples; ++i)
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;
ElementType getUnchecked(int index) const
Returns one of the elements in the array, without checking the index passed in.
int size() const noexcept
Returns the current number of elements in the array.
Class for efficiently approximating expensive arithmetic operations.
FloatType get(FloatType index) const noexcept
Calculates the approximated value for the given index with range checking.
FloatType operator[](FloatType index) const noexcept
FloatType getUnchecked(FloatType index) const noexcept
Calculates the approximated value for the given index without range checking.
bool isInitialised() const noexcept
Returns true if the LookupTable is initialised and ready to be used.
size_t getNumPoints() const noexcept
Returns the size of the LookupTable, i.e., the number of pre-calculated data points.
void initialise(const std::function< FloatType(size_t)> &functionToApproximate, size_t numPointsToUse)
Initialises or changes the parameters of a LookupTable object.
LookupTable()
Creates an uninitialised LookupTable object.