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).
Version: 1.2.1
License:
Included in Brickworks, which is:
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).
| Description | Link |
|---|---|
| Monophonic subtractive synth | Download |
| Polyphonic subtractive synth | Download |

Module type: DSP
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:
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.
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.
template<size_t N_CHANNELS = 1>
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();
...
}
N_CHANNELS in C++ API.BW_INCLUDE_WITH_QUOTES, BW_NO_CXX, and BW_CXX_NO_EXTERN_C.BW_NULL and BW_CXX_NO_ARRAY.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.const and BW_RESTRICT specifiers to input arguments and implementation.process() function taking C-style arrays as arguments.bw_noise_gen_process_multi().