|C++ gaussian noise generation|
Type : gaussian noise generation
References : Posted by paul[at]expdigital[dot]co[dot]uk
Tobybears delphi noise generator was the basis. Simply converted it to C++.
Link for original is:
The output is in noise.
/* Include requisits */
/* Generate a new random seed from system time - do this once in your constructor */
/* Setup constants */
const static int q = 15;
const static float c1 = (1 << q) - 1;
const static float c2 = ((int)(c1 / 3)) + 1;
const static float c3 = 1.f / c1;
/* random number in range 0 - 1 not including 1 */
float random = 0.f;
/* the white noise */
float noise = 0.f;
for (int i = 0; i < numSamples; i++)
random = ((float)rand() / (float)(RAND_MAX + 1));
noise = (2.f * ((random * c2) + (random * c2) + (random * c2)) - 3.f * (c2 - 1.f)) * c3;
Added on : 10/07/09 by none[ AT ]none[ DOT ]com
What's the difference between the much simpler noise generator:
randSeed = (randSeed * 196314165) + 907633515; out=((int)randSeed)*0.0000000004656612873077392578125f;
and this one? they both sound the same to my ears...
Added on : 22/07/11 by unknown[ AT ]unknown[ DOT ]com
How can you change the variance (sigma)?
Added on : 12/06/13 by bebul[ AT ]none[ DOT ]com
This is NOT a good code to generate Gaussian Noice. Look into:
(random * c2) + (random * c2) + (random * c2)
It is all nonsense! The reason of adding three numbers it the Central Limit Theorem to aproximate Gaussian distribution. But the random numbers inside must differ, which is not the case. The code on original link http://www.musicdsp.org/archive.php?classid=0#129 is correct.
|Add your own comment|
Comments are displayed in fixed width, no HTML code allowed!