The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

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

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