The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Envelope.h
1 #ifndef STK_ENVELOPE_H
2 #define STK_ENVELOPE_H
3
4 #include "Generator.h"
5
6 namespace stk {
7
8 /***************************************************/
19 /***************************************************/
20
21 class Envelope : public Generator
22 {
23 public:
24
26 Envelope( void );
27
29 ~Envelope( void );
30
32 Envelope& operator= ( const Envelope& e );
33
35 void keyOn( void ) { this->setTarget( 1.0 ); };
36
38 void keyOff( void ) { this->setTarget( 0.0 ); };
39
41
44 void setRate( StkFloat rate );
45
47
51 void setTime( StkFloat time );
52
54 void setTarget( StkFloat target );
55
57 void setValue( StkFloat value );
58
60 int getState( void ) const { return state_; };
61
63 StkFloat lastOut( void ) const { return lastFrame_[0]; };
64
66 StkFloat tick( void );
67
69
76 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
77
78 protected:
79
80 void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
81
82 StkFloat value_;
83 StkFloat target_;
84 StkFloat rate_;
85 int state_;
86 };
87
88 inline StkFloat Envelope :: tick( void )
89 {
90 if ( state_ ) {
91 if ( target_ > value_ ) {
92 value_ += rate_;
93 if ( value_ >= target_ ) {
94 value_ = target_;
95 state_ = 0;
96 }
97 }
98 else {
99 value_ -= rate_;
100 if ( value_ <= target_ ) {
101 value_ = target_;
102 state_ = 0;
103 }
104 }
105 lastFrame_[0] = value_;
106 }
107
108 return value_;
109 }
110
111 inline StkFrames& Envelope :: tick( StkFrames& frames, unsigned int channel )
112 {
113 #if defined(_STK_DEBUG_)
114 if ( channel >= frames.channels() ) {
115 oStream_ << "Envelope::tick(): channel and StkFrames arguments are incompatible!";
116 handleError( StkError::FUNCTION_ARGUMENT );
117 }
118 #endif
119
120 StkFloat *samples = &frames[channel];
121 unsigned int hop = frames.channels();
122 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
123 *samples = tick();
124
125 return frames;
126 }
127
128 } // stk namespace
129
130 #endif
stk::Envelope::setTarget
void setTarget(StkFloat target)
Set the target value.
stk::Envelope::Envelope
Envelope(void)
Default constructor.
stk::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:407
stk::Envelope::operator=
Envelope & operator=(const Envelope &e)
Assignment operator.
stk::Envelope::setTime
void setTime(StkFloat time)
Set the rate based on a positive time duration (seconds).
stk::Envelope::setRate
void setRate(StkFloat rate)
Set the rate.
stk
The STK namespace.
Definition: ADSR.h:6
stk::Envelope
STK linear line envelope class.
Definition: Envelope.h:21
stk::Envelope::~Envelope
~Envelope(void)
Class destructor.
stk::Envelope::getState
int getState(void) const
Return the current envelope state (0 = at target, 1 otherwise).
Definition: Envelope.h:60
stk::Envelope::setValue
void setValue(StkFloat value)
Set current and target values to value.
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:404
stk::Generator
STK abstract unit generator parent class.
Definition: Generator.h:20
stk::StkFrames
An STK class to handle vectorized audio data.
Definition: Stk.h:275
stk::Envelope::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: Envelope.h:88
stk::Envelope::keyOff
void keyOff(void)
Set target = 0.
Definition: Envelope.h:38
stk::Envelope::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition: Envelope.h:63
stk::Envelope::keyOn
void keyOn(void)
Set target = 1.
Definition: Envelope.h:35

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