1 |
schoenebeck |
30 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
|
|
* Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck * |
6 |
|
|
* * |
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 __EG_VCA_H__ |
24 |
|
|
#define __EG_VCA_H__ |
25 |
|
|
|
26 |
|
|
#include <math.h> |
27 |
|
|
|
28 |
|
|
#include "global.h" |
29 |
|
|
#include "modulationsystem.h" |
30 |
|
|
|
31 |
|
|
#define EG_ENVELOPE_LIMIT 0.001 |
32 |
|
|
#define EG_MIN_RELEASE_TIME 0.005 |
33 |
|
|
|
34 |
|
|
/** |
35 |
|
|
* VCA Envelope Generator |
36 |
|
|
* |
37 |
|
|
* This EG controls volume attenuation. |
38 |
|
|
*/ |
39 |
|
|
class EG_VCA { |
40 |
|
|
public: |
41 |
|
|
enum stage_t { |
42 |
|
|
stage_attack, |
43 |
|
|
stage_sustain, |
44 |
|
|
stage_release, |
45 |
|
|
stage_end |
46 |
|
|
}; |
47 |
|
|
|
48 |
|
|
static const double Limit; |
49 |
|
|
|
50 |
|
|
EG_VCA(); |
51 |
schoenebeck |
31 |
void Process(uint Samples); |
52 |
schoenebeck |
30 |
void Trigger(uint PreAttack, double Attack, double Release); |
53 |
|
|
void Release(); |
54 |
|
|
inline EG_VCA::stage_t GetStage() { return Stage; }; |
55 |
|
|
protected: |
56 |
|
|
float Level; |
57 |
|
|
bool ReleaseSignalReceived; |
58 |
|
|
stage_t Stage; |
59 |
|
|
float AttackCoeff; |
60 |
|
|
long AttackStepsLeft; ///< number of sample points til end of attack stage |
61 |
|
|
float ReleaseCoeff; |
62 |
|
|
long ReleaseStepsLeft; ///< number of sample points til end of release stage |
63 |
|
|
|
64 |
|
|
inline long Min(long A, long B) { |
65 |
|
|
return (A > B) ? B : A; |
66 |
|
|
} |
67 |
|
|
}; |
68 |
|
|
|
69 |
|
|
#endif // __EG_VCA_H__ |