Resampler resamples a stream from one integer sample rate to another (arbitrary) rate, using a kaiser-windowed sinc filter. More...

#include <Resampler.h>

Classes

struct  Phase
 

Public Member Functions

 Resampler (int sourceRate, int targetRate)
 Construct a Resampler to resample from sourceRate to targetRate. More...
 
 Resampler (int sourceRate, int targetRate, double snr, double bandwidth)
 Construct a Resampler to resample from sourceRate to targetRate, using the given filter parameters. More...
 
virtual ~Resampler ()
 
int process (const double *src, double *dst, int n)
 Read n input samples from src and write resampled data to dst. More...
 
std::vector< double > process (const double *src, int n)
 Read n input samples from src and return resampled data by value. More...
 
int getLatency () const
 Return the number of samples of latency at the output due by the filter. More...
 

Static Public Member Functions

static std::vector< double > resample (int sourceRate, int targetRate, const double *data, int n)
 Carry out a one-off resample of a single block of n samples. More...
 

Private Member Functions

void initialise (double, double)
 
double reconstructOne ()
 

Private Attributes

int m_sourceRate
 
int m_targetRate
 
int m_gcd
 
int m_filterLength
 
int m_latency
 
double m_peakToPole
 
Phasem_phaseData
 
int m_phase
 
std::vector< double > m_buffer
 
int m_bufferOrigin
 

Detailed Description

Resampler resamples a stream from one integer sample rate to another (arbitrary) rate, using a kaiser-windowed sinc filter.

The results and performance are pretty similar to libraries such as libsamplerate, though this implementation does not support time-varying ratios (the ratio is fixed on construction).

See also Decimator, which is faster and rougher but supports only power-of-two downsampling factors.

Definition at line 30 of file Resampler.h.

Constructor & Destructor Documentation

Resampler::Resampler ( int  sourceRate,
int  targetRate 
)

Construct a Resampler to resample from sourceRate to targetRate.

Definition at line 36 of file Resampler.cpp.

References initialise().

Resampler::Resampler ( int  sourceRate,
int  targetRate,
double  snr,
double  bandwidth 
)

Construct a Resampler to resample from sourceRate to targetRate, using the given filter parameters.

Definition at line 46 of file Resampler.cpp.

References initialise().

Resampler::~Resampler ( )
virtual

Definition at line 54 of file Resampler.cpp.

References m_phaseData.

Member Function Documentation

int Resampler::process ( const double *  src,
double *  dst,
int  n 
)

Read n input samples from src and write resampled data to dst.

The return value is the number of samples written, which will be no more than ceil((n * targetRate) / sourceRate). The caller must ensure the dst buffer has enough space for the samples returned.

Definition at line 303 of file Resampler.cpp.

References Resampler::Phase::filter, m_buffer, m_bufferOrigin, m_gcd, m_peakToPole, m_phase, m_phaseData, m_sourceRate, m_targetRate, and reconstructOne().

Referenced by process(), and resample().

vector< double > Resampler::process ( const double *  src,
int  n 
)

Read n input samples from src and return resampled data by value.

Definition at line 335 of file Resampler.cpp.

References m_sourceRate, m_targetRate, and process().

int Resampler::getLatency ( ) const
inline

Return the number of samples of latency at the output due by the filter.

(That is, the output will be delayed by this number of samples relative to the input.)

Definition at line 68 of file Resampler.h.

References m_latency, and resample().

Referenced by resample().

vector< double > Resampler::resample ( int  sourceRate,
int  targetRate,
const double *  data,
int  n 
)
static

Carry out a one-off resample of a single block of n samples.

The output is latency-compensated.

Definition at line 346 of file Resampler.cpp.

References getLatency(), and process().

Referenced by getLatency().

double Resampler::reconstructOne ( )
private

Member Data Documentation

int Resampler::m_sourceRate
private

Definition at line 78 of file Resampler.h.

Referenced by initialise(), and process().

int Resampler::m_targetRate
private

Definition at line 79 of file Resampler.h.

Referenced by initialise(), and process().

int Resampler::m_gcd
private

Definition at line 80 of file Resampler.h.

Referenced by initialise(), and process().

int Resampler::m_filterLength
private

Definition at line 81 of file Resampler.h.

Referenced by initialise().

int Resampler::m_latency
private

Definition at line 82 of file Resampler.h.

Referenced by getLatency(), and initialise().

double Resampler::m_peakToPole
private

Definition at line 83 of file Resampler.h.

Referenced by initialise(), and process().

Phase* Resampler::m_phaseData
private

Definition at line 91 of file Resampler.h.

Referenced by initialise(), process(), reconstructOne(), and ~Resampler().

int Resampler::m_phase
private

Definition at line 92 of file Resampler.h.

Referenced by initialise(), process(), and reconstructOne().

std::vector<double> Resampler::m_buffer
private

Definition at line 93 of file Resampler.h.

Referenced by initialise(), process(), and reconstructOne().

int Resampler::m_bufferOrigin
private

Definition at line 94 of file Resampler.h.

Referenced by initialise(), process(), and reconstructOne().


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