The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Modal.h
1#ifndef STK_MODAL_H
2#define STK_MODAL_H
3
4#include "Instrmnt.h"
5#include "Envelope.h"
6#include "FileLoop.h"
7#include "SineWave.h"
8#include "BiQuad.h"
9#include "OnePole.h"
10
11namespace stk {
12
13/***************************************************/
24/***************************************************/
25
26 class Modal : public Instrmnt
27{
28public:
30
33 Modal( unsigned int modes = 4 );
34
36 virtual ~Modal( void );
37
39 void clear( void );
40
42 virtual void setFrequency( StkFloat frequency );
43
45 void setRatioAndRadius( unsigned int modeIndex, StkFloat ratio, StkFloat radius );
46
48 void setMasterGain( StkFloat aGain ) { masterGain_ = aGain; };
49
51 void setDirectGain( StkFloat aGain ) { directGain_ = aGain; };
52
54 void setModeGain( unsigned int modeIndex, StkFloat gain );
55
57 virtual void strike( StkFloat amplitude );
58
60 void damp( StkFloat amplitude );
61
63 void noteOn( StkFloat frequency, StkFloat amplitude );
64
66 void noteOff( StkFloat amplitude );
67
69 virtual void controlChange( int number, StkFloat value ) = 0;
70
72 StkFloat tick( unsigned int channel = 0 );
73
75
82 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
83
84protected:
85
86 Envelope envelope_;
87 FileWvIn *wave_;
88 BiQuad **filters_;
89 OnePole onepole_;
90 SineWave vibrato_;
91
92 unsigned int nModes_;
93 std::vector<StkFloat> ratios_;
94 std::vector<StkFloat> radii_;
95
96 StkFloat vibratoGain_;
97 StkFloat masterGain_;
98 StkFloat directGain_;
99 StkFloat stickHardness_;
100 StkFloat strikePosition_;
101 StkFloat baseFrequency_;
102};
103
104 inline StkFloat Modal :: tick( unsigned int )
105{
106 StkFloat temp = masterGain_ * onepole_.tick( wave_->tick() * envelope_.tick() );
107
108 StkFloat temp2 = 0.0;
109 for ( unsigned int i=0; i<nModes_; i++ )
110 temp2 += filters_[i]->tick(temp);
111
112 temp2 -= temp2 * directGain_;
113 temp2 += directGain_ * temp;
114
115 if ( vibratoGain_ != 0.0 ) {
116 // Calculate AM and apply to master out
117 temp = 1.0 + ( vibrato_.tick() * vibratoGain_ );
118 temp2 = temp * temp2;
119 }
120
121 lastFrame_[0] = temp2;
122 return lastFrame_[0];
123}
124
125 inline StkFrames& Modal :: tick( StkFrames& frames, unsigned int channel )
126{
127 unsigned int nChannels = lastFrame_.channels();
128#if defined(_STK_DEBUG_)
129 if ( channel > frames.channels() - nChannels ) {
130 oStream_ << "Modal::tick(): channel and StkFrames arguments are incompatible!";
131 handleError( StkError::FUNCTION_ARGUMENT );
132 }
133#endif
134
135 StkFloat *samples = &frames[channel];
136 unsigned int j, hop = frames.channels() - nChannels;
137 if ( nChannels == 1 ) {
138 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
139 *samples++ = tick();
140 }
141 else {
142 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
143 *samples++ = tick();
144 for ( j=1; j<nChannels; j++ )
145 *samples++ = lastFrame_[j];
146 }
147 }
148
149 return frames;
150}
151
152} // stk namespace
153
154#endif
stk::BiQuad
STK biquad (two-pole, two-zero) filter class.
Definition: BiQuad.h:21
stk::Envelope
STK linear line envelope class.
Definition: Envelope.h:23
stk::Envelope::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: Envelope.h:89
stk::FileWvIn
STK audio file input class.
Definition: FileWvIn.h:53
stk::FileWvIn::tick
virtual StkFloat tick(unsigned int channel=0)
Compute a sample frame and return the specified channel value.
stk::Instrmnt
STK instrument abstract base class.
Definition: Instrmnt.h:20
stk::Modal
STK resonance model abstract base class.
Definition: Modal.h:27
stk::Modal::setModeGain
void setModeGain(unsigned int modeIndex, StkFloat gain)
Set the gain for a specified mode filter.
stk::Modal::damp
void damp(StkFloat amplitude)
Damp modes with a given decay factor (0.0 - 1.0).
stk::Modal::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
stk::Modal::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
stk::Modal::setFrequency
virtual void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk::Modal::setMasterGain
void setMasterGain(StkFloat aGain)
Set the master gain.
Definition: Modal.h:48
stk::Modal::setDirectGain
void setDirectGain(StkFloat aGain)
Set the direct gain.
Definition: Modal.h:51
stk::Modal::setRatioAndRadius
void setRatioAndRadius(unsigned int modeIndex, StkFloat ratio, StkFloat radius)
Set the ratio and radius for a specified mode filter.
stk::Modal::~Modal
virtual ~Modal(void)
Class destructor.
stk::Modal::controlChange
virtual void controlChange(int number, StkFloat value)=0
Perform the control change specified by number and value (0.0 - 128.0).
stk::Modal::strike
virtual void strike(StkFloat amplitude)
Initiate a strike with the given amplitude (0.0 - 1.0).
stk::Modal::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition: Modal.h:104
stk::Modal::clear
void clear(void)
Reset and clear all internal state.
stk::Modal::Modal
Modal(unsigned int modes=4)
Class constructor, taking the desired number of modes to create.
stk::OnePole
STK one-pole filter class.
Definition: OnePole.h:21
stk::OnePole::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: OnePole.h:80
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--2021 Perry R. Cook and Gary P. Scavone. All Rights Reserved.