-
Notifications
You must be signed in to change notification settings - Fork 182
/
Resonate.cpp
113 lines (95 loc) · 3.06 KB
/
Resonate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***************************************************/
/*! \class Resonate
\brief STK noise driven formant filter.
This instrument contains a noise source, which
excites a biquad resonance filter, with volume
controlled by an ADSR.
Control Change Numbers:
- Resonance Frequency (0-Nyquist) = 2
- Pole Radii = 4
- Notch Frequency (0-Nyquist) = 11
- Zero Radii = 1
- Envelope Gain = 128
by Perry R. Cook and Gary P. Scavone, 1995--2023.
*/
/***************************************************/
#include "Resonate.h"
#include "SKINImsg.h"
namespace stk {
Resonate :: Resonate( void )
{
poleFrequency_ = 4000.0;
poleRadius_ = 0.95;
// Set the filter parameters.
filter_.setResonance( poleFrequency_, poleRadius_, true );
zeroFrequency_ = 0.0;
zeroRadius_ = 0.0;
}
Resonate :: ~Resonate( void )
{
}
void Resonate :: noteOn( StkFloat frequency, StkFloat amplitude )
{
adsr_.setTarget( amplitude );
this->keyOn();
this->setResonance( frequency, poleRadius_ );
}
void Resonate :: noteOff( StkFloat amplitude )
{
this->keyOff();
}
void Resonate :: setResonance( StkFloat frequency, StkFloat radius )
{
if ( frequency < 0.0 ) {
oStream_ << "Resonate::setResonance: frequency parameter is less than zero!";
handleError( StkError::WARNING ); return;
}
if ( radius < 0.0 || radius >= 1.0 ) {
oStream_ << "Resonate::setResonance: radius parameter is out of range!";
handleError( StkError::WARNING ); return;
}
poleFrequency_ = frequency;
poleRadius_ = radius;
filter_.setResonance( poleFrequency_, poleRadius_, true );
}
void Resonate :: setNotch( StkFloat frequency, StkFloat radius )
{
if ( frequency < 0.0 ) {
oStream_ << "Resonate::setNotch: frequency parameter is less than zero ... setting to 0.0!";
handleError( StkError::WARNING ); return;
}
if ( radius < 0.0 ) {
oStream_ << "Resonate::setNotch: radius parameter is less than 0.0!";
handleError( StkError::WARNING ); return;
}
zeroFrequency_ = frequency;
zeroRadius_ = radius;
filter_.setNotch( zeroFrequency_, zeroRadius_ );
}
void Resonate :: controlChange( int number, StkFloat value )
{
#if defined(_STK_DEBUG_)
if ( Stk::inRange( value, 0.0, 128.0 ) == false ) {
oStream_ << "Resonate::controlChange: value (" << value << ") is out of range!";
handleError( StkError::WARNING ); return;
}
#endif
StkFloat normalizedValue = value * ONE_OVER_128;
if (number == 2) // 2
setResonance( normalizedValue * Stk::sampleRate() * 0.5, poleRadius_ );
else if (number == 4) // 4
setResonance( poleFrequency_, normalizedValue * 0.9999 );
else if (number == 11) // 11
this->setNotch( normalizedValue * Stk::sampleRate() * 0.5, zeroRadius_ );
else if (number == 1)
this->setNotch( zeroFrequency_, normalizedValue );
else if (number == __SK_AfterTouch_Cont_) // 128
adsr_.setTarget( normalizedValue );
#if defined(_STK_DEBUG_)
else {
oStream_ << "Resonate::controlChange: undefined control number (" << number << ")!";
handleError( StkError::WARNING );
}
#endif
}
} // stk namespace