blob: dcc31376086bf3c9180da77066ef58b3a567accb (
plain)
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
|
/******************************************/
/* Karplus-Strong drone string model */
/* by Perry Cook, 1995-96 */
/* */
/* There exist at least two patents, */
/* assigned to Stanford, bearing the */
/* names of Karplus and/or Strong. */
/******************************************/
#include "drone.h"
drone :: drone(StkFloat lowestFreq)
{
length = (long) (SRATE / lowestFreq + 1);
loopGain = (StkFloat) 0.999;
loopFilt = new OneZero();
delayLine = new DelayA(0.5*length, length);
envelope = new ADSR();
noise = new Noise;
envelope->setAllTimes(2.0,0.5,0.0,0.5);
this->clear();
}
drone :: ~drone()
{
delete loopFilt;
delete delayLine;
delete envelope;
delete noise;
}
void drone :: clear()
{
loopFilt->clear();
delayLine->clear();
}
void drone :: setFreq(StkFloat frequency)
{
StkFloat delay;
delay = (SRATE / frequency);
delayLine->setDelay(delay - 0.5);
loopGain = (StkFloat) 0.997 + (frequency * (StkFloat) 0.000002);
if (loopGain>1.0) loopGain = (StkFloat) 0.99999;
}
void drone :: pluck(StkFloat amplitude)
{
envelope->keyOn();
}
void drone :: noteOn(StkFloat freq, StkFloat amp)
{
this->setFreq(freq);
this->pluck(amp);
#if defined(_debug_)
printf("drone : NoteOn: Freq=%lf Amp=%lf\n",freq,amp);
#endif
}
void drone :: noteOff(StkFloat amp)
{
loopGain = (StkFloat) 1.0 - amp;
#if defined(_debug_)
printf("drone : NoteOff: Amp=%lf\n",amp);
#endif
}
StkFloat drone :: tick()
{
/* check this out */
/* here's the whole inner loop of the instrument!! */
lastOutput_ = delayLine->tick(loopFilt->tick((delayLine->lastOut() * loopGain))
+ (0.005 * envelope->tick() * noise->tick()));
return lastOutput_;
}
|