1 |
persson |
2055 |
/*************************************************************************** |
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., 51 Franklin St, Fifth Floor, Boston, * |
21 |
|
|
* MA 02110-1301 USA * |
22 |
|
|
***************************************************************************/ |
23 |
|
|
|
24 |
|
|
#ifndef LS_SFZ_EGADSR_H |
25 |
|
|
#define LS_SFZ_EGADSR_H |
26 |
|
|
|
27 |
|
|
#include "../common/EG.h" |
28 |
|
|
|
29 |
|
|
namespace LinuxSampler { namespace sfz { |
30 |
|
|
|
31 |
|
|
/** |
32 |
|
|
* ADSR Envelope Generator |
33 |
|
|
* |
34 |
|
|
* SFZ v1 envelope generator with 'Attack', 'Hold', 'Decay', 'Sustain' |
35 |
|
|
* and 'Release' stages for modulating arbitrary synthesis parameters. |
36 |
|
|
*/ |
37 |
|
|
class EGADSR : public ::LinuxSampler::EG { |
38 |
|
|
public: |
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* Will be called by the voice when the key / voice was triggered. |
42 |
|
|
* |
43 |
|
|
* @param PreAttack - Preattack value for the envelope |
44 |
|
|
* (0 - 1000 permille) |
45 |
|
|
* @param AttackTime - Attack time for the envelope |
46 |
persson |
2203 |
* @param HoldTime - Hold time for the envelope |
47 |
persson |
2055 |
* @param DecayTime - Decay1 time of the sample amplitude EG |
48 |
|
|
* @param SustainLevel - Sustain level of the sample amplitude EG |
49 |
|
|
* (0 - 1000 permille) |
50 |
|
|
* @param ReleaseTIme - Release time for the envelope |
51 |
|
|
* @param SampleRate - sample rate of used audio output driver |
52 |
|
|
*/ |
53 |
persson |
2203 |
void trigger(uint PreAttack, float AttackTime, float HoldTime, float DecayTime, uint SustainLevel, float ReleaseTime, uint SampleRate); //FIXME: we should better use 'float' for SampleRate |
54 |
persson |
2055 |
|
55 |
|
|
/** |
56 |
|
|
* Should be called to inform the EG about an external event and |
57 |
|
|
* also whenever an envelope stage is completed. This will handle |
58 |
|
|
* the envelope's transition to the respective next stage. |
59 |
|
|
* |
60 |
|
|
* @param Event - what happened |
61 |
|
|
* @param SampleRate - sample rate of used audio output driver |
62 |
|
|
*/ |
63 |
|
|
void update(event_t Event, uint SampleRate); |
64 |
|
|
|
65 |
|
|
private: |
66 |
|
|
|
67 |
|
|
enum stage_t { |
68 |
|
|
stage_attack, |
69 |
|
|
stage_attack_hold, |
70 |
|
|
stage_decay, |
71 |
|
|
stage_sustain, |
72 |
|
|
stage_release, |
73 |
|
|
stage_fadeout, |
74 |
|
|
stage_end |
75 |
|
|
}; |
76 |
|
|
|
77 |
|
|
stage_t Stage; |
78 |
persson |
2203 |
int HoldSteps; |
79 |
persson |
2055 |
float DecayTime; |
80 |
|
|
float SustainLevel; |
81 |
|
|
float ReleaseSlope; |
82 |
|
|
|
83 |
|
|
void enterAttackStage(const uint PreAttack, const float AttackTime, const uint SampleRate); |
84 |
|
|
void enterAttackHoldStage(); |
85 |
|
|
void enterDecayStage(const uint SampleRate); |
86 |
|
|
void enterSustainStage(); |
87 |
|
|
void enterReleaseStage(); |
88 |
|
|
}; |
89 |
|
|
|
90 |
|
|
}} // namespace LinuxSampler::sfz |
91 |
|
|
|
92 |
|
|
#endif // LS_SFZ_EGADSR_H |