JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::dsp::LookupTable< FloatType > Class Template Reference

Class for efficiently approximating expensive arithmetic operations. More...

#include <juce_LookupTable.h>

Inheritance diagram for juce::dsp::LookupTable< FloatType >:
Collaboration diagram for juce::dsp::LookupTable< FloatType >:

Public Member Functions

 LookupTable ()
 Creates an uninitialised LookupTable object. More...
 
 LookupTable (const std::function< FloatType(size_t)> &functionToApproximate, size_t numPointsToUse)
 Creates and initialises a LookupTable object. More...
 
FloatType get (FloatType index) const noexcept
 Calculates the approximated value for the given index with range checking. More...
 
size_t getNumPoints () const noexcept
 Returns the size of the LookupTable, i.e., the number of pre-calculated data points. More...
 
FloatType getUnchecked (FloatType index) const noexcept
 Calculates the approximated value for the given index without range checking. More...
 
void initialise (const std::function< FloatType(size_t)> &functionToApproximate, size_t numPointsToUse)
 Initialises or changes the parameters of a LookupTable object. More...
 
bool isInitialised () const noexcept
 Returns true if the LookupTable is initialised and ready to be used. More...
 
FloatType operator[] (FloatType index) const noexcept
 

Private Member Functions

size_t getGuardIndex () const noexcept
 
void prepare () noexcept
 

Static Private Member Functions

static size_t getRequiredBufferSize (size_t numPointsToUse) noexcept
 

Private Attributes

Array< FloatType > data
 

Detailed Description

template<typename FloatType>
class juce::dsp::LookupTable< FloatType >

Class for efficiently approximating expensive arithmetic operations.

The approximation is based on linear interpolation between pre-calculated values. The approximated function should be passed as a callable object to the constructor along with the number of data points to be pre-calculated. The accuracy of the approximation can be increased by using more points at the cost of a larger memory footprint.

Consider using LookupTableTransform as an easy-to-use alternative.

Example:

LookupTable<float> lut ([] (size_t i) { return std::sqrt ((float) i); }, 64);
auto outValue = lut[17];
See also
LookupTableTransform

{DSP}

Constructor & Destructor Documentation

◆ LookupTable() [1/2]

template<typename FloatType>
juce::dsp::LookupTable< FloatType >::LookupTable ( )

Creates an uninitialised LookupTable object.

You need to call initialise() before using the object. Prefer using the non-default constructor instead.

See also
initialise

◆ LookupTable() [2/2]

template<typename FloatType>
juce::dsp::LookupTable< FloatType >::LookupTable ( const std::function< FloatType(size_t)> &  functionToApproximate,
size_t  numPointsToUse 
)

Creates and initialises a LookupTable object.

Parameters
functionToApproximateThe function to be approximated. This should be a mapping from the integer range [0, numPointsToUse - 1].
numPointsToUseThe number of pre-calculated values stored.

Member Function Documentation

◆ get()

template<typename FloatType>
FloatType juce::dsp::LookupTable< FloatType >::get ( FloatType  index) const
inlinenoexcept

Calculates the approximated value for the given index with range checking.

This can be called with any input indices. If the provided index is out-of-range either the bottom or the top element of the LookupTable is returned.

If the index is guaranteed to be in range use the faster getUnchecked() instead.

Parameters
indexThe approximation is calculated for this non-integer index.
Returns
The approximated value at the given index.
See also
getUnchecked, operator[]

◆ getGuardIndex()

template<typename FloatType>
size_t juce::dsp::LookupTable< FloatType >::getGuardIndex ( ) const
inlineprivatenoexcept

◆ getNumPoints()

template<typename FloatType>
size_t juce::dsp::LookupTable< FloatType >::getNumPoints ( ) const
inlinenoexcept

Returns the size of the LookupTable, i.e., the number of pre-calculated data points.

Referenced by juce::dsp::LookupTable< Type >::get(), juce::dsp::LookupTable< Type >::getGuardIndex(), and juce::dsp::LookupTable< Type >::getUnchecked().

◆ getRequiredBufferSize()

template<typename FloatType>
static size_t juce::dsp::LookupTable< FloatType >::getRequiredBufferSize ( size_t  numPointsToUse)
inlinestaticprivatenoexcept

◆ getUnchecked()

template<typename FloatType>
FloatType juce::dsp::LookupTable< FloatType >::getUnchecked ( FloatType  index) const
inlinenoexcept

Calculates the approximated value for the given index without range checking.

Use this if you can guarantee that the index is non-negative and less than numPoints. Otherwise use get().

Parameters
indexThe approximation is calculated for this non-integer index.
Returns
The approximated value at the given index.
See also
get, operator[]

Referenced by juce::dsp::LookupTable< Type >::get(), and juce::dsp::LookupTable< Type >::operator[]().

◆ initialise()

template<typename FloatType>
void juce::dsp::LookupTable< FloatType >::initialise ( const std::function< FloatType(size_t)> &  functionToApproximate,
size_t  numPointsToUse 
)

Initialises or changes the parameters of a LookupTable object.

This function can be used to change what function is approximated by an already constructed LookupTable along with the number of data points used. If the function to be approximated won't ever change, prefer using the non-default constructor.

Parameters
functionToApproximateThe function to be approximated. This should be a mapping from the integer range [0, numPointsToUse - 1].
numPointsToUseThe number of pre-calculated values stored.

Referenced by juce::dsp::LookupTableTransform< Type >::LookupTableTransform().

◆ isInitialised()

template<typename FloatType>
bool juce::dsp::LookupTable< FloatType >::isInitialised ( ) const
inlinenoexcept

Returns true if the LookupTable is initialised and ready to be used.

Referenced by juce::dsp::LookupTable< Type >::getUnchecked().

◆ operator[]()

template<typename FloatType>
FloatType juce::dsp::LookupTable< FloatType >::operator[] ( FloatType  index) const
inlinenoexcept
See also
getUnchecked

◆ prepare()

template<typename FloatType>
void juce::dsp::LookupTable< FloatType >::prepare ( )
privatenoexcept

Member Data Documentation

◆ data


The documentation for this class was generated from the following file: