Brickworks > API documentation > bw_src

bw_src

Description

Aribtrary-ratio IIR sample rate converter.

Info

Module type: dsp

Version: 1.1.0

Requires:

API

bw_src_coeffs

typedef struct bw_src_coeffs bw_src_coeffs;

Coefficients and related.

bw_src_state

typedef struct bw_src_state bw_src_state;

Internal state and related.

bw_src_init()

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.

bw_src_reset_state()

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.

bw_src_reset_state_multi()

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.

bw_src_process()

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.

bw_src_process_multi()

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.

bw_src_coeffs_is_valid()

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.

bw_src_state_is_valid()

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.

C++ wrapper

Brickworks::SRC
template<size_t N_CHANNELS>
class SRC {
public:
	SRC(
		float 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 * 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
...
}

ChangeLog