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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 737 by schoenebeck, Sat Feb 26 02:01:14 2005 UTC revision 738 by schoenebeck, Tue Aug 16 17:14:25 2005 UTC
# Line 5  Line 5 
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 Christian Schoenebeck                              *   *   Copyright (C) 2005 Christian Schoenebeck                              *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   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  *   *   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     *   *   the Free Software Foundation; either version 2 of the License, or     *
11   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
12   *                                                                         *   *                                                                         *
13   *   This program is distributed in the hope that it will be useful,       *   *   This library is distributed in the hope that it will be useful,       *
14   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16   *   GNU General Public License for more details.                          *   *   GNU General Public License for more details.                          *
17   *                                                                         *   *                                                                         *
18   *   You should have received a copy of the GNU General Public License     *   *   You should have received a copy of the GNU General Public License     *
19   *   along with this program; if not, write to the Free Software           *   *   along with this library; if not, write to the Free Software           *
20   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
21   *   MA  02111-1307  USA                                                   *   *   MA  02111-1307  USA                                                   *
22   ***************************************************************************/   ***************************************************************************/
# Line 25  Line 25 
25  #define __LS_GIG_EGDECAY_H__  #define __LS_GIG_EGDECAY_H__
26    
27  #include "../../common/global.h"  #include "../../common/global.h"
   
 #if DEBUG_HEADERS  
 # warning EGDecay.h included  
 #endif // DEBUG_HEADERS  
   
28  #include "../../common/RTMath.h"  #include "../../common/RTMath.h"
 #include "../common/Event.h"  
 #include "Engine.h"  
29    
30  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
31    
32      // just symbol prototyping      /** @brief Decay Envelope Generator (linear)
     class Engine;  
   
     /**  
      * Decay Envelope Generator  
33       *       *
34       * Simple Envelope Generator with only one stage: 'Decay'. We currently use       * Simple Envelope Generator with only one stage: 'Decay' which is a
35       * this specific EG only for pitch and thus it's not generalized yet, means       * linear segment. The initial envelope level (given by 'Depth') will
36       * the initial envelope level (given by 'Depth') will raise / drop in       * raise / drop in 'DecayTime' seconds to a level of exactly 1.0. If
37       * 'DecayTime' seconds to a level of exactly 1.0. If the initial level       * the initial level ('Depth') is already 1.0, nothing happens.
      * ('Depth') is already 1.0, nothing happens. Beside that, the EG just  
      * multiplies it's levels to the synthesis parameter sequence.  
38       */       */
39      class EGDecay {      class EGDecay {
40          public:          public:
41              EGDecay(gig::Engine* pEngine, Event::destination_t ModulationDestination);              EGDecay();
42              bool Process(uint Samples);  
43              void Trigger(float Depth, double DecayTime, uint Delay);              /**
44          protected:               * Will be called by the voice when the key / voice was
45              gig::Engine* pEngine;               * triggered and initialize the envelope generator.
46              Event::destination_t ModulationDestination;               *
47              uint  TriggerDelay;    ///< number of sample points triggering should be delayed               * @param Depth      - initial level of the envelope
48              float Level;               * @param DecayTime  - decay time of the envelope (0.000 - 10.000s)
49              float DecayCoeff;               * @param SampleRate - sample rate of used audio driver
50              long  DecayStepsLeft;               */
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  }} // namespace LinuxSampler::gig

Legend:
Removed from v.737  
changed lines
  Added in v.738

  ViewVC Help
Powered by ViewVC