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

Sinc function-based FIR filter generator class. More...

#include <CDSPSincFilterGen.h>

Public Types

typedef double(CDSPSincFilterGen ::* CWindowFunc) ()
 Window calculation function pointer type.
 
enum  EWindowFunctionType { wftCosine , wftKaiser , wftGaussian }
 Window function type. More...
 

Public Member Functions

double calcWindowBlackman ()
 Returns the next "Blackman" window function coefficient.
 
double calcWindowBlackmanNuttall ()
 Returns the next "Blackman-Nuttall" window function coefficient.
 
double calcWindowGaussian ()
 Returns the next "Gaussian" window function coefficient.
 
double calcWindowHamming ()
 Returns the next "Hamming" window function coefficient.
 
double calcWindowHann ()
 Returns the next "Hann" window function coefficient.
 
double calcWindowKaiser ()
 Returns the next "Kaiser" window function coefficient.
 
double calcWindowNuttall ()
 Returns the next "Nuttall" window function coefficient.
 
void generateBand (double *op, CWindowFunc wfunc=&CDSPSincFilterGen ::calcWindowBlackman)
 Calculates band-limited windowed sinc function-based filter kernel.
 
void generateFrac (double *op, CWindowFunc wfunc=&CDSPSincFilterGen ::calcWindowBlackman, const int opinc=1)
 Calculates windowed fractional delay filter kernel.
 
void generateHilbert (double *op, CWindowFunc wfunc=&CDSPSincFilterGen ::calcWindowBlackman)
 Calculates windowed Hilbert transformer filter kernel.
 
void generateWindow (double *op, CWindowFunc wfunc=&CDSPSincFilterGen ::calcWindowBlackman)
 Calculates the window function only.
 
void initBand (const EWindowFunctionType WinType=wftCosine, const double *const Params=R8B_NULL, const bool UsePower=false)
 Initializes this structure for generation of band-limited sinc filter kernel.
 
void initFrac (const EWindowFunctionType WinType=wftCosine, const double *const Params=R8B_NULL, const bool UsePower=false)
 Initializes this structure for generation of full-bandwidth fractional delay sinc filter kernel.
 
void initHilbert (const EWindowFunctionType WinType=wftCosine, const double *const Params=R8B_NULL, const bool UsePower=false)
 Initializes this structure for Hilbert transformation filter calculation.
 
void initWindow (const EWindowFunctionType WinType=wftCosine, const double *const Params=R8B_NULL, const bool UsePower=false)
 Initializes this structure for generation of a window function, odd-sized.
 

Public Attributes

int fl2
 Internal "half kernel length" value. This value can be used as filter's latency in samples (taps), this variable is set after the call to one of the "init" functions.
 
double FracDelay
 Fractional delay in the range [0; 1], used only in the generateFrac() function. Note that the FracDelay parameter is actually inversed. At 0.0 value it produces 1 sample delay (with the latency equal to fl2), at 1.0 value it produces 0 sample delay (with the latency equal to fl2 - 1).
 
double Freq1
 Required corner circular frequency 1 [0; pi]. Used only in the generateBand() function.
 
double Freq2
 Required corner circular frequency 2 [0; pi]. Used only in the generateBand() function. The range [Freq1; Freq2] defines a pass band for the generateBand() function.
 
int KernelLen
 Resulting length of the filter kernel, this variable is set after the call to one of the "init" functions.
 
double Len2
 Required half filter kernel's length in samples (can be a fractional value). Final physical kernel length will be provided in the KernelLen variable. Len2 should be >= 2.
 
double Len2i
 Equals 1.0 / Len2, initialized and used by some window functions for optimization (should not be initialized by the caller).
 

Detailed Description

Sinc function-based FIR filter generator class.

Structure that holds state used to perform generation of sinc functions of various types, windowed by the Blackman window by default (but the window function can be changed if necessary).

Member Enumeration Documentation

◆ EWindowFunctionType

Window function type.

Enumerator
wftCosine 

Generalized cosine window function. No parameters required. The "Power" parameter is optional.

wftKaiser 

