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

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
Monophonic subtractive synth Download
Polyphonic subtractive synth Download
VST® is a trademark of Steinberg Media Technologies GmbH, registered in Europe and other countries.

API

Module type: DSP

bw_noise_gen_coeffs

typedef struct bw_noise_gen_coeffs bw_noise_gen_coeffs;

Coefficients and related.

bw_noise_gen_init()

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.

bw_noise_gen_set_sample_rate()

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.

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

bw_noise_gen_update_coeffs_ctrl()

static inline void bw_noise_gen_update_coeffs_ctrl(
	bw_noise_gen_coeffs * BW_RESTRICT coeffs);

Triggers control-rate update of coefficients in coeffs.

bw_noise_gen_update_coeffs_audio()

static inline void bw_noise_gen_update_coeffs_audio(
	bw_noise_gen_coeffs * BW_RESTRICT coeffs);

Triggers audio-rate update of coefficients in coeffs.

bw_noise_gen_process1*()

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:

  • bw_noise_gen_process1() assumes that sample rate scaling is disabled;
  • bw_noise_gen_process1_scaling() assumes that sample rate scaling is enabled.

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

bw_noise_gen_process()

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.

bw_noise_gen_process_multi()

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.

bw_noise_gen_set_sample_rate_scaling()

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

bw_noise_gen_get_scaling_k()

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.

bw_noise_gen_coeffs_is_valid()

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

Brickworks::NoiseGen
template<size_t N_CHANNELS>
class NoiseGen {
public:
	NoiseGen(
		uint64_t * BW_RESTRICT state);

	void setSampleRate(
		float sampleRate);

	void reset();

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

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

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

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_noise_gen_reset_coeffs(), bw_noise_gen_update_coeffs_ctrl(), and bw_noise_gen_update_coeffs_audio().
    • bw_noise_gen_process() and bw_noise_gen_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.
    • Removed usage of reserved identifiers.
    • Added debugging code.
  • Version 0.6.0:
    • Removed dependency on bw_config.
  • Version 0.5.0:
    • Added bw_noise_gen_process_multi().
    • Added C++ wrapper.
  • Version 0.2.0:
    • Refactored API.
  • Version 0.1.0:
    • First release.