1 |
schoenebeck |
53 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
schoenebeck |
56 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
schoenebeck |
554 |
* Copyright (C) 2005 Christian Schoenebeck * |
7 |
schoenebeck |
53 |
* * |
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 <math.h> |
28 |
|
|
|
29 |
|
|
#include "../../common/global.h" |
30 |
|
|
#include "../../common/RTMath.h" |
31 |
schoenebeck |
273 |
#include "../../common/Pool.h" |
32 |
schoenebeck |
53 |
#include "../common/Event.h" |
33 |
|
|
#include "Manipulator.h" |
34 |
|
|
#include "Engine.h" |
35 |
|
|
|
36 |
|
|
namespace LinuxSampler { namespace gig { |
37 |
|
|
|
38 |
|
|
/** |
39 |
|
|
* ADSR Envelope Generator |
40 |
|
|
* |
41 |
|
|
* Envelope Generator with stage 'Attack', 'Attack_Hold', 'Decay_1', |
42 |
|
|
* 'Decay_2', 'Sustain' and 'Release' for modulating arbitrary synthesis |
43 |
|
|
* parameters. |
44 |
|
|
*/ |
45 |
|
|
class EGADSR { |
46 |
|
|
public: |
47 |
|
|
enum stage_t { |
48 |
|
|
stage_attack, |
49 |
|
|
stage_attack_hold, |
50 |
persson |
614 |
stage_decay1_init, |
51 |
schoenebeck |
53 |
stage_decay1, |
52 |
persson |
614 |
stage_decay1_part2_init, |
53 |
|
|
stage_decay1_part2, |
54 |
|
|
stage_decay2_init, |
55 |
schoenebeck |
53 |
stage_decay2, |
56 |
|
|
stage_sustain, |
57 |
persson |
614 |
stage_release_init, |
58 |
schoenebeck |
53 |
stage_release, |
59 |
persson |
614 |
stage_release_part2_init, |
60 |
|
|
stage_release_part2, |
61 |
schoenebeck |
252 |
stage_fadeout, |
62 |
schoenebeck |
53 |
stage_end |
63 |
|
|
}; |
64 |
|
|
|
65 |
|
|
EGADSR(gig::Engine* pEngine, Event::destination_t ModulationDestination); |
66 |
schoenebeck |
271 |
void Process(uint TotalSamples, RTList<Event>* pEvents, RTList<Event>::Iterator itTriggerEvent, double SamplePos, double CurrentPitch, RTList<Event>::Iterator itKillEvent = RTList<Event>::Iterator()); |
67 |
persson |
614 |
void Trigger(uint PreAttack, double AttackTime, bool HoldAttack, long LoopStart, double Decay1Time, double Decay2Time, bool InfiniteSustain, uint SustainLevel, double ReleaseTime, uint Delay, float Volume); |
68 |
schoenebeck |
53 |
inline EGADSR::stage_t GetStage() { return Stage; } |
69 |
|
|
protected: |
70 |
|
|
gig::Engine* pEngine; |
71 |
|
|
Event::destination_t ModulationDestination; |
72 |
|
|
uint TriggerDelay; ///< number of sample points triggering should be delayed |
73 |
|
|
float Level; |
74 |
|
|
stage_t Stage; |
75 |
|
|
float AttackCoeff; |
76 |
|
|
long AttackStepsLeft; ///< number of sample points til end of attack stage |
77 |
|
|
bool HoldAttack; |
78 |
|
|
long LoopStart; |
79 |
|
|
float Decay1Coeff; |
80 |
persson |
614 |
float Decay1Coeff2; |
81 |
|
|
float Decay1Coeff3; |
82 |
|
|
float Decay1Level2; |
83 |
|
|
float Decay1Slope; |
84 |
schoenebeck |
53 |
long Decay1StepsLeft; ///< number of sample points in Decay1 stage |
85 |
|
|
float Decay2Coeff; |
86 |
persson |
614 |
long Decay2StepsLeft; |
87 |
schoenebeck |
53 |
bool InfiniteSustain; |
88 |
|
|
float SustainLevel; |
89 |
|
|
float ReleaseCoeff; |
90 |
persson |
614 |
float ReleaseCoeff2; |
91 |
|
|
float ReleaseCoeff3; |
92 |
|
|
float ReleaseLevel2; |
93 |
|
|
float ReleaseSlope; |
94 |
schoenebeck |
53 |
long ReleaseStepsLeft; ///< number of sample points til end of release stage |
95 |
|
|
bool ReleasePostponed; ///< If a "release" event occured in the previous audio fragment, but wasn't processed yet. |
96 |
persson |
614 |
float ExpOffset; |
97 |
schoenebeck |
252 |
const static float FadeOutCoeff; |
98 |
schoenebeck |
239 |
private: |
99 |
schoenebeck |
252 |
static float CalculateFadeOutCoeff(); |
100 |
schoenebeck |
53 |
}; |
101 |
|
|
|
102 |
|
|
}} // namespace LinuxSampler::gig |
103 |
|
|
|
104 |
|
|
#endif // __LS_GIG_EGADSR_H__ |