r8brain-free-src
High-quality pro audio sample rate converter library
 
Loading...
Searching...
No Matches
r8b::CDSPFracInterpolator Class Reference

Fractional delay filter bank-based interpolator class. More...

#include <CDSPFracInterpolator.h>

Inheritance diagram for r8b::CDSPFracInterpolator:
r8b::CDSPProcessor

Public Member Functions

 CDSPFracInterpolator (const double aSrcSampleRate, const double aDstSampleRate, const double ReqAtten, const bool IsThird, const double PrevLatency)
 Initalizes the interpolator. It is important to call the getMaxOutLen() function afterwards to obtain the optimal output buffer length.
 
virtual void clear ()
 Clears (resets) the state of this object and returns it to the state after construction.
 
virtual int getInLenBeforeOutPos (const int ReqOutPos) const
 Returns the number of input samples required to advance to the specified output sample position (so that the next process() call passes this output position).
 
virtual int getLatency () const
 Return the latency, in samples, which is present in the output signal.
 
virtual double getLatencyFrac () const
 Returns fractional latency, in samples, which is present in the output signal.
 
virtual int getMaxOutLen (const int MaxInLen) const
 Returns the maximal length of the output buffer required when processing the MaxInLen number of input samples.
 
virtual int process (double *ip, int l, double *&op0)
 Performs DSP processing.
 

Detailed Description

Fractional delay filter bank-based interpolator class.

Class implements the fractional delay interpolator. This implementation at first puts the input signal into a ring buffer and then performs interpolation. The interpolation is performed using sinc-based fractional delay filters. These filters are contained in a bank, and for higher precision they are interpolated between adjacent filters.

To increase the sample-timing precision, this class uses "resettable counter" approach. This gives zero overall sample-timing error. With the R8B_FASTTIMING configuration option enabled, the sample timing experiences a very minor drift.

Constructor & Destructor Documentation

◆ CDSPFracInterpolator()

r8b::CDSPFracInterpolator::CDSPFracInterpolator ( const double aSrcSampleRate,
const double aDstSampleRate,
const double ReqAtten,
const bool IsThird,
const double PrevLatency )

Initalizes the interpolator. It is important to call the getMaxOutLen() function afterwards to obtain the optimal output buffer length.

Parameters
aSrcSampleRateSource sample rate.
aDstSampleRateDestination sample rate.
ReqAttenRequired filter attentuation.
IsThirdtrue if one-third filter is required.
PrevLatencyLatency, in samples (any non-negative value), which was left in the output signal by a previous process. This latency will be consumed completely.

Member Function Documentation

◆ clear()

virtual void r8b::CDSPFracInterpolator::clear ( )
virtual

Clears (resets) the state of this object and returns it to the state after construction.

All input data accumulated in the internal buffer so far will be discarded.

Implements r8b::CDSPProcessor.

◆ getInLenBeforeOutPos()

virtual int r8b::CDSPFracInterpolator::getInLenBeforeOutPos ( const int ReqOutPos) const
virtual

Returns the number of input samples required to advance to the specified output sample position (so that the next process() call passes this output position).

Assumes starting at the cleared or after-construction state of this object.

Note that the implementation of this function assumes the caller only needs to estimate an initial buffering requirement; passing a full sample length value (e.g., greater than 100000) may overflow the calculation or cause rounding errors.

Parameters
ReqOutPosThe required output position. Set to 0 to obtain "input length before output start" latency. Must be a non-negative value.
Returns
The number of input samples required.

Implements r8b::CDSPProcessor.

◆ getLatency()

virtual int r8b::CDSPFracInterpolator::getLatency ( ) const
virtual

Return the latency, in samples, which is present in the output signal.

This value is usually zero if the DSP processor "consumes" the latency automatically.

Implements r8b::CDSPProcessor.

◆ getLatencyFrac()

virtual double r8b::CDSPFracInterpolator::getLatencyFrac ( ) const
virtual

Returns fractional latency, in samples, which is present in the output signal.

This value is usually zero if a linear-phase filtering is used. With minimum-phase filters in use, this value can be non-zero even if the getLatency() function returns zero.

Implements r8b::CDSPProcessor.

◆ getMaxOutLen()

virtual int r8b::CDSPFracInterpolator::getMaxOutLen ( const int MaxInLen) const
virtual

Returns the maximal length of the output buffer required when processing the MaxInLen number of input samples.

Parameters
MaxInLenThe number of samples planned to process at once, at most.

Implements r8b::CDSPProcessor.

◆ process()

virtual int r8b::CDSPFracInterpolator::process ( double * ip,
int l0,
double *& op0 )
virtual

Performs DSP processing.

Parameters
ipInput data pointer.
l0How many samples to process.
[out]op0Output data pointer. The capacity of this buffer should be equal to the value returned by the getMaxOutLen() function for the given l0. This buffer can be equal to ip only if the getMaxOutLen( l0 ) call returned a value lesser than l0. This pointer can be incremented on function's return if latency compensation was performed by the processor. Note that on function's return, this pointer may point to some internal buffers, including the ip buffer, ignoring the originally passed value.
Returns
The number of output samples written to the op0 buffer and available after processing. This value can be smaller or larger in comparison to the original l0 value due to processing and filter's latency compensation that took place, and due to resampling if it was performed.

Implements r8b::CDSPProcessor.