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
30class 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
88inline StkFloat Resonate :: tick( unsigned int )
89{
90 lastFrame_[0] = filter_.tick( noise_.tick() );
91 lastFrame_[0] *= adsr_.tick();
92 return lastFrame_[0];
93}
94
95inline 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 envelope class.
Definition ADSR.h:25
void keyOff(void)
Set target = 0, state = ADSR::RELEASE.
void keyOn(void)
Set target = 1, state = ADSR::ATTACK.
STK biquad (two-pole, two-zero) filter class.
Definition BiQuad.h:26
void setEqualGainZeroes(void)
Sets the filter zeroes for equal resonance gain.
STK instrument abstract base class.
Definition Instrmnt.h:20
STK noise generator.
Definition Noise.h:22
StkFloat tick(void)
Compute and return one output sample.
Definition Noise.h:59
STK noise driven formant filter.
Definition Resonate.h:31
void keyOff(void)
Signal a key-off event to the envelope.
Definition Resonate.h:52
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
~Resonate(void)
Class destructor.
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
void setResonance(StkFloat frequency, StkFloat radius)
Set the filter for a resonance at the given frequency (Hz) and radius.
Resonate(void)
Class constructor.
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition Resonate.h:88
void setNotch(StkFloat frequency, StkFloat radius)
Set the filter for a notch at the given frequency (Hz) and radius.
void setEqualGainZeroes(void)
Set the filter zero coefficients for contant resonance gain.
Definition Resonate.h:46
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
void keyOn(void)
Initiate the envelope with a key-on event.
Definition Resonate.h:49
An STK class to handle vectorized audio data.
Definition Stk.h:279
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:419
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.