Integer-ratio IIR sample rate converter.
The multi-rate filtering approach was inspired by
M. Holters and J. D. Parker, "A Combined Model for a Bucket Brigade Device and its Input and Output Filters", 21st Intl. Conf. Digital Audio Effects (DAFx-18), Aveiro, Portugal, September 2018.
Version: 1.2.0
License:
Advanced version: bwp_src_int
Included in Brickworks, which is:
Here you can download one or more example VST3 plugins for Windows, macOS and Linux. Source code of the audio engine(s) is included in the archive(s).
Description | Link |
---|---|
Hard clipper | Download |
Distortion | Download |
Overdrive | Download |
Fuzz | Download |
Saturation | Download |
Module type: DSP
typedef struct bw_src_int_coeffs bw_src_int_coeffs;
Coefficients and related.
typedef struct bw_src_int_state bw_src_int_state;
Internal state and related.
static inline void bw_src_int_init(
bw_src_int_coeffs * BW_RESTRICT coeffs,
int ratio);
Initializes coeffs
using the given resampling ratio
.
If ratio
is positive, then the sample rate of the output signal will be ratio
times the sample rate of the input signal, otherwise, if it is negative, then the sample rate of the output signal will be equal to the sample rate of the input signal divided by -ratio
.
ratio
must not be in [-1
, 1
].
static inline float bw_src_int_reset_state(
const bw_src_int_coeffs * BW_RESTRICT coeffs,
bw_src_int_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_int_reset_state_multi(
const bw_src_int_coeffs * BW_RESTRICT coeffs,
bw_src_int_state * BW_RESTRICT const * BW_RESTRICT state,
const float * x_0,
float * y_0,
size_t n_channels);
Resets each of the n_channels
state
s 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 size_t bw_src_int_process(
const bw_src_int_coeffs * BW_RESTRICT coeffs,
bw_src_int_state * BW_RESTRICT state,
const float * BW_RESTRICT x,
float * BW_RESTRICT y,
size_t n_in_samples);
Processes the first n_in_samples
of the input buffer x
and fills the output buffer y
using coeffs
, while using and updating state
.
The number of generated output samples will be ratio
times n_in_samples
if ratio
is positive, otherwise at most n_in_samples
divided by -ratio
and then rounded towards positive infinity.
x
and y
must point to different buffers.
Returns the number of generated output samples.
static inline void bw_src_int_process_multi(
const bw_src_int_coeffs * BW_RESTRICT coeffs,
bw_src_int_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 n_in_samples,
size_t * BW_RESTRICT n_out_samples);
Processes the first n_in_samples
of the n_channels
input buffers x
and fills the n_channels
output buffers y
using coeffs
, while using and updating each of the n_channels
state
s.
The number of generated output samples in each output buffer will be ratio
times n_in_samples
if ratio
is positive, otherwise at most n_in_samples
divided by -ratio
and then rounded towards positive infinity.
A given buffer cannot be used both as an input and output buffer.
n_out_samples
is filled with the number of generated output samples for each output buffer, if not BW_NULL
.
static inline char bw_src_int_coeffs_is_valid(
const bw_src_int_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_int_coeffs
.
static inline char bw_src_int_state_is_valid(
const bw_src_int_coeffs * BW_RESTRICT coeffs,
const bw_src_int_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_int_state
.
template<size_t N_CHANNELS>
class SRCInt {
public:
SRCInt(
int ratio);
void reset(
float x0 = 0.f,
float * BW_RESTRICT y0 = nullptr);
# 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 = nullptr);
# ifndef BW_CXX_NO_ARRAY
void reset(
std::array<float, N_CHANNELS> x0,
std::array<float, N_CHANNELS> * BW_RESTRICT y0 = nullptr);
# endif
void process(
const float * BW_RESTRICT const * BW_RESTRICT x,
float * const * BW_RESTRICT y,
size_t nInSamples,
size_t * BW_RESTRICT nOutSamples = nullptr);
# ifndef BW_CXX_NO_ARRAY
void process(
std::array<const float * BW_RESTRICT, N_CHANNELS> x,
std::array<float * BW_RESTRICT, N_CHANNELS> y,
size_t nInSamples,
std::array<size_t, N_CHANNELS> * BW_RESTRICT nOutSamples = nullptr);
# endif
...
}
BW_INCLUDE_WITH_QUOTES
, BW_NO_CXX
, and BW_CXX_NO_EXTERN_C
.BW_NULL
and BW_CXX_NO_ARRAY
.bw_src_int_reset_state_multi()
and updated C++ API in this regard.bw_src_int_reset_state()
returns the initial output value.reset()
functions taking arrays as arguments.bw_src_int_lim_process()
and bw_src_int_lim_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_int_process_multi()
.