Advanced version of bw_src_int based on tunable Type II Chebyshev filters.
We can privately hand you one or more example plugins if you are interested.
Module type: DSP
typedef struct bwp_src_int_coeffs bwp_src_int_coeffs;
Coefficients and related.
typedef struct bwp_src_int_state bwp_src_int_state;
Internal state and related.
static inline void bwp_src_int_init(
bwp_src_int_coeffs * BW_RESTRICT coeffs,
int ratio,
int order,
float cutoff_k,
float attenuation);
Initializes coeffs
using the given resampling ratio
, filter order
, resampling filter cutoff scaling factor cutoff_k
, and stopband attenuation
factor (linear gain).
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
.
The actual resampling filter cutoff is computed as
cutoff = 0.5 * cutoff_k / |ratio|
ratio
must not be in [-1
, 1
].
order
must be even and in [2
, 16
].
cutoff_k
must be positive and it must be cutoff_k < |ratio|
.
attenuation
must be finite and positive.
static inline float bwp_src_int_reset_state(
const bwp_src_int_coeffs * BW_RESTRICT coeffs,
bwp_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 bwp_src_int_reset_state_multi(
const bwp_src_int_coeffs * BW_RESTRICT coeffs,
bwp_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 bwp_src_int_process(
const bwp_src_int_coeffs * BW_RESTRICT coeffs,
bwp_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 bwp_src_int_process_multi(
const bwp_src_int_coeffs * BW_RESTRICT coeffs,
bwp_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 bwp_src_int_coeffs_is_valid(
const bwp_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 bwp_src_int_coeffs
.
static inline char bwp_src_int_state_is_valid(
const bwp_src_int_coeffs * BW_RESTRICT coeffs,
const bwp_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 bwp_src_int_state
.
template<size_t N_CHANNELS>
class SRCInt {
public:
SRCInt(
int ratio,
int order,
float cutoff_k,
float attenuation);
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 * const * BW_RESTRICT y,
size_t nInSamples,
size_t * BW_RESTRICT nOutSamples = BW_NULL);
# 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 = BW_NULL);
# endif
...
}
BW_NULL
in the C++ API and implementation.