Arduino STK 4.6.2
Simple.h
1#ifndef STK_SIMPLE_H
2#define STK_SIMPLE_H
3
4#include "Instrmnt.h"
5#include "ADSR.h"
6#ifdef __RAW_ARRAYS__
7# include "MemoryLoop.h"
8#else
9# include "FileLoop.h"
10#endif
11#include "OnePole.h"
12#include "BiQuad.h"
13#include "Noise.h"
14
15namespace stk {
16
17/***************************************************/
34/***************************************************/
35
36class Simple : public Instrmnt
37{
38 public:
40
43 Simple( void );
44
46 ~Simple( void );
47
49 void setFrequency( StkFloat frequency );
50
52 void keyOn( void );
53
55 void keyOff( void );
56
58 void noteOn( StkFloat frequency, StkFloat amplitude );
59
61 void noteOff( StkFloat amplitude );
62
64 void controlChange( int number, StkFloat value );
65
67 StkFloat tick( unsigned int channel = 0 );
68
70
77 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
78
79 protected:
80
81 ADSR adsr_;
82 FileLoop *loop_;
83 OnePole filter_;
84 BiQuad biquad_;
85 Noise noise_;
86 StkFloat baseFrequency_;
87 StkFloat loopGain_;
88
89};
90
91inline StkFloat Simple :: tick( unsigned int )
92{
93 lastFrame_[0] = loopGain_ * loop_->tick();
94 biquad_.tick( noise_.tick() );
95 lastFrame_[0] += (1.0f - loopGain_) * biquad_.lastOut();
96 lastFrame_[0] = filter_.tick( lastFrame_[0] );
97 lastFrame_[0] *= adsr_.tick();
98 return lastFrame_[0];
99}
100
101inline StkFrames& Simple :: tick( StkFrames& frames, unsigned int channel )
102{
103 unsigned int nChannels = lastFrame_.channels();
104#if defined(_STK_DEBUG_)
105 if ( channel > frames.channels() - nChannels ) {
106 oStream_ << "Simple::tick(): channel and StkFrames arguments are incompatible!";
107 handleError( StkError::FUNCTION_ARGUMENT );
108 }
109#endif
110
111 StkFloat *samples = &frames[channel];
112 unsigned int j, hop = frames.channels() - nChannels;
113 if ( nChannels == 1 ) {
114 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
115 *samples++ = tick();
116 }
117 else {
118 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
119 *samples++ = tick();
120 for ( j=1; j<nChannels; j++ )
121 *samples++ = lastFrame_[j];
122 }
123 }
124
125 return frames;
126}
127
128} // stk namespace
129
130#endif
STK ADSR envelope class.
Definition ADSR.h:27
STK biquad (two-pole, two-zero) filter class.
Definition BiQuad.h:21
STK file looping / oscillator class.
Definition FileLoop.h:27
Instrmnt(void)
Class constructor.
Definition Instrmnt.h:23
STK noise generator.
Definition Noise.h:22
StkFloat tick(void)
Compute and return one output sample.
Definition Noise.h:59
STK one-pole filter class.
Definition OnePole.h:21
void keyOff(void)
Start envelope toward "off" target.
void keyOn(void)
Start envelope toward "on" target.
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
Simple(void)
Class constructor.
~Simple(void)
Class destructor.
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition Simple.h:91
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
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