1 /***************************************************/
2 /*! \class Noise
3     \brief STK noise generator.
4 
5     Generic random number generation using the
6     C rand() function.  The quality of the rand()
7     function varies from one OS to another.
8 
9     by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
10 */
11 /***************************************************/
12 
13 #include "Noise.h"
14 #include <stdlib.h>
15 #include <time.h>
16 
17 using namespace Nyq;
18 
Noise()19 Noise :: Noise() : Generator()
20 {
21   // Seed the random number generator with system time.
22   this->setSeed( 0 );
23   lastOutput_ = (StkFloat) 0.0;
24 }
25 
Noise(unsigned int seed)26 Noise :: Noise( unsigned int seed ) : Generator()
27 {
28   // Seed the random number generator
29   this->setSeed( seed );
30   lastOutput_ = (StkFloat) 0.0;
31 }
32 
~Noise()33 Noise :: ~Noise()
34 {
35 }
36 
setSeed(unsigned int seed)37 void Noise :: setSeed( unsigned int seed )
38 {
39   if ( seed == 0 )
40     srand( (unsigned int) time(NULL) );
41   else
42     srand( seed );
43 }
44 
computeSample()45 StkFloat Noise :: computeSample()
46 {
47   lastOutput_ = (StkFloat) (2.0 * rand() / (RAND_MAX + 1.0) );
48   lastOutput_ -= 1.0;
49   return lastOutput_;
50 }
51 
52