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;
from : none[AT]none[DOT]com
comment : 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...
from : unknown[AT]unknown[DOT]com
comment : How can you change the variance (sigma)?
from : bebul[AT]none[DOT]com
comment : 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.