bw_src_int

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.

Examples

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).

DescriptionLink
Hard clipper Download
Distortion Download
Overdrive Download
Fuzz Download
Saturation Download
VST® is a trademark of Steinberg Media Technologies GmbH, registered in Europe and other countries.

API

Module type: DSP

bw_src_int_coeffs

typedef struct bw_src_int_coeffs bw_src_int_coeffs;

Coefficients and related.

bw_src_int_state

typedef struct bw_src_int_state bw_src_int_state;

Internal state and related.

bw_src_int_init()

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].

bw_src_int_reset_state()

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.

bw_src_int_reset_state_multi()

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 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_int_process()

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.

bw_src_int_process_multi()

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 states.

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.

bw_src_int_coeffs_is_valid()

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.

bw_src_int_state_is_valid()

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.

C++ wrapper

Brickworks::SRCInt
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
...
}

Changelog

  • Version 1.2.0:
    • Added support for BW_INCLUDE_WITH_QUOTES, BW_NO_CXX, and BW_CXX_NO_EXTERN_C.
  • Version 1.1.0:
    • Now using BW_NULL and BW_CXX_NO_ARRAY.
  • Version 1.0.0:
    • Added bw_src_int_reset_state_multi() and updated C++ API in this regard.
    • Now bw_src_int_reset_state() returns the initial output value.
    • Added overloaded C++ 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.
    • Added more const and BW_RESTRICT specifiers to input arguments and implementation.
    • Moved C++ code to C header.
    • Added overloaded C++ process() function taking C-style arrays as arguments.
    • Fixed frequency response and improved speed.
    • Removed usage of reserved identifiers.
    • Clarified that the same buffer cannot be used for both input and output.
    • Added debugging code.
  • Version 0.6.0:
    • Removed dependency on bw_config.
  • Version 0.5.0:
    • Added bw_src_int_process_multi().
    • Added C++ wrapper.
  • Version 0.4.0:
    • First release.