The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Noise.h
1#ifndef STK_NOISE_H
2#define STK_NOISE_H
3
4#include "Generator.h"
5#include <stdlib.h>
6
7namespace stk {
8
9/***************************************************/
19/***************************************************/
20
21 class Noise : public Generator
22{
23public:
24
26
30 Noise( unsigned int seed = 0 );
31
33
37 void setSeed( unsigned int seed = 0 );
38
40 StkFloat lastOut( void ) const { return lastFrame_[0]; };
41
43 StkFloat tick( void );
44
46
53 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
54
55protected:
56
57};
58
59 inline StkFloat Noise :: tick( void )
60{
61 return lastFrame_[0] = (StkFloat) ( 2.0 * rand() / (RAND_MAX + 1.0) - 1.0 );
62}
63
64 inline StkFrames& Noise :: tick( StkFrames& frames, unsigned int channel )
65{
66#if defined(_STK_DEBUG_)
67 if ( channel >= frames.channels() ) {
68 oStream_ << "Noise::tick(): channel and StkFrames arguments are incompatible!";
69 handleError( StkError::FUNCTION_ARGUMENT );
70 }
71#endif
72
73 StkFloat *samples = &frames[channel];
74 unsigned int hop = frames.channels();
75 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
76 *samples = (StkFloat) ( 2.0 * rand() / (RAND_MAX + 1.0) - 1.0 );
77
78 lastFrame_[0] = *(samples-hop);
79 return frames;
80}
81
82} // stk namespace
83
84#endif
stk::Generator
STK abstract unit generator parent class.
Definition Generator.h:21
stk::Noise
STK noise generator.
Definition Noise.h:22
stk::Noise::Noise
Noise(unsigned int seed=0)
Default constructor that can also take a specific seed value.
stk::Noise::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition Noise.h:40
stk::Noise::tick
StkFloat tick(void)
Compute and return one output sample.
Definition Noise.h:59
stk::Noise::setSeed
void setSeed(unsigned int seed=0)
Seed the random number generator with a specific seed value.
stk::StkFrames
An STK class to handle vectorized audio data.
Definition Stk.h:279
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:419
stk
The STK namespace.
Definition ADSR.h:6

The Synthesis ToolKit in C++ (STK)
©1995--2023 Perry R. Cook and Gary P. Scavone. All Rights Reserved.