Files
stk/src/Noise.cpp
Gary Scavone 27d9b79dc7 Version 4.3.0
2013-09-29 23:07:00 +02:00

50 lines
1015 B
C++

/***************************************************/
/*! \class Noise
\brief STK noise generator.
Generic random number generation using the
C rand() function. The quality of the rand()
function varies from one OS to another.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
*/
/***************************************************/
#include "Noise.h"
#include <stdlib.h>
#include <time.h>
Noise :: Noise() : Generator()
{
// Seed the random number generator with system time.
this->setSeed( 0 );
lastOutput_ = (StkFloat) 0.0;
}
Noise :: Noise( unsigned int seed ) : Generator()
{
// Seed the random number generator
this->setSeed( seed );
lastOutput_ = (StkFloat) 0.0;
}
Noise :: ~Noise()
{
}
void Noise :: setSeed( unsigned int seed )
{
if ( seed == 0 )
srand( (unsigned int) time(NULL) );
else
srand( seed );
}
StkFloat Noise :: computeSample()
{
lastOutput_ = (StkFloat) (2.0 * rand() / (RAND_MAX + 1.0) );
lastOutput_ -= 1.0;
return lastOutput_;
}