arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BaseInterpolator Struct Referenceabstract

Base class for resampling algorithms using a buffer of float values. More...

#include <ResampleStreamT.h>

Inheritance diagram for BaseInterpolator:
BSplineInterpolator HermiteInterpolator LagrangeInterpolator LinearInterpolator ParabolicInterpolator

Public Member Functions

void addValue (float value)
 Adds a new value to the buffer, discarding the oldest.
 
bool begin ()
 Constructor. Initializes the buffer with four zeros.
 
bool getValue (float &newValue)
 Gets the next interpolated value.
 
 operator bool () const
 Returns true if there are more values to read.
 
void setStepSize (float step)
 Sets the step size for interpolation.
 
float valueExt (float *y, float xf)
 

Protected Member Functions

virtual float value (float *y, float xf)=0
 Interpolation function to be implemented by derived classes.
 
virtual int vectorSize ()=0
 

Protected Attributes

float step = 0
 
float step_size = 1.0f
 Step size for resampling, default is 1.0.
 
SingleBuffer< float > values
 Buffer holding the last 4 values for interpolation.
 

Detailed Description

Base class for resampling algorithms using a buffer of float values.

Call getValue() to get the next interpolated value until it returns false. Then provide a new value with addValue() to continue.

Derived classes must implement the value() and vectorSize() methods for interpolation. The calculation depends on n values. For example, a linear interpolation only needs the last two values, while a cubic B-spline interpolation requires the last four values. The buffer is always filled with the required number of values, so the derived class can assume that it has access to all required values for interpolation.

The buffer is initilaized with 0 values and it is re-initialized when setStepSize() is called with a different size.

Member Function Documentation

◆ addValue()

void addValue ( float  value)
inline

Adds a new value to the buffer, discarding the oldest.

Parameters
valueThe new sample value to add.

◆ getValue()

bool getValue ( float &  newValue)
inline

Gets the next interpolated value.

Parameters
newValueReference to store the interpolated value.
Returns
True if a value was produced, false if more input is needed.

◆ setStepSize()

void setStepSize ( float  step)
inline

Sets the step size for interpolation.

Parameters
stepThe new step size.

◆ value()

virtual float value ( float *  y,
float  xf 
)
protectedpure virtual

Interpolation function to be implemented by derived classes.

Parameters
yPointer to the buffer of 4 values.
xfThe fractional index for interpolation.
Returns
Interpolated value.

Implemented in LinearInterpolator, BSplineInterpolator, LagrangeInterpolator, HermiteInterpolator, and ParabolicInterpolator.

◆ vectorSize()

virtual int vectorSize ( )
protectedpure virtual

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