Aribtrary-ratio IIR sample rate converter.
Version: 1.2.2
License:
Included in Brickworks, which is:
Module type: DSP
typedef struct bw_src_coeffs bw_src_coeffs;
Coefficients and related.
typedef struct bw_src_state bw_src_state;
Internal state and related.
static inline void bw_src_init(
bw_src_coeffs * BW_RESTRICT coeffs,
float ratio);
Initializes coeffs using the given resampling ratio.
ratio must be positive and determines the sample rate of the output signal, which will be equal to ratio times the sample rate of the input signal.
static inline float bw_src_reset_state(
const bw_src_coeffs * BW_RESTRICT coeffs,
bw_src_state * BW_RESTRICT state,
float x_0);
Resets the given state to its initial values using the given coeffs and the initial input value x_0.
Returns the corresponding initial output value.
static inline void bw_src_reset_state_multi(
const bw_src_coeffs * BW_RESTRICT coeffs,
bw_src_state * BW_RESTRICT const * BW_RESTRICT state,
const float * x_0,
float * y_0,
size_t n_channels);
Resets each of the n_channels states to its initial values using the given coeffs and the corresponding initial input value in the x_0 array.
The corresponding initial output values are written into the y_0 array, if not BW_NULL.
static inline void bw_src_process(
const bw_src_coeffs * BW_RESTRICT coeffs,
bw_src_state * BW_RESTRICT state,
const float * BW_RESTRICT x,
float * BW_RESTRICT y,
size_t * BW_RESTRICT n_in_samples,
size_t * BW_RESTRICT n_out_samples);
Processes at most the first n_in_samples of the input buffer x and fills the output buffer y with at most n_out_samples using coeffs, while using and updating state.
After the call n_in_samples and n_out_samples will contain the actual number of consumed input samples and generated output samples, respectively.
x and y must point to different buffers and also n_in_samples. Also, n_in_samples and n_out_samples must be different.
static inline void bw_src_process_multi(
const bw_src_coeffs * BW_RESTRICT coeffs,
bw_src_state * BW_RESTRICT const * BW_RESTRICT state,
const float * BW_RESTRICT const * BW_RESTRICT x,
float * BW_RESTRICT const * BW_RESTRICT y,
size_t n_channels,
size_t * BW_RESTRICT n_in_samples,
size_t * BW_RESTRICT n_out_samples);
Processes at most the first n_in_samples[i] of each input buffer x[i] and fills the corresponding output buffer y[i] with at most n_out_samples[i] using coeffs, while using and updating each state[i].
After the call each element in n_in_samples and n_out_samples will contain the actual number of consumed input samples and generated output samples, respectively, for each of the n_channels input/output buffer couples.
A given buffer cannot be used both as an input and output buffer. Also, n_in_samples and n_out_samples must point to non-overlapping memory areas.
static inline char bw_src_coeffs_is_valid(
const bw_src_coeffs * BW_RESTRICT coeffs);
Tries to determine whether coeffs is valid and returns non-0 if it seems to be the case and 0 if it is certainly not. False positives are possible, false negatives are not.
coeffs must at least point to a readable memory block of size greater than or equal to that of bw_src_coeffs.
static inline char bw_src_state_is_valid(
const bw_src_coeffs * BW_RESTRICT coeffs,
const bw_src_state * BW_RESTRICT state);
Tries to determine whether state is valid and returns non-0 if it seems to be the case and 0 if it is certainly not. False positives are possible, false negatives are not.
If coeffs is not BW_NULL extra cross-checks might be performed (state is supposed to be associated to coeffs).
state must at least point to a readable memory block of size greater than or equal to that of bw_src_state.
template<size_t N_CHANNELS = 1>
class SRC {
public:
SRC(
float ratio);
void reset(
float x0 = 0.f,
float * BW_RESTRICT y0 = BW_NULL);
# ifndef BW_CXX_NO_ARRAY
void reset(
float x0,
std::array<float, N_CHANNELS> * BW_RESTRICT y0);
# endif
void reset(
const float * x0,
float * y0 = BW_NULL);
# ifndef BW_CXX_NO_ARRAY
void reset(
std::array<float, N_CHANNELS> x0,
std::array<float, N_CHANNELS> * BW_RESTRICT y0 = BW_NULL);
# endif
void process(
const float * BW_RESTRICT const * BW_RESTRICT x,
float * BW_RESTRICT const * BW_RESTRICT y,
size_t * BW_RESTRICT nInSamples,
size_t * BW_RESTRICT nOutSamples);
# ifndef BW_CXX_NO_ARRAY
void process(
std::array<const float * BW_RESTRICT, N_CHANNELS> x,
std::array<float * BW_RESTRICT, N_CHANNELS> y,
std::array<size_t, N_CHANNELS> & nInSamples,
std::array<size_t, N_CHANNELS> & nOutSamples);
# endif
...
}
N_CHANNELS in C++ API.BW_NULL in the C++ API and implementation.BW_INCLUDE_WITH_QUOTES, BW_NO_CXX, and BW_CXX_NO_EXTERN_C.BW_NULL and BW_CXX_NO_ARRAY.bw_src_reset_state_multi() and updated C++ API in this regard.bw_src_reset_state() returns the initial output value.reset() functions taking arrays as arguments.bw_src_process() and bw_src_process_multi() now use size_t to count samples and channels.const and BW_RESTRICT specifiers to input arguments and implementation.process() function taking C-style arrays as arguments.bw_src_process_multi().