Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


SingWave.h
1 #ifndef STK_SINGWAVE_H
2 #define STK_SINGWAVE_H
3 
4 #include "FileLoop.h"
5 #include "Modulate.h"
6 #include "Envelope.h"
7 
8 namespace stk {
9 
10 /***************************************************/
23 /***************************************************/
24 
25 class SingWave : public Generator
26 {
27  public:
29 
36  SingWave( std::string fileName, bool raw = false );
37 
39  ~SingWave( void );
40 
42  void reset( void ) { wave_.reset(); lastFrame_[0] = 0.0; };
43 
45  void normalize( void ) { wave_.normalize(); };
46 
48  void normalize( StkFloat peak ) { wave_.normalize( peak ); };
49 
51  void setFrequency( StkFloat frequency );
52 
54  void setVibratoRate( StkFloat rate ) { modulator_.setVibratoRate( rate ); };
55 
57  void setVibratoGain( StkFloat gain ) { modulator_.setVibratoGain( gain ); };
58 
60  void setRandomGain( StkFloat gain ) { modulator_.setRandomGain( gain ); };
61 
63  void setSweepRate( StkFloat rate ) { sweepRate_ = rate; };
64 
66  void setGainRate( StkFloat rate ) { envelope_.setRate( rate ); };
67 
69  void setGainTarget( StkFloat target ) { envelope_.setTarget( target ); };
70 
72  void noteOn( void ) { envelope_.keyOn(); };
73 
75  void noteOff( void ) { envelope_.keyOff(); };
76 
78  StkFloat lastOut( void ) const { return lastFrame_[0]; };
79 
81  StkFloat tick( void );
82 
84 
91  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
92 
93  protected:
94 
95  FileLoop wave_;
96  Modulate modulator_;
97  Envelope envelope_;
98  Envelope pitchEnvelope_;
99  StkFloat rate_;
100  StkFloat sweepRate_;
101 
102 };
103 
104 inline StkFloat SingWave :: tick( void )
105 {
106  // Set the wave rate.
107  StkFloat newRate = pitchEnvelope_.tick();
108  newRate += newRate * modulator_.tick();
109  wave_.setRate( newRate );
110 
111  lastFrame_[0] = wave_.tick();
112  lastFrame_[0] *= envelope_.tick();
113 
114  return lastFrame_[0];
115 }
116 
117 inline StkFrames& SingWave :: tick( StkFrames& frames, unsigned int channel )
118 {
119 #if defined(_STK_DEBUG_)
120  if ( channel >= frames.channels() ) {
121  oStream_ << "SingWave::tick(): channel and StkFrames arguments are incompatible!";
122  handleError( StkError::FUNCTION_ARGUMENT );
123  }
124 #endif
125 
126  StkFloat *samples = &frames[channel];
127  unsigned int hop = frames.channels();
128  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
129  *samples = SingWave::tick();
130 
131  return frames;
132 }
133 
134 } // stk namespace
135 
136 #endif
stk::SingWave::setSweepRate
void setSweepRate(StkFloat rate)
Set the sweep rate.
Definition: SingWave.h:63
stk::FileLoop::setRate
void setRate(StkFloat rate)
Set the data read rate in samples. The rate can be negative.
stk::SingWave::setFrequency
void setFrequency(StkFloat frequency)
Set looping parameters for a particular frequency.
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:407
stk::SingWave::~SingWave
~SingWave(void)
Class destructor.
stk::SingWave::noteOn
void noteOn(void)
Start a note.
Definition: SingWave.h:72
stk::Generator
STK abstract unit generator parent class.
Definition: Generator.h:21
stk::SingWave::reset
void reset(void)
Reset file to beginning.
Definition: SingWave.h:42
stk::FileLoop::tick
StkFloat tick(unsigned int channel=0)
Compute a sample frame and return the specified channel value.
stk::SingWave::setVibratoGain
void setVibratoGain(StkFloat gain)
Set the vibrato gain.
Definition: SingWave.h:57
stk::SingWave::noteOff
void noteOff(void)
Stop a note.
Definition: SingWave.h:75
stk::Modulate::setRandomGain
void setRandomGain(StkFloat gain)
Set the random modulation gain.
stk::StkFrames
An STK class to handle vectorized audio data.
Definition: Stk.h:276
stk::FileLoop::reset
void reset(void)
Clear outputs and reset time (file) pointer to zero.
Definition: FileLoop.h:57
stk::SingWave::normalize
void normalize(void)
Normalize the file to a maximum of +-1.0.
Definition: SingWave.h:45
stk::SingWave::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: SingWave.h:104
stk::SingWave::setRandomGain
void setRandomGain(StkFloat gain)
Set the random-ness amount.
Definition: SingWave.h:60
stk::Envelope::keyOn
void keyOn(void)
Set target = 1.
Definition: Envelope.h:35
stk::Envelope
STK linear line envelope class.
Definition: Envelope.h:22
stk::Envelope::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: Envelope.h:88
stk::SingWave
STK "singing" looped soundfile class.
Definition: SingWave.h:26
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:404
stk::SingWave::SingWave
SingWave(std::string fileName, bool raw=false)
Class constructor taking filename argument.
stk::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
stk::SingWave::setVibratoRate
void setVibratoRate(StkFloat rate)
Set the vibrato frequency in Hz.
Definition: SingWave.h:54
stk::Envelope::setTarget
void setTarget(StkFloat target)
Set the target value.
stk::FileLoop
STK file looping / oscillator class.
Definition: FileLoop.h:27
stk::Envelope::setRate
void setRate(StkFloat rate)
Set the rate.
stk::SingWave::setGainRate
void setGainRate(StkFloat rate)
Set the gain rate.
Definition: SingWave.h:66
stk::SingWave::normalize
void normalize(StkFloat peak)
Normalize the file to a maximum of +- peak.
Definition: SingWave.h:48
stk::Modulate::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: Modulate.h:80
stk::SingWave::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition: SingWave.h:78
stk::FileLoop::normalize
void normalize(void)
Normalize data to a maximum of +-1.0.
Definition: FileLoop.h:67
stk::Envelope::keyOff
void keyOff(void)
Set target = 0.
Definition: Envelope.h:38
stk::Modulate::setVibratoRate
void setVibratoRate(StkFloat rate)
Set the periodic (vibrato) rate or frequency in Hz.
Definition: Modulate.h:39
stk::Modulate::setVibratoGain
void setVibratoGain(StkFloat gain)
Set the periodic (vibrato) gain.
Definition: Modulate.h:42
stk::Modulate
STK periodic/random modulator.
Definition: Modulate.h:24
stk
The STK namespace.
Definition: ADSR.h:6
stk::SingWave::setGainTarget
void setGainTarget(StkFloat target)
Set the gain target value.
Definition: SingWave.h:69

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