The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Flute.h
1 #ifndef STK_FLUTE_H
2 #define STK_FLUTE_H
3
4 #include "Instrmnt.h"
5 #include "JetTable.h"
6 #include "DelayL.h"
7 #include "OnePole.h"
8 #include "PoleZero.h"
9 #include "Noise.h"
10 #include "ADSR.h"
11 #include "SineWave.h"
12
13 namespace stk {
14
15 /***************************************************/
37 /***************************************************/
38
39 class Flute : public Instrmnt
40 {
41 public:
43
46 Flute( StkFloat lowestFrequency );
47
49 ~Flute( void );
50
52 void clear( void );
53
55 void setFrequency( StkFloat frequency );
56
58 void setJetReflection( StkFloat coefficient ) { jetReflection_ = coefficient; };
59
61 void setEndReflection( StkFloat coefficient ) { endReflection_ = coefficient; };
62
64 void setJetDelay( StkFloat aRatio );
65
67 void startBlowing( StkFloat amplitude, StkFloat rate );
68
70 void stopBlowing( StkFloat rate );
71
73 void noteOn( StkFloat frequency, StkFloat amplitude );
74
76 void noteOff( StkFloat amplitude );
77
79 void controlChange( int number, StkFloat value );
80
82 StkFloat tick( unsigned int channel = 0 );
83
85
92 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
93
94 protected:
95
96 DelayL jetDelay_;
97 DelayL boreDelay_;
98 JetTable jetTable_;
99 OnePole filter_;
100 PoleZero dcBlock_;
101 Noise noise_;
102 ADSR adsr_;
103 SineWave vibrato_;
104
105 StkFloat lastFrequency_;
106 StkFloat maxPressure_;
107 StkFloat jetReflection_;
108 StkFloat endReflection_;
109 StkFloat noiseGain_;
110 StkFloat vibratoGain_;
111 StkFloat outputGain_;
112 StkFloat jetRatio_;
113
114 };
115
116 inline StkFloat Flute :: tick( unsigned int )
117 {
118 StkFloat pressureDiff;
119 StkFloat breathPressure;
120
121 // Calculate the breath pressure (envelope + noise + vibrato)
122 breathPressure = maxPressure_ * adsr_.tick();
123 breathPressure += breathPressure * ( noiseGain_ * noise_.tick() + vibratoGain_ * vibrato_.tick() );
124
125 StkFloat temp = -filter_.tick( boreDelay_.lastOut() );
126 temp = dcBlock_.tick( temp ); // Block DC on reflection.
127
128 pressureDiff = breathPressure - (jetReflection_ * temp);
129 pressureDiff = jetDelay_.tick( pressureDiff );
130 pressureDiff = jetTable_.tick( pressureDiff ) + (endReflection_ * temp);
131 lastFrame_[0] = (StkFloat) 0.3 * boreDelay_.tick( pressureDiff );
132
133 lastFrame_[0] *= outputGain_;
134 return lastFrame_[0];
135 }
136
137 inline StkFrames& Flute :: tick( StkFrames& frames, unsigned int channel )
138 {
139 unsigned int nChannels = lastFrame_.channels();
140 #if defined(_STK_DEBUG_)
141 if ( channel > frames.channels() - nChannels ) {
142 oStream_ << "Flute::tick(): channel and StkFrames arguments are incompatible!";
143 handleError( StkError::FUNCTION_ARGUMENT );
144 }
145 #endif
146
147 StkFloat *samples = &frames[channel];
148 unsigned int j, hop = frames.channels() - nChannels;
149 if ( nChannels == 1 ) {
150 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
151 *samples++ = tick();
152 }
153 else {
154 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
155 *samples++ = tick();
156 for ( j=1; j<nChannels; j++ )
157 *samples++ = lastFrame_[j];
158 }
159 }
160
161 return frames;
162 }
163
164 } // stk namespace
165
166 #endif
stk::OnePole
STK one-pole filter class.
Definition: OnePole.h:20
stk::JetTable
STK jet table class.
Definition: JetTable.h:23
stk::ADSR
STK ADSR envelope class.
Definition: ADSR.h:24
stk::SineWave
STK sinusoid oscillator class.
Definition: SineWave.h:25
stk::Flute::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
stk::Flute::~Flute
~Flute(void)
Class destructor.
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:407
stk::Flute::setFrequency
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk::Noise::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: Noise.h:59
stk::OnePole::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: OnePole.h:80
stk::DelayL
STK linear interpolating delay line class.
Definition: DelayL.h:27
stk::Flute::Flute
Flute(StkFloat lowestFrequency)
Class constructor, taking the lowest desired playing frequency.
stk::DelayL::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition: DelayL.h:76
stk::StkFrames
An STK class to handle vectorized audio data.
Definition: Stk.h:275
stk::Flute::stopBlowing
void stopBlowing(StkFloat rate)
Decrease breath velocity with given rate of decrease.
stk::SineWave::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: SineWave.h:99
stk::JetTable::tick
StkFloat tick(StkFloat input)
Take one sample input and map to one sample of output.
Definition: JetTable.h:54
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:404
stk::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
stk::PoleZero::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: PoleZero.h:79
stk::Flute
STK flute physical model class.
Definition: Flute.h:39
stk::Flute::setJetDelay
void setJetDelay(StkFloat aRatio)
Set the length of the jet delay in terms of a ratio of jet delay to air column delay lengths.
stk::Flute::startBlowing
void startBlowing(StkFloat amplitude, StkFloat rate)
Apply breath velocity to instrument with given amplitude and rate of increase.
stk::Flute::setEndReflection
void setEndReflection(StkFloat coefficient)
Set the reflection coefficient for the air column delay (-1.0 - 1.0).
Definition: Flute.h:61
stk::Flute::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
stk::Flute::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition: Flute.h:116
stk::DelayL::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: DelayL.h:163
stk::Noise
STK noise generator.
Definition: Noise.h:21
stk
The STK namespace.
Definition: ADSR.h:6
stk::PoleZero
STK one-pole, one-zero filter class.
Definition: PoleZero.h:21
stk::ADSR::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: ADSR.h:115
stk::Instrmnt
STK instrument abstract base class.
Definition: Instrmnt.h:19
stk::Flute::setJetReflection
void setJetReflection(StkFloat coefficient)
Set the reflection coefficient for the jet delay (-1.0 - 1.0).
Definition: Flute.h:58
stk::Flute::controlChange
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
stk::Flute::clear
void clear(void)
Reset and clear all internal state.

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