forked from thestk/stk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Simple.cpp
105 lines (89 loc) · 2.55 KB
/
Simple.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
/***************************************************/
/*! \class Simple
\brief STK wavetable/noise instrument.
This class combines a looped wave, a
noise source, a biquad resonance filter,
a one-pole filter, and an ADSR envelope
to create some interesting sounds.
Control Change Numbers:
- Filter Pole Position = 2
- Noise/Pitched Cross-Fade = 4
- Envelope Rate = 11
- Gain = 128
by Perry R. Cook and Gary P. Scavone, 1995--2023.
*/
/***************************************************/
#include "Simple.h"
#include "SKINImsg.h"
namespace stk {
Simple :: Simple( void )
{
// Concatenate the STK rawwave path to the rawwave file
loop_ = new FileLoop( (Stk::rawwavePath() + "impuls10.raw").c_str(), true );
filter_.setPole( 0.5 );
baseFrequency_ = 440.0;
setFrequency( baseFrequency_ );
loopGain_ = 0.5;
}
Simple :: ~Simple( void )
{
delete loop_;
}
void Simple :: keyOn( void )
{
adsr_.keyOn();
}
void Simple :: keyOff( void )
{
adsr_.keyOff();
}
void Simple :: noteOn( StkFloat frequency, StkFloat amplitude )
{
this->keyOn();
this->setFrequency( frequency );
filter_.setGain( amplitude );
}
void Simple :: noteOff( StkFloat amplitude )
{
this->keyOff();
}
void Simple :: setFrequency( StkFloat frequency )
{
#if defined(_STK_DEBUG_)
if ( frequency <= 0.0 ) {
oStream_ << "Simple::setFrequency: argument is less than or equal to zero!";
handleError( StkError::WARNING ); return;
}
#endif
biquad_.setResonance( frequency, 0.98, true );
loop_->setFrequency( frequency );
}
void Simple :: controlChange( int number, StkFloat value )
{
#if defined(_STK_DEBUG_)
if ( Stk::inRange( value, 0.0, 128.0 ) == false ) {
oStream_ << "Simple::controlChange: value (" << value << ") is out of range!";
handleError( StkError::WARNING ); return;
}
#endif
StkFloat normalizedValue = value * ONE_OVER_128;
if (number == __SK_Breath_) // 2
filter_.setPole( 0.99 * (1.0 - (normalizedValue * 2.0)) );
else if (number == __SK_NoiseLevel_) // 4
loopGain_ = normalizedValue;
else if (number == __SK_ModFrequency_) { // 11
normalizedValue /= 0.2 * Stk::sampleRate();
adsr_.setAttackRate( normalizedValue );
adsr_.setDecayRate( normalizedValue );
adsr_.setReleaseRate( normalizedValue );
}
else if (number == __SK_AfterTouch_Cont_) // 128
adsr_.setTarget( normalizedValue );
#if defined(_STK_DEBUG_)
else {
oStream_ << "Simple::controlChange: undefined control number (" << number << ")!";
handleError( StkError::WARNING );
}
#endif
}
} // stk namespace