Xeno-rat
Loading...
Searching...
No Matches
NAudio.Dsp.WdlResampler Class Reference

Fully managed resampler, based on Cockos WDL Resampler. More...

Collaboration diagram for NAudio.Dsp.WdlResampler:

Classes

class  WDL_Resampler_IIRFilter
 

Public Member Functions

 WdlResampler ()
 Creates a new Resampler.
 
void SetMode (bool interp, int filtercnt, bool sinc, int sinc_size=64, int sinc_interpsize=32)
 Sets the mode for resampling with optional sinc interpolation and filter count.
 
void SetFilterParms (float filterpos=0.693f, float filterq=0.707f)
 Sets the filter parameters with default values for position and quality factor.
 
void SetFeedMode (bool wantInputDriven)
 Sets the feed mode for the system.
 
void Reset (double fracpos=0.0)
 Resets the history of the resampler by creating a new history array.
 
void SetRates (double rate_in, double rate_out)
 Sets the input and output rates, ensuring they are at least 1.0, and updates the internal ratio if the rates have changed.
 
double GetCurrentLatency ()
 Gets the current latency in seconds.
 
int ResamplePrepare (int out_samples, int nch, out WDL_ResampleSample[] inbuffer, out int inbufferOffset)
 Prepares the resampling process and returns the number of samples required for the resampled output.
 
int ResampleOut (WDL_ResampleSample[] outBuffer, int outBufferIndex, int nsamples_in, int nsamples_out, int nch)
 Resamples the input buffer to the output buffer based on the given parameters and returns the number of samples written to the output buffer.
 

Private Member Functions

void BuildLowPass (double filtpos)
 Builds a lowpass filter based on the given filter position.
 
void SincSample (WDL_ResampleSample[] outBuffer, int outBufferIndex, WDL_ResampleSample[] inBuffer, int inBufferIndex, double fracpos, int nch, WDL_SincFilterSample[] filter, int filterIndex, int filtsz)
 Performs sample rate conversion using sinc interpolation.
 
void SincSample1 (WDL_ResampleSample[] outBuffer, int outBufferIndex, WDL_ResampleSample[] inBuffer, int inBufferIndex, double fracpos, WDL_SincFilterSample[] filter, int filterIndex, int filtsz)
 Performs sinc resampling on the input buffer and writes the result to the output buffer at the specified indices.
 
void SincSample2 (WDL_ResampleSample[] outptr, int outBufferIndex, WDL_ResampleSample[] inBuffer, int inBufferIndex, double fracpos, WDL_SincFilterSample[] filter, int filterIndex, int filtsz)
 Performs a sinc resampling of the input buffer and stores the result in the output buffer.
 

Private Attributes

double m_sratein
 
double m_srateout
 
double m_fracpos
 
double m_ratio
 
double m_filter_ratio
 
float m_filterq
 
float m_filterpos
 
WDL_ResampleSample[] m_rsinbuf
 
WDL_SincFilterSample[] m_filter_coeffs
 
WDL_Resampler_IIRFilter m_iirfilter
 
int m_filter_coeffs_size
 
int m_last_requested
 
int m_filtlatency
 
int m_samples_in_rsinbuf
 
int m_lp_oversize
 
int m_sincsize
 
int m_filtercnt
 
int m_sincoversize
 
bool m_interp
 
bool m_feedmode
 

Static Private Attributes

const int WDL_RESAMPLE_MAX_FILTERS = 4
 
const int WDL_RESAMPLE_MAX_NCH = 64
 
const double PI = 3.1415926535897932384626433832795
 

Detailed Description

Fully managed resampler, based on Cockos WDL Resampler.

Constructor & Destructor Documentation

◆ WdlResampler()

NAudio.Dsp.WdlResampler.WdlResampler ( )
inline

Creates a new Resampler.

Here is the call graph for this function:

Member Function Documentation

◆ BuildLowPass()

void NAudio.Dsp.WdlResampler.BuildLowPass ( double filtpos)
inlineprivate

Builds a lowpass filter based on the given filter position.

Parameters
filtposThe position of the filter.

This method builds a lowpass filter based on the given filter position, filter size, and interpolation size. It modifies the original filter coefficients array in place. The algorithm uses Blackman-Harris window and sinc function to construct the filter coefficients.

Here is the caller graph for this function:

◆ GetCurrentLatency()

double NAudio.Dsp.WdlResampler.GetCurrentLatency ( )
inline

Gets the current latency in seconds.

Returns
The current latency in seconds.

◆ ResampleOut()

int NAudio.Dsp.WdlResampler.ResampleOut ( WDL_ResampleSample[] outBuffer,
int outBufferIndex,
int nsamples_in,
int nsamples_out,
int nch )
inline

Resamples the input buffer to the output buffer based on the given parameters and returns the number of samples written to the output buffer.

