DSPark 1.8.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::SincInterpolator< T > Class Template Reference

32-tap Kaiser-windowed sinc reader for transparent fractional reads. More...

#include <Interpolation.h>

Public Member Functions

 SincInterpolator ()
 Builds the kernel table (allocates: construct on a setup thread).
 
T read (const T *x, double frac) const noexcept
 Interpolates kTaps consecutive samples at x[kBefore] + frac.
 
T readRing (const T *ring, int64_t mask, int64_t intPos, double frac) const noexcept
 Reads a power-of-two ring buffer at intPos + frac.
 

Static Public Attributes

static constexpr int kTaps = 32
 Kernel length.
 
static constexpr int kBefore = kTaps / 2 - 1
 Samples needed before intPos.
 
static constexpr int kAfter = kTaps / 2
 Samples needed after intPos.
 
static constexpr int kPhases = 256
 Tabulated fractional phases.
 

Detailed Description

template<FloatType T>
class dspark::SincInterpolator< T >

32-tap Kaiser-windowed sinc reader for transparent fractional reads.

The reader for resampling a stream at a fixed or varying rate. Its worst-case error against the ideal fractional delay, over every fractional position, stays below -96 dB up to 15 kHz at 44.1 and 48 kHz (and 18 kHz at 48 kHz). A 4-point cubic (Hermite / Catmull-Rom) reader reaches -24 dB at 10 kHz and -12 dB at 15 kHz, and because its error changes with the fractional position, a moving read point turns it into modulation noise.

The kernel is a full-band sinc (cutoff at Nyquist) under a Kaiser window (beta 10), tabulated at 256 fractional phases, each normalized to unit DC gain, and linearly interpolated between phases. Integer positions are an exact identity. Near Nyquist the 32 taps cannot hold the band: at 20 kHz the error is -50 dB at 48 kHz and -17 dB at 44.1 kHz.

Reading position intPos + frac needs the samples intPos - 15 through intPos + 16.

Template Parameters
TSample type (float or double).

Definition at line 322 of file Interpolation.h.

Constructor & Destructor Documentation

◆ SincInterpolator()

template<FloatType T>
dspark::SincInterpolator< T >::SincInterpolator ( )
inline

Builds the kernel table (allocates: construct on a setup thread).

Definition at line 331 of file Interpolation.h.

Member Function Documentation

◆ read()

template<FloatType T>
T dspark::SincInterpolator< T >::read ( const T *  x,
double  frac 
) const
inlinenoexcept

Interpolates kTaps consecutive samples at x[kBefore] + frac.

Parameters
xSamples intPos - kBefore through intPos + kAfter.
fracFractional position in [0, 1).
Returns
Interpolated value.

Definition at line 374 of file Interpolation.h.

◆ readRing()

template<FloatType T>
T dspark::SincInterpolator< T >::readRing ( const T *  ring,
int64_t  mask,
int64_t  intPos,
double  frac 
) const
inlinenoexcept

Reads a power-of-two ring buffer at intPos + frac.

Parameters
ringRing storage.
maskRing size minus one (the size must be a power of two).
intPosInteger read position (masked, so any value works).
fracFractional position in [0, 1).
Returns
Interpolated value.

Definition at line 394 of file Interpolation.h.

Member Data Documentation

◆ kAfter

template<FloatType T>
constexpr int dspark::SincInterpolator< T >::kAfter = kTaps / 2
staticconstexpr

Samples needed after intPos.

Definition at line 327 of file Interpolation.h.

◆ kBefore

template<FloatType T>
constexpr int dspark::SincInterpolator< T >::kBefore = kTaps / 2 - 1
staticconstexpr

Samples needed before intPos.

Definition at line 326 of file Interpolation.h.

◆ kPhases

template<FloatType T>
constexpr int dspark::SincInterpolator< T >::kPhases = 256
staticconstexpr

Tabulated fractional phases.

Definition at line 328 of file Interpolation.h.

◆ kTaps

template<FloatType T>
constexpr int dspark::SincInterpolator< T >::kTaps = 32
staticconstexpr

Kernel length.

Definition at line 325 of file Interpolation.h.


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