class
SushiDSP::Resampler
Arbitrary-ratio polyphase resampler over one committed prototype filter.
- Declared in
include/SushiDSP/math/Resampler.hpp
A single fractional phase accumulator walks the kernel of src/math/ResamplerKernel.hpp; a ratio change moves the accumulator's step and the kernel's time scale, and never rebuilds a filter bank. Every buffer is sized in prepare(); process() and set_rates() are allocation-, lock-, syscall- and throw-free.
Static public attributes
static constexpr double kMaximumRatio = 16.0Largest target/source ratio set_rates() will honour.
Public member functions
void prepare(double source_rate, double target_rate, std::uint32_t max_input_frames, double minimum_ratio)Sizes every buffer for the worst case this instance will be asked for.
Parameters
source_rateInitial input rate in Hz.
target_rateInitial output rate in Hz.
max_input_framesLargest input_frames a single process() call will carry.
minimum_ratioSmallest target/source this instance will ever be set to; the kernel's span grows as 1/ratio when decimating, so this sizes the history.
void set_rates(double source_rate, double target_rate)Changes the conversion rates.
Real-time safe; allocates nothing.
Parameters
source_rateInput rate in Hz.
target_rateOutput rate in Hz.
Precondition
prepare() has been called; the ratio is clamped to [minimum_ratio, kMaximumRatio].
std::uint32_t process(const float *input, std::uint32_t input_frames, float *output, std::uint32_t output_capacity)Converts one push of input, producing however many outputs are now available.
Parameters
input_framesNumber of input samples; must not exceed max_input_frames.
outputDestination, at least output_capacity samples; must not alias input.
output_capacityRoom available; use maximum_output_frames() to size it. A smaller buffer defers the rest to the next call, and drops the deferred backlog once it reaches further back than the history ring holds.
Precondition
prepare() has been called.
Returns
Number of output samples written.
std::uint32_t maximum_output_frames(std::uint32_t input_frames) constUpper bound on what process() can return for that many input frames.
Parameters
input_framesThe push size.
Returns
Output samples to make room for, at the current rates.
double latency_seconds() constAvailability latency: an output at time t reads input a kernel half span either side of t, so it can only be emitted once the input half a span past it has arrived.
Report it for plugin delay compensation and size buffers with it. The converter is zero phase, so output time t carries input time t and a null against a dry path aligns at lag 0; subtracting this value as an offset misaligns it.
Returns
Availability latency in seconds, 34 / min(source_rate, target_rate).
std::uint32_t latency_samples() constThe same availability latency counted in source-rate samples, rounded to nearest.
Look-ahead, never an alignment offset; see latency_seconds().
Returns
Look-ahead in input samples.