Parameters
outBufferThe output buffer to write the resampled samples to.
outBufferIndexThe index in the output buffer to start writing the resampled samples.
nsamples_inThe number of input samples to be resampled.
nsamples_outThe number of output samples to be generated.
nchThe number of channels in the input and output buffers.
Returns
The number of samples written to the output buffer.

This method resamples the input buffer to the output buffer based on the given parameters. It handles filtering, interpolation, and padding as necessary to ensure accurate resampling. The resampling process modifies the output buffer in place.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResamplePrepare()

int NAudio.Dsp.WdlResampler.ResamplePrepare ( int out_samples,
int nch,
out WDL_ResampleSample[] inbuffer,
out int inbufferOffset )
inline

Prepares the resampling process and returns the number of samples required for the resampled output.

Parameters
out_samplesThe number of output samples.
nchThe number of channels.
inbufferThe input buffer for resampling.
inbufferOffsetThe offset for the input buffer.
Returns
The number of samples required for the resampled output.

This method prepares the resampling process by resizing the input buffer and calculating the number of samples required for the resampled output. It also handles the filter latency and adjusts the size of the input buffer accordingly.

Here is the caller graph for this function:

◆ Reset()

void NAudio.Dsp.WdlResampler.Reset ( double fracpos = 0::0)
inline

Resets the history of the resampler by creating a new history array.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetFeedMode()

void NAudio.Dsp.WdlResampler.SetFeedMode ( bool wantInputDriven)
inline

Sets the feed mode for the system.

Parameters
wantInputDrivenA boolean value indicating whether the system should be in input-driven feed mode.

This method sets the feed mode for the system. If wantInputDriven is true, the system will operate in input-driven feed mode; otherwise, it will operate in a different mode.

Here is the caller graph for this function:

◆ SetFilterParms()

void NAudio.Dsp.WdlResampler.SetFilterParms ( float filterpos = 0::693f,
float filterq = 0::707f )
inline

Sets the filter parameters with default values for position and quality factor.

Parameters
filterposThe position parameter for the filter. Default value is 0.693.
filterqThe quality factor parameter for the filter. Default value is 0.707.
Here is the caller graph for this function:

◆ SetMode()

void NAudio.Dsp.WdlResampler.SetMode ( bool interp,
int filtercnt,
bool sinc,
int sinc_size = 64,
int sinc_interpsize = 32 )
inline

Sets the mode for resampling with optional sinc interpolation and filter count.

Parameters
interpSpecifies whether to use interpolation.
filtercntThe number of filters to be used.
sincSpecifies whether to use sinc interpolation.
sinc_sizeThe size of the sinc interpolation. Default is 64.
sinc_interpsizeThe interpolation size for sinc. Default is 32.

This method sets the mode for resampling with optional sinc interpolation and filter count. It modifies the internal state of the resampler based on the provided parameters.

Here is the caller graph for this function:

◆ SetRates()

void NAudio.Dsp.WdlResampler.SetRates ( double rate_in,
double rate_out )
inline

Sets the input and output rates, ensuring they are at least 1.0, and updates the internal ratio if the rates have changed.

Parameters
rate_inThe input rate to be set.
rate_outThe output rate to be set.

If the input rate rate_in is less than 1.0, it is set to 1.0. If the output rate rate_out is less than 1.0, it is set to 1.0. If either rate_in or rate_out is different from the current input or output rates, the internal rates are updated and the ratio is recalculated as the input rate divided by the output rate.

Here is the caller graph for this function:

◆ SincSample()

void NAudio.Dsp.WdlResampler.SincSample ( WDL_ResampleSample[] outBuffer,
int outBufferIndex,
WDL_ResampleSample[] inBuffer,
int inBufferIndex,
double fracpos,
int nch,
WDL_SincFilterSample[] filter,
int filterIndex,
int filtsz )
inlineprivate

Performs sample rate conversion using sinc interpolation.

Parameters
outBufferThe output buffer to store the resampled samples.
outBufferIndexThe index in the output buffer to start writing the resampled samples.
inBufferThe input buffer containing the original samples.
inBufferIndexThe index in the input buffer to start reading the original samples.
fracposThe fractional position within the input buffer for interpolation.
nchThe number of channels in the audio data.
filterThe sinc filter coefficients for interpolation.
filterIndexThe index in the filter array to start applying the filter.
filtszThe size of the filter.

This method performs sample rate conversion using sinc interpolation. It applies a sinc filter to the input samples to generate the resampled output. The fractional position within the input buffer is used for interpolation, and the number of channels and filter size are taken into account during the process. The resampled samples are written to the output buffer starting from the specified index.

Here is the caller graph for this function:

◆ SincSample1()

