The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

BlowBotl.h
1 #ifndef STK_BLOWBOTL_H
2 #define STK_BLOWBOTL_H
3
4 #include "Instrmnt.h"
5 #include "JetTable.h"
6 #include "BiQuad.h"
7 #include "PoleZero.h"
8 #include "Noise.h"
9 #include "ADSR.h"
10 #include "SineWave.h"
11
12 namespace stk {
13
14 /***************************************************/
30 /***************************************************/
31
32 class BlowBotl : public Instrmnt
33 {
34 public:
36
39 BlowBotl( void );
40
42 ~BlowBotl( void );
43
45 void clear( void );
46
48 void setFrequency( StkFloat frequency );
49
51 void startBlowing( StkFloat amplitude, StkFloat rate );
52
54 void stopBlowing( StkFloat rate );
55
57 void noteOn( StkFloat frequency, StkFloat amplitude );
58
60 void noteOff( StkFloat amplitude );
61
63 void controlChange( int number, StkFloat value );
64
66 StkFloat tick( unsigned int channel = 0 );
67
69
76 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
77
78 protected:
79
80 JetTable jetTable_;
81 BiQuad resonator_;
82 PoleZero dcBlock_;
83 Noise noise_;
84 ADSR adsr_;
85 SineWave vibrato_;
86 StkFloat maxPressure_;
87 StkFloat noiseGain_;
88 StkFloat vibratoGain_;
89 StkFloat outputGain_;
90
91 };
92
93 inline StkFloat BlowBotl :: tick( unsigned int )
94 {
95 StkFloat breathPressure;
96 StkFloat randPressure;
97 StkFloat pressureDiff;
98
99 // Calculate the breath pressure (envelope + vibrato)
100 breathPressure = maxPressure_ * adsr_.tick();
101 breathPressure += vibratoGain_ * vibrato_.tick();
102
103 pressureDiff = breathPressure - resonator_.lastOut();
104
105 randPressure = noiseGain_ * noise_.tick();
106 randPressure *= breathPressure;
107 randPressure *= (1.0 + pressureDiff);
108
109 resonator_.tick( breathPressure + randPressure - ( jetTable_.tick( pressureDiff ) * pressureDiff ) );
110 lastFrame_[0] = 0.2 * outputGain_ * dcBlock_.tick( pressureDiff );
111
112 return lastFrame_[0];
113 }
114
115 inline StkFrames& BlowBotl :: tick( StkFrames& frames, unsigned int channel )
116 {
117 unsigned int nChannels = lastFrame_.channels();
118 #if defined(_STK_DEBUG_)
119 if ( channel > frames.channels() - nChannels ) {
120 oStream_ << "BlowBotl::tick(): channel and StkFrames arguments are incompatible!";
121 handleError( StkError::FUNCTION_ARGUMENT );
122 }
123 #endif
124
125 StkFloat *samples = &frames[channel];
126 unsigned int j, hop = frames.channels() - nChannels;
127 if ( nChannels == 1 ) {
128 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
129 *samples++ = tick();
130 }
131 else {
132 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
133 *samples++ = tick();
134 for ( j=1; j<nChannels; j++ )
135 *samples++ = lastFrame_[j];
136 }
137 }
138
139 return frames;
140 }
141
142 } // stk namespace
143
144 #endif
stk::BlowBotl::stopBlowing
void stopBlowing(StkFloat rate)
Decrease breath velocity with given rate of decrease.
stk::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
stk::JetTable
STK jet table class.
Definition: JetTable.h:23
stk::PoleZero::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: PoleZero.h:79
stk::Noise::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: Noise.h:59
stk::BiQuad::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition: BiQuad.h:87
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:407
stk::SineWave
STK sinusoid oscillator class.
Definition: SineWave.h:25
stk::BlowBotl::controlChange
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
stk::BlowBotl::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
stk
The STK namespace.
Definition: ADSR.h:6
stk::SineWave::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: SineWave.h:99
stk::BlowBotl::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
stk::BlowBotl::startBlowing
void startBlowing(StkFloat amplitude, StkFloat rate)
Apply breath velocity to instrument with given amplitude and rate of increase.
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:404
stk::BlowBotl
STK blown bottle instrument class.
Definition: BlowBotl.h:32
stk::BiQuad
STK biquad (two-pole, two-zero) filter class.
Definition: BiQuad.h:20
stk::JetTable::tick
StkFloat tick(StkFloat input)
Take one sample input and map to one sample of output.
Definition: JetTable.h:54
stk::ADSR
STK ADSR envelope class.
Definition: ADSR.h:24
stk::StkFrames
An STK class to handle vectorized audio data.
Definition: Stk.h:275
stk::BlowBotl::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition: BlowBotl.h:93
stk::PoleZero
STK one-pole, one-zero filter class.
Definition: PoleZero.h:21
stk::Instrmnt
STK instrument abstract base class.
Definition: Instrmnt.h:19
stk::ADSR::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: ADSR.h:115
stk::BlowBotl::setFrequency
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk::Noise
STK noise generator.
Definition: Noise.h:21
stk::BlowBotl::clear
void clear(void)
Reset and clear all internal state.
stk::BlowBotl::~BlowBotl
~BlowBotl(void)
Class destructor.
stk::BlowBotl::BlowBotl
BlowBotl(void)
Class constructor.
stk::BiQuad::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return a reference to one output.
Definition: BiQuad.h:119

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