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

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

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

revision 2054 by persson, Sun Jun 22 14:46:46 2008 UTC revision 2055 by persson, Sat Jan 30 10:30:02 2010 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
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 - 2010 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   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  *   *   it under the terms of the GNU General Public License as published by  *
# Line 24  Line 24 
24  #ifndef __LS_GIG_EGADSR_H__  #ifndef __LS_GIG_EGADSR_H__
25  #define __LS_GIG_EGADSR_H__  #define __LS_GIG_EGADSR_H__
26    
27  #include "../../common/global.h"  #include "../common/EG.h"
 #include "../../common/RTMath.h"  
28    
29  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
30    
# Line 36  namespace LinuxSampler { namespace gig { Line 35  namespace LinuxSampler { namespace gig {
35   * 'Decay_2', 'Sustain' and 'Release' for modulating arbitrary synthesis   * 'Decay_2', 'Sustain' and 'Release' for modulating arbitrary synthesis
36   * parameters.   * parameters.
37   */   */
38  class EGADSR {  class EGADSR : public EG {
39      public:      public:
40    
41          /**          /**
          * Used to define what kind of segment the envelope currently is at.  
          */  
         enum segment_t {  
             segment_end = 0, ///< final end state of envelope reached  
             segment_lin = 1, ///< envelope is currently at a linear segment  
             segment_exp = 2  ///< envelope is currently at a exponental segment  
         };  
   
         /**  
          * Used to inform the EG about an event.  
          */  
         enum event_t {  
             event_stage_end,  
             event_release,  
             event_cancel_release,  
             event_hold_end  
         };  
   
         /**  
          * Constructor  
          */  
         EGADSR();  
   
         /**  
          * Change fade out time.  
          */  
         void CalculateFadeOutCoeff(float FadeOutTime, float SampleRate);  
   
         /**  
42           * Will be called by the voice when the key / voice was triggered.           * Will be called by the voice when the key / voice was triggered.
43           *           *
44           * @param PreAttack       - Preattack value for the envelope           * @param PreAttack       - Preattack value for the envelope
# Line 97  class EGADSR { Line 67  class EGADSR {
67          void trigger(uint PreAttack, float AttackTime, bool HoldAttack, float Decay1Time, double Decay2Time, bool InfiniteSustain, uint SustainLevel, float ReleaseTime, float Volume, uint SampleRate); //FIXME: we should better use 'float' for SampleRate          void trigger(uint PreAttack, float AttackTime, bool HoldAttack, float Decay1Time, double Decay2Time, bool InfiniteSustain, uint SustainLevel, float ReleaseTime, float Volume, uint SampleRate); //FIXME: we should better use 'float' for SampleRate
68    
69          /**          /**
          * Returns true in case envelope hasn't reached its final end state yet.  
          */  
         inline bool active() {  
             return (bool) Segment;  
         }  
   
         /**  
          * Returns what kind of segment the envelope currently is at.  
          */  
         inline segment_t getSegmentType() {  
             return Segment;  
         }  
   
         /**  
          * Advance envelope by \a SamplePoints steps.  
          */  
         inline void increment(int SamplePoints) {  
             StepsLeft = RTMath::Max(0, StepsLeft - SamplePoints);  
         }  
   
         /**  
          * Returns amount of steps until the end of current envelope stage.  
          */  
         inline int toStageEndLeft() {  
             return StepsLeft;  
         }  
   
         /**  
70           * Should be called to inform the EG about an external event and           * Should be called to inform the EG about an external event and
71           * also whenever an envelope stage is completed. This will handle           * also whenever an envelope stage is completed. This will handle
72           * the envelope's transition to the respective next stage.           * the envelope's transition to the respective next stage.
# Line 133  class EGADSR { Line 75  class EGADSR {
75           */           */
76          void update(event_t Event, uint SampleRate);          void update(event_t Event, uint SampleRate);
77    
         /**  
          * Calculates exactly one, the next sample point of EG  
          * (linear segment). Call this if envelope is currently in a linear  
          * segment.  
          *  
          * @returns next envelope level  
          */  
         inline float processLin() {  
             return (Level += Coeff);  
         }  
   
         /**  
          * Calculates exactly one, the next sample point of EG  
          * (exponential segment). Call this if envelope is currently in an  
          * exponential segment.  
          *  
          * @returns next envelope level  
          */  
         inline float processExp() {  
             return (Level = Level * Coeff + Offset);  
         }  
   
         /**  
          * Returns current envelope level without modifying anything. This  
          * might be needed once the envelope reached its final end state,  
          * because calling processLin() or processExp() at this point will  
          * result in undesired behavior.  
          */  
         inline float getLevel() {  
             return Level;  
         }  
   
         void enterFadeOutStage();  
         void enterFadeOutStage(int maxFadeOutSteps);  
   
78      private:      private:
79    
80          enum stage_t {          enum stage_t {
# Line 183  class EGADSR { Line 90  class EGADSR {
90              stage_end              stage_end
91          };          };
92    
         float     Level;  
         float     Coeff;  
         float     Offset;  
         int       StepsLeft;  
         segment_t Segment;  
93          stage_t   Stage;          stage_t   Stage;
94          bool      HoldAttack;          bool      HoldAttack;
95          bool      InfiniteSustain;          bool      InfiniteSustain;
# Line 203  class EGADSR { Line 105  class EGADSR {
105          float     ReleaseSlope;          float     ReleaseSlope;
106          float     invVolume;          float     invVolume;
107          float     ExpOffset;          float     ExpOffset;
         float     FadeOutCoeff; ///< very fast ramp down for e.g. voice stealing  
108    
109          void enterAttackStage(const uint PreAttack, const float AttackTime, const uint SampleRate);          void enterAttackStage(const uint PreAttack, const float AttackTime, const uint SampleRate);
110          void enterAttackHoldStage();          void enterAttackHoldStage();
# Line 213  class EGADSR { Line 114  class EGADSR {
114          void enterSustainStage();          void enterSustainStage();
115          void enterReleasePart1Stage();          void enterReleasePart1Stage();
116          void enterReleasePart2Stage();          void enterReleasePart2Stage();
         void enterEndStage();  
117  };  };
118    
119  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

Legend:
Removed from v.2054  
changed lines
  Added in v.2055

  ViewVC Help
Powered by ViewVC