void NAudio.Dsp.WdlResampler.SincSample1 ( WDL_ResampleSample[] outBuffer,
int outBufferIndex,
WDL_ResampleSample[] inBuffer,
int inBufferIndex,
double fracpos,
WDL_SincFilterSample[] filter,
int filterIndex,
int filtsz )
inlineprivate

Performs sinc resampling on the input buffer and writes the result to the output buffer at the specified indices.

Parameters
outBufferThe output buffer where the resampled data will be written.
outBufferIndexThe index in the output buffer where the resampled data will be written.
inBufferThe input buffer containing the original data to be resampled.
inBufferIndexThe index in the input buffer from where the original data will be read for resampling.
fracposThe fractional position within the input buffer for resampling.
filterThe sinc filter used for resampling.
filterIndexThe index in the sinc filter array.
filtszThe size of the sinc filter.

This method performs sinc resampling on the input buffer using the provided sinc filter and fractional position. It calculates the resampled value using the filter coefficients and writes the result to the output buffer at the specified index.

Here is the caller graph for this function:

◆ SincSample2()

void NAudio.Dsp.WdlResampler.SincSample2 ( WDL_ResampleSample[] outptr,
int outBufferIndex,
WDL_ResampleSample[] inBuffer,
int inBufferIndex,
double fracpos,
WDL_SincFilterSample[] filter,
int filterIndex,
int filtsz )
inlineprivate

Performs a sinc resampling of the input buffer and stores the result in the output buffer.

Parameters
outptrThe output buffer where the resampled data will be stored.
outBufferIndexThe index in the output buffer where the resampled data will start.
inBufferThe input buffer containing the original data to be resampled.
inBufferIndexThe index in the input buffer from where the original data will be read for resampling.
fracposThe fractional position within the input buffer for resampling.
filterThe sinc filter used for resampling.
filterIndexThe index in the filter array from where filtering will start.
filtszThe size of the filter array.

This method performs a sinc resampling of the input buffer using the provided sinc filter. It calculates the resampled values based on the fractional position within the input buffer and stores the result in the output buffer starting from the specified index. The resampling process involves applying the sinc filter to the input buffer data to obtain the resampled values. The filter is applied based on the fractional position, and the resulting values are stored in the output buffer.

Here is the caller graph for this function:

Member Data Documentation

◆ m_feedmode

bool NAudio.Dsp.WdlResampler.m_feedmode
private

◆ m_filter_coeffs

WDL_SincFilterSample [] NAudio.Dsp.WdlResampler.m_filter_coeffs
private

◆ m_filter_coeffs_size

int NAudio.Dsp.WdlResampler.m_filter_coeffs_size
private

◆ m_filter_ratio

double NAudio.Dsp.WdlResampler.m_filter_ratio
private

◆ m_filtercnt

int NAudio.Dsp.WdlResampler.m_filtercnt
private

◆ m_filterpos

float NAudio.Dsp.WdlResampler.m_filterpos
private

◆ m_filterq

float NAudio.Dsp.WdlResampler.m_filterq
private

◆ m_filtlatency

int NAudio.Dsp.WdlResampler.m_filtlatency
private

◆ m_fracpos

double NAudio.Dsp.WdlResampler.m_fracpos
private

◆ m_iirfilter

WDL_Resampler_IIRFilter NAudio.Dsp.WdlResampler.m_iirfilter
private

◆ m_interp

bool NAudio.Dsp.WdlResampler.m_interp
private

◆ m_last_requested

int NAudio.Dsp.WdlResampler.m_last_requested
private

◆ m_lp_oversize

int NAudio.Dsp.WdlResampler.m_lp_oversize
private

◆ m_ratio

double NAudio.Dsp.WdlResampler.m_ratio
private

◆ m_rsinbuf

WDL_ResampleSample [] NAudio.Dsp.WdlResampler.m_rsinbuf
private

◆ m_samples_in_rsinbuf

int NAudio.Dsp.WdlResampler.m_samples_in_rsinbuf
private

◆ m_sincoversize

int NAudio.Dsp.WdlResampler.m_sincoversize
private

◆ m_sincsize

int NAudio.Dsp.WdlResampler.m_sincsize
private

◆ m_sratein

double NAudio.Dsp.WdlResampler.m_sratein
private

◆ m_srateout

double NAudio.Dsp.WdlResampler.m_srateout
private

◆ PI

const double NAudio.Dsp.WdlResampler.PI = 3.1415926535897932384626433832795
staticprivate

◆ WDL_RESAMPLE_MAX_FILTERS

const int NAudio.Dsp.WdlResampler.WDL_RESAMPLE_MAX_FILTERS = 4
staticprivate

◆ WDL_RESAMPLE_MAX_NCH

const int NAudio.Dsp.WdlResampler.WDL_RESAMPLE_MAX_NCH = 64
staticprivate

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