Class samplerate_converter¶
class samplerate_converter<T> dsp¶
template <typename T>
struct samplerate_converter { … } A template class for performing sample rate conversion on audio signals.
This class supports both push and pull methods for resampling audio data. It maintains an internal state to handle contiguous signals split into buffers of varying sizes.
| T | The data type of the audio samples (e.g., float, double). |
typedef itype ¶
using itype = i64 Fully qualified name: kfr::samplerate_converter<T>::itype
Declared at dsp/sample_rate_conversion.hpp:69
typedef ftype ¶
using ftype = subtype<T> Fully qualified name: kfr::samplerate_converter<T>::ftype
Declared at dsp/sample_rate_conversion.hpp:70
function window(fbase) ¶
Computes the Kaiser window function for a given sample position.
| n | Normalized sample position. |
| The window value. |
Fully qualified name: kfr::samplerate_converter<T>::window(fbase)
Declared at dsp/sample_rate_conversion.hpp:78
function sidelobe_att() ¶
Calculates the sidelobe attenuation based on the Kaiser beta parameter.
| Sidelobe attenuation in dB. |
Fully qualified name: kfr::samplerate_converter<T>::sidelobe_att()
Declared at dsp/sample_rate_conversion.hpp:87
function transition_width() ¶
Calculates the transition width based on sidelobe attenuation and depth.
| Transition width in radians. |
Fully qualified name: kfr::samplerate_converter<T>::transition_width()
Declared at dsp/sample_rate_conversion.hpp:93
function reset() ¶
void reset() noexcept Resets the converter to its initial state.
Fully qualified name: kfr::samplerate_converter<T>::reset()
Declared at dsp/sample_rate_conversion.hpp:106
function filter_order(sample_rate_conversion_quality) ¶
static KFR_MEM_INTRINSIC size_t filter_order(sample_rate_conversion_quality quality) Computes the filter order for a given quality level.
| quality | The sample rate conversion quality. |
| The filter order as a size_t. |
Fully qualified name: kfr::samplerate_converter<T>::filter_order(sample_rate_conversion_quality)
Declared at dsp/sample_rate_conversion.hpp:118
function sidelobe_attenuation(sample_rate_conversion_quality) ¶
static KFR_MEM_INTRINSIC fbase sidelobe_attenuation(sample_rate_conversion_quality quality) Returns the sidelobe attenuation for a given quality level.
| quality | The sample rate conversion quality. |
| Sidelobe attenuation in dB. |
Fully qualified name: kfr::samplerate_converter<T>::sidelobe_attenuation(sample_rate_conversion_quality)
Declared at dsp/sample_rate_conversion.hpp:128
function transition_width(sample_rate_conversion_quality) ¶
static KFR_MEM_INTRINSIC fbase transition_width(sample_rate_conversion_quality quality) Returns the transition width for a given quality level.
| quality | The sample rate conversion quality. |
| Transition width in radians. |
Fully qualified name: kfr::samplerate_converter<T>::transition_width(sample_rate_conversion_quality)
Declared at dsp/sample_rate_conversion.hpp:138
function window_param(sample_rate_conversion_quality) ¶
static KFR_MEM_INTRINSIC fbase window_param(sample_rate_conversion_quality quality) Computes the Kaiser window parameter for a given quality level.
| quality | The sample rate conversion quality. |
| The Kaiser beta parameter. |
Fully qualified name: kfr::samplerate_converter<T>::window_param(sample_rate_conversion_quality)
Declared at dsp/sample_rate_conversion.hpp:148
function window_param(fbase) ¶
Fully qualified name: kfr::samplerate_converter<T>::window_param(fbase)
Declared at dsp/sample_rate_conversion.hpp:152
constructor samplerate_converter<T>(sample_rate_conversion_quality, itype, itype, fbase, fbase) ¶
samplerate_converter(sample_rate_conversion_quality quality, itype interpolation_factor,
itype decimation_factor, fbase scale = ftype(1), fbase cutoff = 0.5f) Constructs a sample rate converter.
| quality | The desired conversion quality. |
| interpolation_factor | Factor by which to interpolate the input signal. |
| decimation_factor | Factor by which to decimate the output signal. |
| scale | Scaling factor for the output (default: 1). |
| cutoff | Cutoff frequency as a fraction of the Nyquist frequency (default: 0.5). |
Fully qualified name: kfr::samplerate_converter<T>::samplerate_converter<T>(sample_rate_conversion_quality, itype, itype, fbase, fbase)
Declared at dsp/sample_rate_conversion.hpp:169
constructor samplerate_converter<T>(int, itype, itype, fbase, fbase, fbase, fbase) ¶
samplerate_converter(int taps, itype interpolation_factor, itype decimation_factor, fbase scale,
fbase cutoff, fbase sidelobe_attenuation, fbase transition_width) Constructs a sample rate converter from explicit filter parameters.
| taps | Number of taps per polyphase branch (processing depth). |
| interpolation_factor | Factor by which to interpolate the input signal. |
| decimation_factor | Factor by which to decimate the output signal. |
| scale | Scaling factor applied to the output. |
| cutoff | Cutoff frequency as a fraction of the Nyquist frequency. |
| sidelobe_attenuation | Sidelobe attenuation in dB used to derive the Kaiser window. |
| transition_width | Transition width in radians used to adjust the cutoff. |
Fully qualified name: kfr::samplerate_converter<T>::samplerate_converter<T>(int, itype, itype, fbase, fbase, fbase, fbase)
Declared at dsp/sample_rate_conversion.hpp:182
constructor samplerate_converter<T>() ¶
samplerate_converter() = default Default constructor.
Fully qualified name: kfr::samplerate_converter<T>::samplerate_converter<T>()
Declared at dsp/sample_rate_conversion.hpp:193
constructor samplerate_converter<T>(samplerate_converter<T> &&) ¶
samplerate_converter(samplerate_converter&&) noexcept = default Move constructor.
Fully qualified name: kfr::samplerate_converter<T>::samplerate_converter<T>(samplerate_converter<T> &&)
Declared at dsp/sample_rate_conversion.hpp:202
function operator=(samplerate_converter<T> &&) ¶
samplerate_converter& operator=(samplerate_converter&&) noexcept = default Move assignment operator.
| other | The converter to move from. |
A reference to *this . |
Fully qualified name: kfr::samplerate_converter<T>::operator=(samplerate_converter<T> &&)
Declared at dsp/sample_rate_conversion.hpp:214
function input_position_to_intermediate(itype) ¶
Converts an input position to an intermediate (interpolated) position.
The intermediate domain is the high-rate domain obtained after interpolation and before decimation. This maps an input sample index to its corresponding index in that domain.
| in_pos | Input position. |
Intermediate position in_pos * interpolation_factor . |
Fully qualified name: kfr::samplerate_converter<T>::input_position_to_intermediate(itype)
Declared at dsp/sample_rate_conversion.hpp:225
function output_position_to_intermediate(itype) ¶
Converts an output position to an intermediate (pre-decimation) position.
Maps an output sample index back to its corresponding index in the high-rate intermediate domain.
| out_pos | Output position. |
Intermediate position out_pos * decimation_factor . |
Fully qualified name: kfr::samplerate_converter<T>::output_position_to_intermediate(itype)
Declared at dsp/sample_rate_conversion.hpp:238
function input_position_to_output(itype) ¶
Converts an input position to the corresponding output position.
Uses floor division of the intermediate position by the decimation factor, so the result is the index of the output sample that consumes the given input sample (or the last output sample produced at or before it).
| in_pos | Input position. |
| Corresponding output position. |
Fully qualified name: kfr::samplerate_converter<T>::input_position_to_output(itype)
Declared at dsp/sample_rate_conversion.hpp:252
function output_position_to_input(itype) ¶
Converts an output position to the corresponding input position.
Uses floor division of the intermediate position by the interpolation factor, so the result is the index of the input sample needed to produce the given output sample.
| out_pos | Output position. |
| Corresponding input position. |
Fully qualified name: kfr::samplerate_converter<T>::output_position_to_input(itype)
Declared at dsp/sample_rate_conversion.hpp:266
function output_size_for_input(itype) ¶
Calculates the output size produced for a given input size (push method).
| input_size | Size of the input buffer. |
| Required output buffer size. |
Fully qualified name: kfr::samplerate_converter<T>::output_size_for_input(itype)
Declared at dsp/sample_rate_conversion.hpp:280
function input_size_for_output(itype) ¶
Calculates the input size required to produce a given output size (pull method).
| output_size | Size of the output buffer. |
| Required input buffer size. |
Fully qualified name: kfr::samplerate_converter<T>::input_size_for_output(itype)
Declared at dsp/sample_rate_conversion.hpp:295
function skip(size_t, univector_ref<const T>) ¶
size_t skip(size_t output_size, univector_ref<const T> input) Skips a specified number of output samples, updating internal state.
| output_size | Number of output samples to skip. |
| input | Input buffer to consume. |
| Number of input samples consumed. |
Fully qualified name: kfr::samplerate_converter<T>::skip(size_t, univector_ref<const T>)
Declared at dsp/sample_rate_conversion.hpp:313
function process(univector<T, Tag> &, univector_ref<const T>) ¶
template <univector_tag Tag>
size_t process(univector<T, Tag>& output, univector_ref<const T> input) Processes input data to produce resampled output (pull or push method).
| Tag | Type tag for the univector output. |
| output | Output buffer to write resampled data. |
| input | Input buffer to read samples from. |
| Number of input samples processed. |
Fully qualified name: kfr::samplerate_converter<T>::process(univector<T, Tag> &, univector_ref<const T>)
Declared at dsp/sample_rate_conversion.hpp:347
function get_fractional_delay() ¶
Gets the fractional delay introduced by the resampler.
The delay is the group delay of the symmetric FIR filter, expressed in output-sample units.
| Fractional delay in output samples. |
Fully qualified name: kfr::samplerate_converter<T>::get_fractional_delay()
Declared at dsp/sample_rate_conversion.hpp:359
function get_delay() ¶
Gets the integer delay introduced by the resampler.
| Delay in output samples. |
Fully qualified name: kfr::samplerate_converter<T>::get_delay()
Declared at dsp/sample_rate_conversion.hpp:369
variable kaiser_beta ¶
fbase kaiser_beta Kaiser window beta parameter.
Fully qualified name: kfr::samplerate_converter<T>::kaiser_beta
Declared at dsp/sample_rate_conversion.hpp:371
variable depth ¶
itype depth Processing depth.
Fully qualified name: kfr::samplerate_converter<T>::depth
Declared at dsp/sample_rate_conversion.hpp:372
variable taps ¶
itype taps Number of filter taps.
Fully qualified name: kfr::samplerate_converter<T>::taps
Declared at dsp/sample_rate_conversion.hpp:373
variable order ¶
size_t order Filter order.
Fully qualified name: kfr::samplerate_converter<T>::order
Declared at dsp/sample_rate_conversion.hpp:374
variable interpolation_factor ¶
itype interpolation_factor Interpolation factor.
Fully qualified name: kfr::samplerate_converter<T>::interpolation_factor
Declared at dsp/sample_rate_conversion.hpp:375
variable decimation_factor ¶
itype decimation_factor Decimation factor.
Fully qualified name: kfr::samplerate_converter<T>::decimation_factor
Declared at dsp/sample_rate_conversion.hpp:376
variable filter ¶
univector<T> filter Filter coefficients.
Fully qualified name: kfr::samplerate_converter<T>::filter
Declared at dsp/sample_rate_conversion.hpp:377
variable delay ¶
univector<T> delay Delay line buffer.
Fully qualified name: kfr::samplerate_converter<T>::delay
Declared at dsp/sample_rate_conversion.hpp:378
variable input_position ¶
itype input_position Current input position.
Fully qualified name: kfr::samplerate_converter<T>::input_position
Declared at dsp/sample_rate_conversion.hpp:381
variable output_position ¶
itype output_position Current output position.
Fully qualified name: kfr::samplerate_converter<T>::output_position
Declared at dsp/sample_rate_conversion.hpp:382
function process_impl(univector_ref<T>, univector_ref<const T>) ¶
size_t process_impl(univector_ref<T> output, univector_ref<const T> input) Internal implementation of the process function.
| output | Output buffer slice. |
| input | Input buffer slice. |
| Number of input samples processed. |
Fully qualified name: kfr::samplerate_converter<T>::process_impl(univector_ref<T>, univector_ref<const T>)
Declared at dsp/sample_rate_conversion.hpp:390
Fully qualified name: kfr::samplerate_converter<T>
Declared at dsp/sample_rate_conversion.hpp:67