The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Clarinet.h
1 #ifndef STK_CLARINET_H
2 #define STK_CLARINET_H
3
4 #include "Instrmnt.h"
5 #include "DelayL.h"
6 #include "ReedTable.h"
7 #include "OneZero.h"
8 #include "Envelope.h"
9 #include "Noise.h"
10 #include "SineWave.h"
11
12 namespace stk {
13
14 /***************************************************/
36 /***************************************************/
37
38 class Clarinet : public Instrmnt
39 {
40 public:
42
45 Clarinet( StkFloat lowestFrequency = 8.0 );
46
48 ~Clarinet( void );
49
51 void clear( void );
52
54 void setFrequency( StkFloat frequency );
55
57 void startBlowing( StkFloat amplitude, StkFloat rate );
58
60 void stopBlowing( StkFloat rate );
61
63 void noteOn( StkFloat frequency, StkFloat amplitude );
64
66 void noteOff( StkFloat amplitude );
67
69 void controlChange( int number, StkFloat value );
70
72 StkFloat tick( unsigned int channel = 0 );
73
75
82 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
83
84 protected:
85
86 DelayL delayLine_;
87 ReedTable reedTable_;
88 OneZero filter_;
89 Envelope envelope_;
90 Noise noise_;
91 SineWave vibrato_;
92
93 StkFloat outputGain_;
94 StkFloat noiseGain_;
95 StkFloat vibratoGain_;
96 };
97
98 inline StkFloat Clarinet :: tick( unsigned int )
99 {
100 StkFloat pressureDiff;
101 StkFloat breathPressure;
102
103 // Calculate the breath pressure (envelope + noise + vibrato)
104 breathPressure = envelope_.tick();
105 breathPressure += breathPressure * noiseGain_ * noise_.tick();
106 breathPressure += breathPressure * vibratoGain_ * vibrato_.tick();
107
108 // Perform commuted loss filtering.
109 pressureDiff = -0.95 * filter_.tick( delayLine_.lastOut() );
110
111 // Calculate pressure difference of reflected and mouthpiece pressures.
112 pressureDiff = pressureDiff - breathPressure;
113
114 // Perform non-linear scattering using pressure difference in reed function.
115 lastFrame_[0] = delayLine_.tick(breathPressure + pressureDiff * reedTable_.tick(pressureDiff));
116
117 // Apply output gain.
118 lastFrame_[0] *= outputGain_;
119
120 return lastFrame_[0];
121 }
122
123 inline StkFrames& Clarinet :: tick( StkFrames& frames, unsigned int channel )
124 {
125 unsigned int nChannels = lastFrame_.channels();
126 #if defined(_STK_DEBUG_)
127 if ( channel > frames.channels() - nChannels ) {
128 oStream_ << "Clarinet::tick(): channel and StkFrames arguments are incompatible!";
129 handleError( StkError::FUNCTION_ARGUMENT );
130 }
131 #endif
132
133 StkFloat *samples = &frames[channel];
134 unsigned int j, hop = frames.channels() - nChannels;
135 if ( nChannels == 1 ) {
136 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
137 *samples++ = tick();
138 }
139 else {
140 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
141 *samples++ = tick();
142 for ( j=1; j<nChannels; j++ )
143 *samples++ = lastFrame_[j];
144 }
145 }
146
147 return frames;
148 }
149
150 } // stk namespace
151
152 #endif
stk::SineWave
STK sinusoid oscillator class.
Definition: SineWave.h:26
stk::Clarinet::clear
void clear(void)
Reset and clear all internal state.
stk::Clarinet::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
stk::ReedTable
STK reed table class.
Definition: ReedTable.h:28
stk::Clarinet::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
stk::Clarinet::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition: Clarinet.h:98
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:407
stk::ReedTable::tick
StkFloat tick(StkFloat input)
Take one sample input and map to one sample of output.
Definition: ReedTable.h:81
stk::Noise::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: Noise.h:59
stk::DelayL
STK linear interpolating delay line class.
Definition: DelayL.h:28
stk::Clarinet::setFrequency
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk::Clarinet::Clarinet
Clarinet(StkFloat lowestFrequency=8.0)
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:276
stk::SineWave::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: SineWave.h:99
stk::Clarinet::stopBlowing
void stopBlowing(StkFloat rate)
Decrease breath pressure with given rate of decrease.
stk::OneZero::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: OneZero.h:79
stk::Envelope
STK linear line envelope class.
Definition: Envelope.h:22
stk::Envelope::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: Envelope.h:88
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::OneZero
STK one-zero filter class.
Definition: OneZero.h:21
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:22
stk::Clarinet::controlChange
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
stk
The STK namespace.
Definition: ADSR.h:6
stk::Clarinet::~Clarinet
~Clarinet(void)
Class destructor.
stk::Instrmnt
STK instrument abstract base class.
Definition: Instrmnt.h:20
stk::Clarinet::startBlowing
void startBlowing(StkFloat amplitude, StkFloat rate)
Apply breath pressure to instrument with given amplitude and rate of increase.
stk::Clarinet
STK clarinet physical model class.
Definition: Clarinet.h:39

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