Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Modulate.h
1 #ifndef STK_MODULATE_H
2 #define STK_MODULATE_H
3 
4 #include "Generator.h"
5 #include "SineWave.h"
6 #include "Noise.h"
7 #include "OnePole.h"
8 
9 namespace stk {
10 
11 /***************************************************/
21 /***************************************************/
22 
23 class Modulate : public Generator
24 {
25  public:
27 
30  Modulate( void );
31 
33  ~Modulate( void );
34 
36  void reset( void ) { lastFrame_[0] = 0.0; };
37 
39  void setVibratoRate( StkFloat rate ) { vibrato_.setFrequency( rate ); };
40 
42  void setVibratoGain( StkFloat gain ) { vibratoGain_ = gain; };
43 
45  void setRandomGain( StkFloat gain );
46 
48  StkFloat lastOut( void ) const { return lastFrame_[0]; };
49 
51  StkFloat tick( void );
52 
54 
61  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
62 
63  protected:
64 
65  void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
66 
67  SineWave vibrato_;
68  Noise noise_;
69  OnePole filter_;
70  StkFloat vibratoGain_;
71  StkFloat randomGain_;
72  unsigned int noiseRate_;
73  unsigned int noiseCounter_;
74 
75 };
76 
77 inline StkFloat Modulate :: tick( void )
78 {
79  // Compute periodic and random modulations.
80  lastFrame_[0] = vibratoGain_ * vibrato_.tick();
81  if ( noiseCounter_++ >= noiseRate_ ) {
82  noise_.tick();
83  noiseCounter_ = 0;
84  }
85  lastFrame_[0] += filter_.tick( noise_.lastOut() );
86  return lastFrame_[0];
87 }
88 
89 inline StkFrames& Modulate :: tick( StkFrames& frames, unsigned int channel )
90 {
91 #if defined(_STK_DEBUG_)
92  if ( channel >= frames.channels() ) {
93  oStream_ << "Modulate::tick(): channel and StkFrames arguments are incompatible!";
94  handleError( StkError::FUNCTION_ARGUMENT );
95  }
96 #endif
97 
98  StkFloat *samples = &frames[channel];
99  unsigned int hop = frames.channels();
100  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
101  *samples = Modulate::tick();
102 
103  return frames;
104 }
105 
106 } // stk namespace
107 
108 #endif
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
StkFloat tick(void)
Compute and return one output sample.
Definition: Noise.h:59
void setVibratoRate(StkFloat rate)
Set the periodic (vibrato) rate or frequency in Hz.
Definition: Modulate.h:39
STK sinusoid oscillator class.
Definition: SineWave.h:25
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:377
void setFrequency(StkFloat frequency)
Set the data interpolation rate based on a looping frequency.
void setVibratoGain(StkFloat gain)
Set the periodic (vibrato) gain.
Definition: Modulate.h:42
~Modulate(void)
Class destructor.
void reset(void)
Reset internal state.
Definition: Modulate.h:36
The STK namespace.
Definition: ADSR.h:6
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: OnePole.h:80
StkFloat tick(void)
Compute and return one output sample.
Definition: SineWave.h:99
StkFloat tick(void)
Compute and return one output sample.
Definition: Modulate.h:77
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:380
STK one-pole filter class.
Definition: OnePole.h:20
Modulate(void)
Class constructor.
STK periodic/random modulator.
Definition: Modulate.h:23
void setRandomGain(StkFloat gain)
Set the random modulation gain.
STK abstract unit generator parent class.
Definition: Generator.h:20
StkFloat lastOut(void) const
Return the last computed output value.
Definition: Modulate.h:48
An STK class to handle vectorized audio data.
Definition: Stk.h:272
StkFloat lastOut(void) const
Return the last computed output value.
Definition: Noise.h:40
STK noise generator.
Definition: Noise.h:21

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