Arduino STK 4.6.2
SingWave.h
1#ifndef STK_SINGWAVE_H
2#define STK_SINGWAVE_H
3
4#include "ArdConfig.h"
5#ifdef __RAW_ARRAYS__
6# include "MemoryLoop.h"
7#else
8# include "FileLoop.h"
9#endif
10#include "Modulate.h"
11#include "Envelope.h"
12
13namespace stk {
14
15/***************************************************/
28/***************************************************/
29
30class SingWave : public Generator
31{
32 public:
34
41 SingWave( std::string fileName, bool raw = false );
42
44 ~SingWave( void );
45
47 void reset( void ) { wave_.reset(); lastFrame_[0] = 0.0; };
48
50 void normalize( void ) { wave_.normalize(); };
51
53 void normalize( StkFloat peak ) { wave_.normalize( peak ); };
54
56 void setFrequency( StkFloat frequency );
57
59 void setVibratoRate( StkFloat rate ) { modulator_.setVibratoRate( rate ); };
60
62 void setVibratoGain( StkFloat gain ) { modulator_.setVibratoGain( gain ); };
63
65 void setRandomGain( StkFloat gain ) { modulator_.setRandomGain( gain ); };
66
68 void setSweepRate( StkFloat rate ) { sweepRate_ = rate; };
69
71 void setGainRate( StkFloat rate ) { envelope_.setRate( rate ); };
72
74 void setGainTarget( StkFloat target ) { envelope_.setTarget( target ); };
75
77 void noteOn( void ) { envelope_.keyOn(); };
78
80 void noteOff( void ) { envelope_.keyOff(); };
81
83 StkFloat lastOut( void ) const { return lastFrame_[0]; };
84
86 StkFloat tick( void );
87
89
96 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
97
98 protected:
99#ifdef __RAW_ARRAYS__
100 MemoryLoop wave_;
101#else
102 FileLoop wave_;
103#endif
104 Modulate modulator_;
105 Envelope envelope_;
106 Envelope pitchEnvelope_;
107 StkFloat rate_;
108 StkFloat sweepRate_;
109
110};
111
112inline StkFloat SingWave :: tick( void )
113{
114 // Set the wave rate.
115 StkFloat newRate = pitchEnvelope_.tick();
116 newRate += newRate * modulator_.tick();
117 wave_.setRate( newRate );
118
119 lastFrame_[0] = wave_.tick();
120 lastFrame_[0] *= envelope_.tick();
121
122 return lastFrame_[0];
123}
124
125inline StkFrames& SingWave :: tick( StkFrames& frames, unsigned int channel )
126{
127#if defined(_STK_DEBUG_)
128 if ( channel >= frames.channels() ) {
129 oStream_ << "SingWave::tick(): channel and StkFrames arguments are incompatible!";
130 handleError( StkError::FUNCTION_ARGUMENT );
131 }
132#endif
133
134 StkFloat *samples = &frames[channel];
135 unsigned int hop = frames.channels();
136 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
137 *samples = SingWave::tick();
138
139 return frames;
140}
141
142} // stk namespace
143
144#endif
STK linear line envelope class.
Definition Envelope.h:22
StkFloat tick(void)
Compute and return one output sample.
Definition Envelope.h:88
STK file looping / oscillator class.
Definition FileLoop.h:27
Generator(void)
Class constructor.
Definition Generator.h:25
STK looping / oscillator class using a simple memory array as input.
Definition MemoryLoop.h:29
STK periodic/random modulator.
Definition Modulate.h:24
~SingWave(void)
Class destructor.
void setRandomGain(StkFloat gain)
Set the random-ness amount.
Definition SingWave.h:65
StkFloat tick(void)
Compute and return one output sample.
Definition SingWave.h:112
void setVibratoGain(StkFloat gain)
Set the vibrato gain.
Definition SingWave.h:62
SingWave(std::string fileName, bool raw=false)
Class constructor taking filename argument.
void setGainRate(StkFloat rate)
Set the gain rate.
Definition SingWave.h:71
void reset(void)
Reset file to beginning.
Definition SingWave.h:47
void setVibratoRate(StkFloat rate)
Set the vibrato frequency in Hz.
Definition SingWave.h:59
void noteOn(void)
Start a note.
Definition SingWave.h:77
void setSweepRate(StkFloat rate)
Set the sweep rate.
Definition SingWave.h:68
StkFloat lastOut(void) const
Return the last computed output value.
Definition SingWave.h:83
void setGainTarget(StkFloat target)
Set the gain target value.
Definition SingWave.h:74
void noteOff(void)
Stop a note.
Definition SingWave.h:80
void setFrequency(StkFloat frequency)
Set looping parameters for a particular frequency.
void normalize(void)
Normalize the file to a maximum of +-1.0.
Definition SingWave.h:50
void normalize(StkFloat peak)
Normalize the file to a maximum of +- peak.
Definition SingWave.h:53
An STK class to handle vectorized audio data.
Definition Stk.h:287
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:415
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:418
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
The STK namespace.
Definition ADSR.h:8