MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ resample()

MAYAFLUX_API std::vector< double > MayaFlux::Kinesis::Discrete::resample ( std::span< const double > src,
uint32_t from_rate,
uint32_t to_rate,
const ResampleConfig & config = {} )
nodiscard

Resample a sequence from one rate to another with an anti-aliasing filter.

The ratio is reduced to up / down by its greatest common divisor and applied as a polyphase filter: the sequence is conceptually upsampled by up, lowpass filtered at the lower of the two Nyquist frequencies, and decimated by down, without computing the samples in between. Output sample k is at time k / to_rate and the filter delay is removed, so the first output sample lines up with the first input sample. Samples outside the input are zero. The same rates return a copy. Output blocks are computed in parallel.

The result matches scipy.signal.resample_poly with a Kaiser window of the same beta and a filter half length of zero_crossings * max(up, down) samples.

Parameters
srcInput samples
from_rateRate of the input in Hz
to_rateRate of the output in Hz
configAnti-aliasing filter design
Returns
resampled_length(src.size(), from_rate, to_rate) samples, empty when the input is empty or either rate is 0

Definition at line 135 of file Resample.cpp.

137{
138 if (src.empty() || from_rate == 0 || to_rate == 0) {
139 return {};
140 }
141 if (from_rate == to_rate) {
142 return { src.begin(), src.end() };
143 }
144
145 const uint32_t divisor = std::gcd(from_rate, to_rate);
146 const uint32_t up = to_rate / divisor;
147 const uint32_t down = from_rate / divisor;
148
149 const auto table = build_polyphase(design_filter(up, down, config), up);
150 std::vector<double> out(resampled_length(src.size(), from_rate, to_rate));
151 fill_outputs(src, 0, table, 0, out, up, down);
152 return out;
153}
size_t resampled_length(size_t samples, uint32_t from_rate, uint32_t to_rate) noexcept
Number of samples resample returns.
Definition Resample.cpp:126

References resample(), and resampled_length().

Referenced by resample().

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