-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathadsr.h
69 lines (57 loc) · 1.58 KB
/
adsr.h
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
//
// ADRS.h
//
// Originally Created by Nigel Redmon on 12/18/12.
// EarLevel Engineering: earlevel.com
// Copyright 2012 Nigel Redmon
// C Port by Francesco D'Este
//
// For a complete explanation of the ADSR envelope generator and code,
// read the series of articles by the author, starting here:
// http://www.earlevel.com/main/2013/06/01/envelope-generators/
//
// License:
//
// This source code is provided as is, without warranty.
// You may copy and distribute verbatim copies of this document.
// You may modify and use this source code to create binary code for your own purposes, free or commercial.
//
#ifndef ADRS_h
#define ADRS_h
enum envState {
env_idle = 0,
env_attack,
env_decay,
env_sustain,
env_release
};
typedef struct {
int state;
float output;
float attackRate;
float decayRate;
float releaseRate;
float attackCoef;
float decayCoef;
float releaseCoef;
float sustainLevel;
float targetRatioA;
float targetRatioDR;
float attackBase;
float decayBase;
float releaseBase;
int gate;
} ADSR;
float calcCoef(float rate, float targetRatio);
float process(ADSR* ptr);
float getOutput(ADSR* ptr);
int getState(ADSR* ptr);
void gate(ADSR* ptr);
void setAttackRate(ADSR* ptr, float rate);
void setDecayRate(ADSR* ptr, float rate);
void setReleaseRate(ADSR* ptr, float rate);
void setSustainLevel(ADSR* ptr, float level);
void setTargetRatioA(ADSR* ptr, float targetRatio);
void setTargetRatioDR(ADSR* ptr, float targetRatio);
void reset(ADSR* ptr);
#endif