The Synthesis ToolKit in C++ (STK)

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
9namespace 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 setRandomRate( StkFloat rate ) { noiseRate_ = (unsigned int) ( rate * Stk::sampleRate() / 22050.0 ); };
46
48 void setRandomGain( StkFloat gain );
49
51 StkFloat lastOut( void ) const { return lastFrame_[0]; };
52
54 StkFloat tick( void );
55
57
64 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
65
66 protected:
67
68 void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
69
70 SineWave vibrato_;
71 Noise noise_;
72 OnePole filter_;
73 StkFloat vibratoGain_;
74 StkFloat randomGain_;
75 unsigned int noiseRate_;
76 unsigned int noiseCounter_;
77
78};
79
80 inline StkFloat Modulate :: tick( void )
81{
82 // Compute periodic and random modulations.
83 lastFrame_[0] = vibratoGain_ * vibrato_.tick();
84 if ( noiseCounter_++ >= noiseRate_ ) {
85 noise_.tick();
86 noiseCounter_ = 0;
87 }
88 lastFrame_[0] += filter_.tick( noise_.lastOut() );
89 return lastFrame_[0];
90}
91
92 inline StkFrames& Modulate :: tick( StkFrames& frames, unsigned int channel )
93{
94#if defined(_STK_DEBUG_)
95 if ( channel >= frames.channels() ) {
96 oStream_ << "Modulate::tick(): channel and StkFrames arguments are incompatible!";
97 handleError( StkError::FUNCTION_ARGUMENT );
98 }
99#endif
100
101 StkFloat *samples = &frames[channel];
102 unsigned int hop = frames.channels();
103 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
104 *samples = Modulate::tick();
105
106 return frames;
107}
108
109} // stk namespace
110
111#endif
stk::Generator
STK abstract unit generator parent class.
Definition: Generator.h:21
stk::Modulate
STK periodic/random modulator.
Definition: Modulate.h:24
stk::Modulate::setVibratoGain
void setVibratoGain(StkFloat gain)
Set the periodic (vibrato) gain.
Definition: Modulate.h:42
stk::Modulate::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: Modulate.h:80
stk::Modulate::setVibratoRate
void setVibratoRate(StkFloat rate)
Set the periodic (vibrato) rate or frequency in Hz.
Definition: Modulate.h:39
stk::Modulate::reset
void reset(void)
Reset internal state.
Definition: Modulate.h:36
stk::Modulate::setRandomRate
void setRandomRate(StkFloat rate)
Set the periodic (vibrato) rate or frequency in Hz.
Definition: Modulate.h:45
stk::Modulate::Modulate
Modulate(void)
Class constructor.
stk::Modulate::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition: Modulate.h:51
stk::Modulate::setRandomGain
void setRandomGain(StkFloat gain)
Set the random modulation gain.
stk::Modulate::~Modulate
~Modulate(void)
Class destructor.
stk::Noise
STK noise generator.
Definition: Noise.h:22
stk::OnePole
STK one-pole filter class.
Definition: OnePole.h:21
stk::OnePole::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: OnePole.h:80
stk::SineWave
STK sinusoid oscillator class.
Definition: SineWave.h:26
stk::SineWave::setFrequency
void setFrequency(StkFloat frequency)
Set the data interpolation rate based on a looping frequency.
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::Stk::sampleRate
static StkFloat sampleRate(void)
Static method that returns the current STK sample rate.
Definition: Stk.h:148
stk
The STK namespace.
Definition: ADSR.h:6

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