52 template <
typename FloatType>
71 LookupTable (
const std::function<FloatType(
size_t)>& functionToApproximate,
size_t numPointsToUse);
83 void initialise (
const std::function<FloatType(
size_t)>& functionToApproximate,
size_t numPointsToUse);
99 jassert (isPositiveAndBelow (index, FloatType (
getNumPoints())));
101 auto i = truncatePositiveToUnsignedInt (index);
102 auto f = index - FloatType (i);
103 jassert (isPositiveAndBelow (f, FloatType (1)));
108 return jmap (f, x0, x1);
124 FloatType
get (FloatType index)
const noexcept
127 index = static_cast<FloatType> (getGuardIndex());
148 void prepare() noexcept;
149 static size_t getRequiredBufferSize (
size_t numPointsToUse) noexcept {
return numPointsToUse + 1; }
150 size_t getGuardIndex()
const noexcept {
return getRequiredBufferSize (
getNumPoints()) - 1; }
152 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (
LookupTable)
174 template <
typename FloatType>
200 FloatType minInputValueToUse,
201 FloatType maxInputValueToUse,
204 initialise (functionToApproximate, minInputValueToUse, maxInputValueToUse, numPoints);
218 void initialise (
const std::function<FloatType(FloatType)>& functionToApproximate,
219 FloatType minInputValueToUse,
220 FloatType maxInputValueToUse,
236 jassert (value >= minInputValue && value <= maxInputValue);
237 return lookupTable[scaler * value + offset];
256 auto index = scaler * jlimit (minInputValue, maxInputValue, value) + offset;
257 jassert (isPositiveAndBelow (index, FloatType (lookupTable.getNumPoints())));
259 return lookupTable[index];
264 FloatType
operator[] (FloatType index)
const noexcept {
return processSampleUnchecked (index); }
267 FloatType operator() (FloatType index)
const noexcept {
return processSample (index); }
273 void processUnchecked (
const FloatType* input, FloatType* output,
size_t numSamples)
const noexcept
275 for (
size_t i = 0; i < numSamples; ++i)
276 output[i] = processSampleUnchecked (input[i]);
283 void process (
const FloatType* input, FloatType* output,
size_t numSamples)
const noexcept
285 for (
size_t i = 0; i < numSamples; ++i)
286 output[i] = processSample (input[i]);
312 static double calculateMaxRelativeError (
const std::function<FloatType(FloatType)>& functionToApproximate,
313 FloatType minInputValue,
314 FloatType maxInputValue,
316 size_t numTestPoints = 0);
319 static double calculateRelativeDifference (
double,
double) noexcept;
324 FloatType minInputValue, maxInputValue;
325 FloatType scaler, offset;
void initialise(const std::function< FloatType(size_t)> &functionToApproximate, size_t numPointsToUse)
size_t getNumPoints() const noexcept
FloatType getUnchecked(FloatType index) const noexcept
ElementType getUnchecked(int index) const
FloatType operator[](FloatType index) const noexcept
bool isInitialised() const noexcept
int size() const noexcept