The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Resonate.h
1#ifndef STK_RESONATE_H
2#define STK_RESONATE_H
3
4#include "Instrmnt.h"
5#include "ADSR.h"
6#include "BiQuad.h"
7#include "Noise.h"
8
9namespace stk {
10
11/***************************************************/
28/***************************************************/
29
30 class Resonate : public Instrmnt
31{
32 public:
34 Resonate( void );
35
37 ~Resonate( void );
38
40 void setResonance( StkFloat frequency, StkFloat radius );
41
43 void setNotch( StkFloat frequency, StkFloat radius );
44
46 void setEqualGainZeroes( void ) { filter_.setEqualGainZeroes(); };
47
49 void keyOn( void ) { adsr_.keyOn(); };
50
52 void keyOff( void ) { adsr_.keyOff(); };
53
55 void noteOn( StkFloat frequency, StkFloat amplitude );
56
58 void noteOff( StkFloat amplitude );
59
61 void controlChange( int number, StkFloat value );
62
64 StkFloat tick( unsigned int channel = 0 );
65
67
74 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
75
76 protected:
77
78 ADSR adsr_;
79 BiQuad filter_;
80 Noise noise_;
81 StkFloat poleFrequency_;
82 StkFloat poleRadius_;
83 StkFloat zeroFrequency_;
84 StkFloat zeroRadius_;
85
86};
87
88 inline StkFloat Resonate :: tick( unsigned int )
89{
90 lastFrame_[0] = filter_.tick( noise_.tick() );
91 lastFrame_[0] *= adsr_.tick();
92 return lastFrame_[0];
93}
94
95 inline StkFrames& Resonate :: tick( StkFrames& frames, unsigned int channel )
96{
97 unsigned int nChannels = lastFrame_.channels();
98#if defined(_STK_DEBUG_)
99 if ( channel > frames.channels() - nChannels ) {
100 oStream_ << "Resonate::tick(): channel and StkFrames arguments are incompatible!";
101 handleError( StkError::FUNCTION_ARGUMENT );
102 }
103#endif
104
105 StkFloat *samples = &frames[channel];
106 unsigned int j, hop = frames.channels() - nChannels;
107 if ( nChannels == 1 ) {
108 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
109 *samples++ = tick();
110 }
111 else {
112 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
113 *samples++ = tick();
114 for ( j=1; j<nChannels; j++ )
115 *samples++ = lastFrame_[j];
116 }
117 }
118
119 return frames;
120}
121
122} // stk namespace
123
124#endif
stk::ADSR
STK ADSR envelope class.
Definition ADSR.h:25
stk::ADSR::keyOff
void keyOff(void)
Set target = 0, state = ADSR::RELEASE.
stk::ADSR::keyOn
void keyOn(void)
Set target = 1, state = ADSR::ATTACK.
stk::BiQuad
STK biquad (two-pole, two-zero) filter class.
Definition BiQuad.h:26
stk::BiQuad::setEqualGainZeroes
void setEqualGainZeroes(void)
Sets the filter zeroes for equal resonance gain.
stk::Instrmnt
STK instrument abstract base class.
Definition Instrmnt.h:20
stk::Noise
STK noise generator.
Definition Noise.h:22
stk::Noise::tick
StkFloat tick(void)
Compute and return one output sample.
Definition Noise.h:59
stk::Resonate
STK noise driven formant filter.
Definition Resonate.h:31
stk::Resonate::keyOff
void keyOff(void)
Signal a key-off event to the envelope.
Definition Resonate.h:52
stk::Resonate::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
stk::Resonate::~Resonate
~Resonate(void)
Class destructor.
stk::Resonate::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
stk::Resonate::setResonance
void setResonance(StkFloat frequency, StkFloat radius)
Set the filter for a resonance at the given frequency (Hz) and radius.
stk::Resonate::Resonate
Resonate(void)
Class constructor.
stk::Resonate::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition Resonate.h:88
stk::Resonate::setNotch
void setNotch(StkFloat frequency, StkFloat radius)
Set the filter for a notch at the given frequency (Hz) and radius.
stk::Resonate::setEqualGainZeroes
void setEqualGainZeroes(void)
Set the filter zero coefficients for contant resonance gain.
Definition Resonate.h:46
stk::Resonate::controlChange
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
stk::Resonate::keyOn
void keyOn(void)
Initiate the envelope with a key-on event.
Definition Resonate.h:49
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.