Brickworks > API documentation > bw_noise_gen



Generator of white noise with uniform distribution.

This module has no internal state, rather its state is stored into a uint64_t value to which the API user supplies a pointer (as in bw_rand).


Module type: dsp

Version: 1.1.0




typedef struct bw_noise_gen_coeffs bw_noise_gen_coeffs;

Coefficients and related.


static inline void bw_noise_gen_init(
	bw_noise_gen_coeffs * BW_RESTRICT coeffs,
	uint64_t * BW_RESTRICT            state);

Initializes input parameter values and sets the state pointer to obtain pseudo-random numbers in coeffs.


static inline void bw_noise_gen_set_sample_rate(
	bw_noise_gen_coeffs * BW_RESTRICT coeffs,
	float                             sample_rate);

Sets the sample_rate (Hz) value in coeffs.


static inline void bw_noise_gen_reset_coeffs(
	bw_noise_gen_coeffs * BW_RESTRICT coeffs);

Resets coefficients in coeffs to assume their target values.


static inline void bw_noise_gen_update_coeffs_ctrl(
	bw_noise_gen_coeffs * BW_RESTRICT coeffs);

Triggers control-rate update of coefficients in coeffs.


static inline void bw_noise_gen_update_coeffs_audio(
	bw_noise_gen_coeffs * BW_RESTRICT coeffs);

Triggers audio-rate update of coefficients in coeffs.


static inline float bw_noise_gen_process1(
	const bw_noise_gen_coeffs * BW_RESTRICT coeffs);

static inline float bw_noise_gen_process1_scaling(
	const bw_noise_gen_coeffs * BW_RESTRICT coeffs);

These functions generate and return one sample using coeffs, where:

Whether sample rate scaling is enabled or not is unchecked even for debugging purposes.


static inline void bw_noise_gen_process(
	bw_noise_gen_coeffs * BW_RESTRICT coeffs,
	float * BW_RESTRICT               y,
	size_t                            n_samples);

Generates and fills the first n_samples of the output buffer y using coeffs.


static inline void bw_noise_gen_process_multi(
	bw_noise_gen_coeffs * BW_RESTRICT       coeffs,
	float * BW_RESTRICT const * BW_RESTRICT y,
	size_t                                  n_channels,
	size_t                                  n_samples);

Generates and fills the first n_samples of the n_channels output buffers y using coeffs.


static inline void bw_noise_gen_set_sample_rate_scaling(
	bw_noise_gen_coeffs * BW_RESTRICT coeffs,
	char                              value);

Sets whether the output should be scaled (value non-0) or not (0) according to the sample rate in coeffs.

In order to maintain the same perceived loudness at different sample rates, a white noise signal with uniform distribution should be accordingly scaled. The 44100 Hz sample rate is used as a reference (that is, the scaling factor at that sample rate is 1.f).

Default value: 0 (off).


static inline float bw_noise_gen_get_scaling_k(
	const bw_noise_gen_coeffs * BW_RESTRICT coeffs);

Returns the sample rate scaling factor that is applied or would be applied if sample rate scaling were enabled, as stored in coeffs.

coeffs must be at least inthe "sample-rate-set" state.


static inline char bw_noise_gen_coeffs_is_valid(
	const bw_noise_gen_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_noise_gen_coeffs.

C++ wrapper

template<size_t N_CHANNELS>
class NoiseGen {
		uint64_t * BW_RESTRICT state);

	void setSampleRate(
		float sampleRate);

	void reset();

	void process(
		float * BW_RESTRICT const * BW_RESTRICT y,
		size_t                                  nSamples);

	void process(
		std::array<float * BW_RESTRICT, N_CHANNELS> y,
		size_t                                      nSamples);

	void setSampleRateScaling(
		bool value);
	float getScalingK();