1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2010 Christian Schoenebeck * |
7 |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
10 |
* the Free Software Foundation; either version 2 of the License, or * |
11 |
* (at your option) any later version. * |
12 |
* * |
13 |
* This program is distributed in the hope that it will be useful, * |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
* GNU General Public License for more details. * |
17 |
* * |
18 |
* You should have received a copy of the GNU General Public License * |
19 |
* along with this program; if not, write to the Free Software * |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
23 |
|
24 |
#ifndef __LS_GIG_EGADSR_H__ |
25 |
#define __LS_GIG_EGADSR_H__ |
26 |
|
27 |
#include "../common/EG.h" |
28 |
|
29 |
namespace LinuxSampler { namespace gig { |
30 |
|
31 |
/** |
32 |
* ADSR Envelope Generator |
33 |
* |
34 |
* Envelope Generator with stage 'Attack', 'Attack_Hold', 'Decay_1', |
35 |
* 'Decay_2', 'Sustain' and 'Release' for modulating arbitrary synthesis |
36 |
* parameters. |
37 |
*/ |
38 |
class EGADSR : public EG { |
39 |
public: |
40 |
|
41 |
/** |
42 |
* Will be called by the voice when the key / voice was triggered. |
43 |
* |
44 |
* @param PreAttack - Preattack value for the envelope |
45 |
* (0 - 1000 permille) |
46 |
* @param AttackTime - Attack time for the envelope |
47 |
* (0.000 - 60.000s) |
48 |
* @param HoldAttack - if true, Decay1 will be postponed until the |
49 |
* sample reached the sample loop start. |
50 |
* @param Decay1Time - Decay1 time of the sample amplitude EG |
51 |
* (0.000 - 60.000s) |
52 |
* @param Decay2Time - only if !InfiniteSustain: 2nd decay stage |
53 |
* time of the sample amplitude EG |
54 |
* (0.000 - 60.000s) |
55 |
* @param InfiniteSustain - if true, instead of going into Decay2 |
56 |
* stage, Decay1 level will be hold until note |
57 |
* will be released |
58 |
* @param SustainLevel - Sustain level of the sample amplitude EG |
59 |
* (0 - 1000 permille) |
60 |
* @param ReleaseTIme - Release time for the envelope |
61 |
* (0.000 - 60.000s) |
62 |
* @param Volume - volume the sample will be played at |
63 |
* (0.0 - 1.0) - used when calculating the |
64 |
* exponential curve parameters. |
65 |
* @param SampleRate - sample rate of used audio output driver |
66 |
*/ |
67 |
void trigger(uint PreAttack, float AttackTime, bool HoldAttack, float Decay1Time, double Decay2Time, bool InfiniteSustain, uint SustainLevel, float ReleaseTime, float Volume, uint SampleRate); //FIXME: we should better use 'float' for SampleRate |
68 |
|
69 |
/** |
70 |
* Should be called to inform the EG about an external event and |
71 |
* also whenever an envelope stage is completed. This will handle |
72 |
* the envelope's transition to the respective next stage. |
73 |
* |
74 |
* @param Event - what happened |
75 |
*/ |
76 |
void update(event_t Event, uint SampleRate); |
77 |
|
78 |
private: |
79 |
|
80 |
enum stage_t { |
81 |
stage_attack, |
82 |
stage_attack_hold, |
83 |
stage_decay1_part1, |
84 |
stage_decay1_part2, |
85 |
stage_decay2, |
86 |
stage_sustain, |
87 |
stage_release_part1, |
88 |
stage_release_part2, |
89 |
stage_fadeout, |
90 |
stage_end |
91 |
}; |
92 |
|
93 |
stage_t Stage; |
94 |
bool HoldAttack; |
95 |
bool InfiniteSustain; |
96 |
float Decay1Time; |
97 |
float Decay1Level2; |
98 |
float Decay1Slope; |
99 |
float Decay2Time; |
100 |
float SustainLevel; |
101 |
float ReleaseCoeff; |
102 |
float ReleaseCoeff2; |
103 |
float ReleaseCoeff3; |
104 |
float ReleaseLevel2; |
105 |
float ReleaseSlope; |
106 |
float invVolume; |
107 |
float ExpOffset; |
108 |
|
109 |
void enterAttackStage(const uint PreAttack, const float AttackTime, const uint SampleRate); |
110 |
void enterAttackHoldStage(); |
111 |
void enterDecay1Part1Stage(const uint SampleRate); |
112 |
void enterDecay1Part2Stage(const uint SampleRate); |
113 |
void enterDecay2Stage(const uint SampleRate); |
114 |
void enterSustainStage(); |
115 |
void enterReleasePart1Stage(); |
116 |
void enterReleasePart2Stage(); |
117 |
}; |
118 |
|
119 |
}} // namespace LinuxSampler::gig |
120 |
|
121 |
#endif // __LS_GIG_EGADSR_H__ |