Commit c454ef41 authored by David Reid's avatar David Reid Committed by GitHub

Merge pull request #231 from MichealReed/dynamic_noise

added dynamic amplitude, seed, type to noise generation
parents e7940394 54a80d6a
......@@ -1190,6 +1190,9 @@ miniaudio supports generation of white, pink and Brownian noise via the `ma_nois
The noise API uses simple LCG random number generation. It supports a custom seed which is useful for things like automated testing requiring reproducibility.
Setting the seed to zero will default to MA_DEFAULT_LCG_SEED.
The amplitude, seed, and type can be changed dynamically with `ma_noise_set_amplitude()`, `ma_noise_set_seed()`,
and `ma_noise_set_type()` respectively.
By default, the noise API will use different values for different channels. So, for example, the left side in a stereo stream will be different to the right
side. To instead have each channel use the same random value, set the `duplicateChannels` member of the noise config to true, like so:
......@@ -6107,8 +6110,6 @@ MA_API ma_result ma_waveform_set_frequency(ma_waveform* pWaveform, double freque
MA_API ma_result ma_waveform_set_type(ma_waveform* pWaveform, ma_waveform_type type);
MA_API ma_result ma_waveform_set_sample_rate(ma_waveform* pWaveform, ma_uint32 sampleRate);
typedef enum
{
ma_noise_type_white,
......@@ -6150,6 +6151,9 @@ typedef struct
MA_API ma_result ma_noise_init(const ma_noise_config* pConfig, ma_noise* pNoise);
MA_API ma_uint64 ma_noise_read_pcm_frames(ma_noise* pNoise, void* pFramesOut, ma_uint64 frameCount);
MA_API ma_result ma_noise_set_amplitude(ma_noise* pNoise, double amplitude);
MA_API ma_result ma_noise_set_seed(ma_noise* pNoise, ma_uint32 seed);
MA_API ma_result ma_noise_set_type(ma_noise* pNoise, ma_noise_type type);
#endif /* MA_NO_GENERATION */
......@@ -48443,6 +48447,37 @@ MA_API ma_result ma_noise_init(const ma_noise_config* pConfig, ma_noise* pNoise)
return MA_SUCCESS;
}
MA_API ma_result ma_noise_set_amplitude(ma_noise* pNoise, double amplitude)
{
if (pNoise == NULL) {
return MA_INVALID_ARGS;
}
pNoise->config.amplitude = amplitude;
return MA_SUCCESS;
}
MA_API ma_result ma_noise_set_seed(ma_noise* pNoise, ma_int32 seed)
{
if (pNoise == NULL) {
return MA_INVALID_ARGS;
}
pNoise->lcg.state = seed;
return MA_SUCCESS;
}
MA_API ma_result ma_noise_set_type(ma_noise* pNoise, ma_noise_type type)
{
if (pNoise == NULL) {
return MA_INVALID_ARGS;
}
pNoise->config.type = type;
return MA_SUCCESS;
}
static MA_INLINE float ma_noise_f32_white(ma_noise* pNoise)
{
return (float)(ma_lcg_rand_f64(&pNoise->lcg) * pNoise->config.amplitude);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment