qm-dsp 1.8
|
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. | |
Resampler (int sourceRate, int targetRate, double snr, double bandwidth) | |
Construct a Resampler to resample from sourceRate to targetRate, using the given filter parameters. | |
virtual | ~Resampler () |
int | process (const double *src, double *dst, int n) |
Read n input samples from src and write resampled data to dst. | |
std::vector< double > | process (const double *src, int n) |
Read n input samples from src and return resampled data by value. | |
int | getLatency () const |
Return the number of samples of latency at the output due by the filter. | |
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. | |
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_bufferLength |
int | m_latency |
double | m_peakToPole |
Phase * | m_phaseData |
int | m_phase |
std::vector< double > | m_buffer |
int | m_bufferOrigin |
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.
Resampler::Resampler | ( | int | sourceRate, |
int | targetRate | ||
) |
Construct a Resampler to resample from sourceRate to targetRate.
Definition at line 35 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 42 of file Resampler.cpp.
References initialise().
|
virtual |
Definition at line 50 of file Resampler.cpp.
References m_phaseData.
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 312 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 340 of file Resampler.cpp.
References m_sourceRate, m_targetRate, and process().
|
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.
Referenced by resample().
|
static |
Carry out a one-off resample of a single block of n samples.
The output is latency-compensated.
Definition at line 351 of file Resampler.cpp.
References getLatency(), and process().
|
private |
Definition at line 63 of file Resampler.cpp.
References KaiserWindow::Parameters::beta, KaiserWindow::cut(), SincWindow::cut(), Resampler::Phase::drop, Resampler::Phase::filter, MathUtilities::gcd(), knownFilterMutex, knownFilters, KaiserWindow::Parameters::length, m_buffer, m_bufferOrigin, m_filterLength, m_gcd, m_latency, m_peakToPole, m_phase, m_phaseData, m_sourceRate, m_targetRate, Resampler::Phase::nextPhase, and KaiserWindow::parametersForBandwidth().
Referenced by Resampler(), and Resampler().
|
private |
Definition at line 290 of file Resampler.cpp.
References Resampler::Phase::drop, Resampler::Phase::filter, m_buffer, m_bufferOrigin, m_phase, m_phaseData, and Resampler::Phase::nextPhase.
Referenced by process().
|
private |
Definition at line 78 of file Resampler.h.
Referenced by initialise(), process(), and process().
|
private |
Definition at line 79 of file Resampler.h.
Referenced by initialise(), process(), and process().
|
private |
Definition at line 80 of file Resampler.h.
Referenced by initialise(), and process().
|
private |
Definition at line 81 of file Resampler.h.
Referenced by initialise().
|
private |
Definition at line 82 of file Resampler.h.
|
private |
Definition at line 83 of file Resampler.h.
Referenced by getLatency(), and initialise().
|
private |
Definition at line 84 of file Resampler.h.
Referenced by initialise(), and process().
|
private |
Definition at line 92 of file Resampler.h.
Referenced by initialise(), process(), reconstructOne(), and ~Resampler().
|
private |
Definition at line 93 of file Resampler.h.
Referenced by initialise(), process(), and reconstructOne().
|
private |
Definition at line 94 of file Resampler.h.
Referenced by initialise(), process(), and reconstructOne().
|
private |
Definition at line 95 of file Resampler.h.
Referenced by initialise(), process(), and reconstructOne().