/[svn]/linuxsampler/trunk/src/engines/gig/EGDecay.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/gig/EGDecay.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 738 - (show annotations) (download) (as text)
Tue Aug 16 17:14:25 2005 UTC (18 years, 8 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 4545 byte(s)
* extensive synthesis optimization: reimplementation of EGs and LFO(s),
  removed synthesis parameter prerendering and the synthesis parameter
  matrix in general, splitting each audio fragment into subfragments now
  where each subfragment uses constant synthesis parameters
  (everything's still very buggy ATM)

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 Christian Schoenebeck *
7 * *
8 * This library 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 library 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 library; 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_EGDECAY_H__
25 #define __LS_GIG_EGDECAY_H__
26
27 #include "../../common/global.h"
28 #include "../../common/RTMath.h"
29
30 namespace LinuxSampler { namespace gig {
31
32 /** @brief Decay Envelope Generator (linear)
33 *
34 * Simple Envelope Generator with only one stage: 'Decay' which is a
35 * linear segment. The initial envelope level (given by 'Depth') will
36 * raise / drop in 'DecayTime' seconds to a level of exactly 1.0. If
37 * the initial level ('Depth') is already 1.0, nothing happens.
38 */
39 class EGDecay {
40 public:
41 EGDecay();
42
43 /**
44 * Will be called by the voice when the key / voice was
45 * triggered and initialize the envelope generator.
46 *
47 * @param Depth - initial level of the envelope
48 * @param DecayTime - decay time of the envelope (0.000 - 10.000s)
49 * @param SampleRate - sample rate of used audio driver
50 */
51 void trigger(float Depth, float DecayTime, unsigned int SampleRate); //FIXME: we should better use 'float' for SampleRate
52
53 /**
54 * Returns true if envelope is still in stage 'Decay', returns
55 * false if end of envelope is reached.
56 */
57 inline bool active() {
58 return (bool) Coeff;
59 }
60
61 /**
62 * Advance envelope by \a SamplePoints steps.
63 */
64 inline void increment(const int SamplePoints) {
65 StepsLeft = RTMath::Max(0, StepsLeft - SamplePoints);
66 }
67
68 /**
69 * Returns amount of steps until end of envelope is reached.
70 */
71 inline int toEndLeft() {
72 return StepsLeft;
73 }
74
75 /**
76 * Should be called once the end of the envelope is reached. It
77 * will neutralize the envelope coefficient to not alter the
78 * envelope anymore and will set the output level to final level
79 * of exactly 1.0f. So after this call, render() can still
80 * safely be called from the sampler's main synthesis loop.
81 */
82 inline void update() {
83 Level = 1.0f;
84 Coeff = 0.0f;
85 }
86
87 /**
88 * Calculates exactly one level of the envelope.
89 *
90 * @returns next envelope level
91 */
92 inline float render() {
93 return (Level += Coeff);
94 }
95
96 private:
97 float Level; ///< current EG output level
98 float Coeff; ///< linear coefficient for changing the output level in time
99 int StepsLeft; ///< how many steps left until end is reached
100 };
101
102 }} // namespace LinuxSampler::gig
103
104 #endif // __LS_GIG_EGDECAY_H__

  ViewVC Help
Powered by ViewVC