Kaiser window function. Requires the "Beta" parameter. The "Power" parameter is optional.

wftGaussian 

Gaussian window function. Requires the "Sigma" parameter. The "Power" parameter is optional.

Member Function Documentation

◆ generateBand()

void r8b::CDSPSincFilterGen::generateBand ( double * op,
CWindowFunc wfunc = &CDSPSincFilterGen :: calcWindowBlackman )

Calculates band-limited windowed sinc function-based filter kernel.

Parameters
[out]opOutput buffer, length = KernelLen.
wfuncWindow calculation function to use.

◆ generateFrac()

void r8b::CDSPSincFilterGen::generateFrac ( double * op,
CWindowFunc wfunc = &CDSPSincFilterGen :: calcWindowBlackman,
const int opinc = 1 )

Calculates windowed fractional delay filter kernel.

Parameters
[out]opOutput buffer, length = KernelLen.
wfuncWindow calculation function to use.
opincOutput buffer increment, in "op" elements.

◆ generateHilbert()

void r8b::CDSPSincFilterGen::generateHilbert ( double * op,
CWindowFunc wfunc = &CDSPSincFilterGen :: calcWindowBlackman )

Calculates windowed Hilbert transformer filter kernel.

Parameters
[out]opOutput buffer, length = KernelLen.
wfuncWindow calculation function to use.

◆ generateWindow()

void r8b::CDSPSincFilterGen::generateWindow ( double * op,
CWindowFunc wfunc = &CDSPSincFilterGen :: calcWindowBlackman )

Calculates the window function only.

Parameters
[out]opOutput buffer, length = KernelLen.
wfuncWindow calculation function to use.

◆ initBand()

void r8b::CDSPSincFilterGen::initBand ( const EWindowFunctionType WinType = wftCosine,
const double *const Params = R8B_NULL,
const bool UsePower = false )

Initializes this structure for generation of band-limited sinc filter kernel.

The generateBand() function should be used to calculate the filter.

Parameters
WinTypeWindow function type.
ParamsWindow function's parameters. If nullptr, the table values may be used.
UsePowertrue if the power factor should be used to raise the window function. If true, the power factor should be specified as the last value in the Params array. If Params is nullptr, the table or default value of -1.0 (off) will be used.

◆ initFrac()

void r8b::CDSPSincFilterGen::initFrac ( const EWindowFunctionType WinType = wftCosine,
const double *const Params = R8B_NULL,
const bool UsePower = false )

Initializes this structure for generation of full-bandwidth fractional delay sinc filter kernel.

Freq1 and Freq2 variables are not used. The generateFrac() function should be used to calculate the filter.

Parameters
WinTypeWindow function type.
ParamsWindow function's parameters. If nullptr, the table values may be used.
UsePowertrue if the power factor should be used to raise the window function. If true, the power factor should be specified as the last value in the Params array. If Params is nullptr, the table or default value of -1.0 (off) will be used.

◆ initHilbert()

void r8b::CDSPSincFilterGen::initHilbert ( const EWindowFunctionType WinType = wftCosine,
const double *const Params = R8B_NULL,
const bool UsePower = false )

Initializes this structure for Hilbert transformation filter calculation.

Freq1 and Freq2 variables are not used. The generateHilbert() function should be used to calculate the filter.

Parameters
WinTypeWindow function type.
ParamsWindow function's parameters. If nullptr, the table values may be used.
UsePowertrue if the power factor should be used to raise the window function. If true, the power factor should be specified as the last value in the Params array. If Params is nullptr, the table or default value of -1.0 (off) will be used.

◆ initWindow()

void r8b::CDSPSincFilterGen::initWindow ( const EWindowFunctionType WinType = wftCosine,
const double *const Params = R8B_NULL,
const bool UsePower = false )

Initializes this structure for generation of a window function, odd-sized.

Parameters
WinTypeWindow function type.
ParamsWindow function's parameters. If nullptr, the table values may be used.
UsePowertrue if the power factor should be used to raise the window function. If true, the power factor should be specified as the last value in the Params array. If Params is nullptr, the table or default value of -1.0 (off) will be used.