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 |
53 |
* * |
7 |
|
|
* This program is free software; you can redistribute it and/or modify * |
8 |
|
|
* it under the terms of the GNU General Public License as published by * |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
10 |
|
|
* (at your option) any later version. * |
11 |
|
|
* * |
12 |
|
|
* This program is distributed in the hope that it will be useful, * |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
15 |
|
|
* GNU General Public License for more details. * |
16 |
|
|
* * |
17 |
|
|
* You should have received a copy of the GNU General Public License * |
18 |
|
|
* along with this program; if not, write to the Free Software * |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
20 |
|
|
* MA 02111-1307 USA * |
21 |
|
|
***************************************************************************/ |
22 |
|
|
|
23 |
|
|
#ifndef __LS_GIG_EGADSR_H__ |
24 |
|
|
#define __LS_GIG_EGADSR_H__ |
25 |
|
|
|
26 |
|
|
#include <math.h> |
27 |
|
|
|
28 |
|
|
#include "../../common/global.h" |
29 |
|
|
#include "../../common/RTMath.h" |
30 |
schoenebeck |
273 |
#include "../../common/Pool.h" |
31 |
schoenebeck |
53 |
#include "../common/Event.h" |
32 |
|
|
#include "Manipulator.h" |
33 |
|
|
#include "Engine.h" |
34 |
|
|
|
35 |
|
|
#define EG_ENVELOPE_LIMIT 0.001 |
36 |
schoenebeck |
284 |
#define EG_MIN_RELEASE_TIME 0.0025 |
37 |
schoenebeck |
53 |
|
38 |
|
|
namespace LinuxSampler { namespace gig { |
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* ADSR Envelope Generator |
42 |
|
|
* |
43 |
|
|
* Envelope Generator with stage 'Attack', 'Attack_Hold', 'Decay_1', |
44 |
|
|
* 'Decay_2', 'Sustain' and 'Release' for modulating arbitrary synthesis |
45 |
|
|
* parameters. |
46 |
|
|
*/ |
47 |
|
|
class EGADSR { |
48 |
|
|
public: |
49 |
|
|
enum stage_t { |
50 |
|
|
stage_attack, |
51 |
|
|
stage_attack_hold, |
52 |
|
|
stage_decay1, |
53 |
|
|
stage_decay2, |
54 |
|
|
stage_sustain, |
55 |
|
|
stage_release, |
56 |
schoenebeck |
252 |
stage_fadeout, |
57 |
schoenebeck |
53 |
stage_end |
58 |
|
|
}; |
59 |
|
|
|
60 |
|
|
EGADSR(gig::Engine* pEngine, Event::destination_t ModulationDestination); |
61 |
schoenebeck |
271 |
void Process(uint TotalSamples, RTList<Event>* pEvents, RTList<Event>::Iterator itTriggerEvent, double SamplePos, double CurrentPitch, RTList<Event>::Iterator itKillEvent = RTList<Event>::Iterator()); |
62 |
schoenebeck |
53 |
void Trigger(uint PreAttack, double AttackTime, bool HoldAttack, long LoopStart, double Decay1Time, double Decay2Time, bool InfiniteSustain, uint SustainLevel, double ReleaseTime, uint Delay); |
63 |
|
|
inline EGADSR::stage_t GetStage() { return Stage; } |
64 |
|
|
protected: |
65 |
|
|
gig::Engine* pEngine; |
66 |
|
|
Event::destination_t ModulationDestination; |
67 |
|
|
uint TriggerDelay; ///< number of sample points triggering should be delayed |
68 |
|
|
float Level; |
69 |
|
|
stage_t Stage; |
70 |
|
|
float AttackCoeff; |
71 |
|
|
long AttackStepsLeft; ///< number of sample points til end of attack stage |
72 |
|
|
bool HoldAttack; |
73 |
|
|
long LoopStart; |
74 |
|
|
float Decay1Coeff; |
75 |
|
|
long Decay1StepsLeft; ///< number of sample points in Decay1 stage |
76 |
|
|
float Decay2Coeff; |
77 |
|
|
bool InfiniteSustain; |
78 |
|
|
float SustainLevel; |
79 |
|
|
float ReleaseCoeff; |
80 |
|
|
long ReleaseStepsLeft; ///< number of sample points til end of release stage |
81 |
|
|
bool ReleasePostponed; ///< If a "release" event occured in the previous audio fragment, but wasn't processed yet. |
82 |
schoenebeck |
252 |
const static float FadeOutCoeff; |
83 |
schoenebeck |
239 |
private: |
84 |
schoenebeck |
252 |
static float CalculateFadeOutCoeff(); |
85 |
schoenebeck |
53 |
}; |
86 |
|
|
|
87 |
|
|
}} // namespace LinuxSampler::gig |
88 |
|
|
|
89 |
|
|
#endif // __LS_GIG_EGADSR_H__ |