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::Clarinet
STK clarinet physical model class.
Definition Clarinet.h:39
stk::Clarinet::startBlowing
void startBlowing(StkFloat amplitude, StkFloat rate)
Apply breath pressure to instrument with given amplitude and rate of increase.
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::Clarinet::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
stk::Clarinet::~Clarinet
~Clarinet(void)
Class destructor.
stk::Clarinet::controlChange
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
stk::Clarinet::clear
void clear(void)
Reset and clear all internal state.
stk::Clarinet::Clarinet
Clarinet(StkFloat lowestFrequency=8.0)
Class constructor, taking the lowest desired playing frequency.
stk::Clarinet::stopBlowing
void stopBlowing(StkFloat rate)
Decrease breath pressure with given rate of decrease.
stk::Clarinet::setFrequency
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk::DelayL
STK linear interpolating delay line class.
Definition DelayL.h:28
stk::Envelope
STK linear line envelope class.
Definition Envelope.h:23
stk::Instrmnt
STK instrument abstract base class.
Definition Instrmnt.h:20
stk::Noise
STK noise generator.
Definition Noise.h:22
stk::OneZero
STK one-zero filter class.
Definition OneZero.h:21
stk::ReedTable
STK reed table class.
Definition ReedTable.h:28
stk::SineWave
STK sinusoid oscillator class.
Definition SineWave.h:26
stk::SineWave::tick
StkFloat tick(void)
Compute and return one output sample.
Definition SineWave.h:99
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.