The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Saxofony.h
1 #ifndef STK_SAXOFONY_H
2 #define STK_SAXOFONY_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 /***************************************************/
49 /***************************************************/
50
51 class Saxofony : public Instrmnt
52 {
53 public:
55
58 Saxofony( StkFloat lowestFrequency );
59
61 ~Saxofony( void );
62
64 void clear( void );
65
67 void setFrequency( StkFloat frequency );
68
70 void setBlowPosition( StkFloat aPosition );
71
73 void startBlowing( StkFloat amplitude, StkFloat rate );
74
76 void stopBlowing( StkFloat rate );
77
79 void noteOn( StkFloat frequency, StkFloat amplitude );
80
82 void noteOff( StkFloat amplitude );
83
85 void controlChange( int number, StkFloat value );
86
88 StkFloat tick( unsigned int channel = 0 );
89
91
98 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
99
100 protected:
101
102 DelayL delays_[2];
103 ReedTable reedTable_;
104 OneZero filter_;
105 Envelope envelope_;
106 Noise noise_;
107 SineWave vibrato_;
108
109 StkFloat outputGain_;
110 StkFloat noiseGain_;
111 StkFloat vibratoGain_;
112 StkFloat position_;
113
114 };
115
116 inline StkFloat Saxofony :: tick( unsigned int )
117 {
118 StkFloat pressureDiff;
119 StkFloat breathPressure;
120 StkFloat temp;
121
122 // Calculate the breath pressure (envelope + noise + vibrato)
123 breathPressure = envelope_.tick();
124 breathPressure += breathPressure * noiseGain_ * noise_.tick();
125 breathPressure += breathPressure * vibratoGain_ * vibrato_.tick();
126
127 temp = -0.95 * filter_.tick( delays_[0].lastOut() );
128 lastFrame_[0] = temp - delays_[1].lastOut();
129 pressureDiff = breathPressure - lastFrame_[0];
130 delays_[1].tick( temp );
131 delays_[0].tick( breathPressure - (pressureDiff * reedTable_.tick(pressureDiff)) - temp );
132
133 lastFrame_[0] *= outputGain_;
134 return lastFrame_[0];
135 }
136
137 inline StkFrames& Saxofony :: 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_ << "Saxofony::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::SineWave
STK sinusoid oscillator class.
Definition: SineWave.h:25
stk::Saxofony::Saxofony
Saxofony(StkFloat lowestFrequency)
Class constructor, taking the lowest desired playing frequency.
stk::ReedTable
STK reed table class.
Definition: ReedTable.h:27
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:407
stk::Saxofony::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
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:27
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::SineWave::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: SineWave.h:99
stk::Saxofony::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
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:21
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::Saxofony::~Saxofony
~Saxofony(void)
Class destructor.
stk::Saxofony::setFrequency
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk::Saxofony::controlChange
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
stk::OneZero
STK one-zero filter class.
Definition: OneZero.h:20
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::Saxofony::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition: Saxofony.h:116
stk
The STK namespace.
Definition: ADSR.h:6
stk::Saxofony::startBlowing
void startBlowing(StkFloat amplitude, StkFloat rate)
Apply breath pressure to instrument with given amplitude and rate of increase.
stk::Saxofony::stopBlowing
void stopBlowing(StkFloat rate)
Decrease breath pressure with given rate of decrease.
stk::Instrmnt
STK instrument abstract base class.
Definition: Instrmnt.h:19
stk::Instrmnt::lastOut
StkFloat lastOut(unsigned int channel=0)
Return the specified channel value of the last computed frame.
Definition: Instrmnt.h:88
stk::Saxofony::setBlowPosition
void setBlowPosition(StkFloat aPosition)
Set the "blowing" position between the air column terminations (0.0 - 1.0).
stk::Saxofony::clear
void clear(void)
Reset and clear all internal state.
stk::Saxofony
STK faux conical bore reed instrument class.
Definition: Saxofony.h:51

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