Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Brass.h
1#ifndef STK_BRASS_H
2#define STK_BRASS_H
3
4#include "Instrmnt.h"
5#include "DelayA.h"
6#include "BiQuad.h"
7#include "PoleZero.h"
8#include "ADSR.h"
9#include "SineWave.h"
10
11 namespace stk {
12
13/***************************************************/
33/***************************************************/
34
35 class Brass: public Instrmnt
36{
37 public:
39
42 Brass( StkFloat lowestFrequency = 8.0 );
43
45 ~Brass( );
46
48 void clear( );
49
51 void setFrequency( StkFloat frequency );
52
54 void setLip( 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 DelayA delayLine_;
87 BiQuad lipFilter_;
88 PoleZero dcBlock_;
89 ADSR adsr_;
90 SineWave vibrato_;
91
92 StkFloat lipTarget_;
93 StkFloat slideTarget_;
94 StkFloat vibratoGain_;
95 StkFloat maxPressure_;
96
97};
98
99 inline StkFloat Brass :: tick( unsigned int )
100{
101 StkFloat breathPressure = maxPressure_ * adsr_.tick();
102 breathPressure += vibratoGain_ * vibrato_.tick();
103
104 StkFloat mouthPressure = 0.3 * breathPressure;
105 StkFloat borePressure = 0.85 * delayLine_.lastOut();
106 StkFloat deltaPressure = mouthPressure - borePressure; // Differential pressure.
107 deltaPressure = lipFilter_.tick( deltaPressure ); // Force - > position.
108 deltaPressure *= deltaPressure; // Basic position to area mapping.
109 if ( deltaPressure > 1.0 ) deltaPressure = 1.0; // Non-linear saturation.
110
111 // The following input scattering assumes the mouthPressure = area.
112 lastFrame_[0] = deltaPressure * mouthPressure + ( 1.0 - deltaPressure) * borePressure;
113 lastFrame_[0] = delayLine_.tick( dcBlock_.tick( lastFrame_[0] ) );
114
115 return lastFrame_[0];
116}
117
118 inline StkFrames& Brass :: tick( StkFrames& frames, unsigned int channel )
119{
120 unsigned int nChannels = lastFrame_.channels();
121#if defined(_STK_DEBUG_)
122 if ( channel > frames.channels() - nChannels ) {
123 oStream_ << "Brass::tick(): channel and StkFrames arguments are incompatible!";
124 handleError( StkError::FUNCTION_ARGUMENT );
125 }
126#endif
127
128 StkFloat *samples = &frames[channel];
129 unsigned int j, hop = frames.channels() - nChannels;
130 if ( nChannels == 1 ) {
131 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
132 *samples++ = tick();
133 }
134 else {
135 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
136 *samples++ = tick();
137 for ( j=1; j<nChannels; j++ )
138 *samples++ = lastFrame_[j];
139 }
140 }
141
142 return frames;
143}
144
145} // stk namespace
146
147#endif
stk::ADSR
STK ADSR envelope class.
Definition ADSR.h:25
stk::BiQuad
STK biquad (two-pole, two-zero) filter class.
Definition BiQuad.h:26
stk::Brass::startBlowing
void startBlowing(StkFloat amplitude, StkFloat rate)
Apply breath pressure to instrument with given amplitude and rate of increase.
stk::Brass::setLip
void setLip(StkFloat frequency)
Set the lips frequency.
stk::Brass::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
stk::Brass::~Brass
~Brass()
Class destructor.
stk::Brass::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition Brass.h:99
stk::Brass::controlChange
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
stk::Brass::Brass
Brass(StkFloat lowestFrequency=8.0)
Class constructor, taking the lowest desired playing frequency.
stk::Brass::setFrequency
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk::Brass::clear
void clear()
Reset and clear all internal state.
stk::Brass::stopBlowing
void stopBlowing(StkFloat rate)
Decrease breath pressure with given rate of decrease.
stk::Brass::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
stk::DelayA
STK allpass interpolating delay line class.
Definition DelayA.h:29
stk::Instrmnt::Instrmnt
Instrmnt(void)
Class constructor.
Definition Instrmnt.h:23
stk::PoleZero
STK one-pole, one-zero filter class.
Definition PoleZero.h:22
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::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
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.