/[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 271 by schoenebeck, Fri Oct 8 20:51:39 2004 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 - 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 23  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 <math.h>  #include "../common/EG.h"
   
 #include "../../common/global.h"  
 #include "../../common/RTMath.h"  
 #include "../../common/RTELMemoryPool.h"  
 #include "../common/Event.h"  
 #include "Manipulator.h"  
 #include "Engine.h"  
   
 #define EG_ENVELOPE_LIMIT       0.001  
 #define EG_MIN_RELEASE_TIME     0.0001  
28    
29  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
30    
# Line 44  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            /**
42             * Will be called by the voice when the key / voice was triggered.
43             *
44             * @param PreAttack       - Preattack value for the envelope
45             *                          (0 - 1000 permille)
46             * @param AttackTime      - Attack time for the envelope
47             *                          (0.000 - 60.000s)
48             * @param HoldAttack      - if true, Decay1 will be postponed until the
49             *                          sample reached the sample loop start.
50             * @param Decay1Time      - Decay1 time of the sample amplitude EG
51             *                          (0.000 - 60.000s)
52             * @param Decay2Time      - only if !InfiniteSustain: 2nd decay stage
53             *                          time of the sample amplitude EG
54             *                          (0.000 - 60.000s)
55             * @param InfiniteSustain - if true, instead of going into Decay2
56             *                          stage, Decay1 level will be hold until note
57             *                          will be released
58             * @param SustainLevel    - Sustain level of the sample amplitude EG
59             *                          (0 - 1000 permille)
60             * @param ReleaseTIme     - Release time for the envelope
61             *                          (0.000 - 60.000s)
62             * @param Volume          - volume the sample will be played at
63             *                          (0.0 - 1.0) - used when calculating the
64             *                          exponential curve parameters.
65             * @param SampleRate      - sample rate of used audio output driver
66             */
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
68    
69            /**
70             * Should be called to inform the EG about an external event and
71             * also whenever an envelope stage is completed. This will handle
72             * the envelope's transition to the respective next stage.
73             *
74             * @param Event        - what happened
75             */
76            void update(event_t Event, uint SampleRate);
77    
78        private:
79    
80          enum stage_t {          enum stage_t {
81              stage_attack,              stage_attack,
82              stage_attack_hold,              stage_attack_hold,
83              stage_decay1,              stage_decay1_part1,
84                stage_decay1_part2,
85              stage_decay2,              stage_decay2,
86              stage_sustain,              stage_sustain,
87              stage_release,              stage_release_part1,
88                stage_release_part2,
89              stage_fadeout,              stage_fadeout,
90              stage_end              stage_end
91          };          };
92    
93          EGADSR(gig::Engine* pEngine, Event::destination_t ModulationDestination);          stage_t   Stage;
94          void Process(uint TotalSamples, RTList<Event>* pEvents, RTList<Event>::Iterator itTriggerEvent, double SamplePos, double CurrentPitch, RTList<Event>::Iterator itKillEvent = RTList<Event>::Iterator());          bool      HoldAttack;
95          void Trigger(uint PreAttack, double AttackTime, bool HoldAttack, long LoopStart, double Decay1Time, double Decay2Time, bool InfiniteSustain, uint SustainLevel, double ReleaseTime, uint Delay);          bool      InfiniteSustain;
96          inline EGADSR::stage_t GetStage() { return Stage; }          float     Decay1Time;
97      protected:          float     Decay1Level2;
98          gig::Engine* pEngine;          float     Decay1Slope;
99          Event::destination_t ModulationDestination;          float     Decay2Time;
100          uint    TriggerDelay;      ///< number of sample points triggering should be delayed          float     SustainLevel;
101          float   Level;          float     ReleaseCoeff;
102          stage_t Stage;          float     ReleaseCoeff2;
103          float   AttackCoeff;          float     ReleaseCoeff3;
104          long    AttackStepsLeft;   ///< number of sample points til end of attack stage          float     ReleaseLevel2;
105          bool    HoldAttack;          float     ReleaseSlope;
106          long    LoopStart;          float     invVolume;
107          float   Decay1Coeff;          float     ExpOffset;
108          long    Decay1StepsLeft;   ///< number of sample points in Decay1 stage  
109          float   Decay2Coeff;          void enterAttackStage(const uint PreAttack, const float AttackTime, const uint SampleRate);
110          bool    InfiniteSustain;          void enterAttackHoldStage();
111          float   SustainLevel;          void enterDecay1Part1Stage(const uint SampleRate);
112          float   ReleaseCoeff;          void enterDecay1Part2Stage(const uint SampleRate);
113          long    ReleaseStepsLeft;  ///< number of sample points til end of release stage          void enterDecay2Stage(const uint SampleRate);
114          bool    ReleasePostponed;  ///< If a "release" event occured in the previous audio fragment, but wasn't processed yet.          void enterSustainStage();
115          const static float FadeOutCoeff;          void enterReleasePart1Stage();
116      private:          void enterReleasePart2Stage();
         static float CalculateFadeOutCoeff();  
117  };  };
118    
119  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

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

  ViewVC Help
Powered by ViewVC