-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathAhdEnv.cpp
More file actions
40 lines (32 loc) · 858 Bytes
/
AhdEnv.cpp
File metadata and controls
40 lines (32 loc) · 858 Bytes
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
#include "AhdEnv.h"
#include "Utility.h"
using namespace daisy;
using namespace daisysp;
void AhdEnv::Init(float sample_rate) {
ad.Init(sample_rate);
adsr.Init(sample_rate);
adsr.SetTime(ADSR_SEG_DECAY, 0.001);
adsr.SetSustainLevel(0.5);
}
float AhdEnv::Process() {
// The AD envelope is used to count off the gate time of the ADSR, providing the hold time.
ad.Process();
return adsr.Process(ad.IsRunning());
}
void AhdEnv::Trigger() {
ad.Trigger();
adsr.Retrigger(true);
}
void AhdEnv::SetAttack(float time) {
ad.SetTime(ADENV_SEG_ATTACK, time);
adsr.SetTime(ADSR_SEG_ATTACK, time);
}
void AhdEnv::SetHold(float time) {
ad.SetTime(ADENV_SEG_DECAY, time);
}
void AhdEnv::SetDecay(float time) {
adsr.SetTime(ADSR_SEG_RELEASE, time);
}
bool AhdEnv::IsRunning() const {
return adsr.IsRunning();
}