/[svn]/linuxsampler/trunk/src/engines/sfz/EGADSR.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/sfz/EGADSR.cpp

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

revision 2310 by persson, Sat Jul 9 16:44:27 2011 UTC revision 2311 by persson, Sat Feb 11 11:08:09 2012 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 - 2011 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2012 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 94  namespace LinuxSampler { namespace sfz { Line 94  namespace LinuxSampler { namespace sfz {
94          }          }
95      }      }
96    
97      void EGADSR::trigger(uint PreAttack, float AttackTime, float HoldTime, float DecayTime, uint SustainLevel, float ReleaseTime, uint SampleRate) {      void EGADSR::trigger(uint PreAttack, float AttackTime, float HoldTime, float DecayTime, uint SustainLevel, float ReleaseTime, uint SampleRate, bool LinearRelease) {
98          this->SustainLevel = SustainLevel / 1000.0;          this->SustainLevel = SustainLevel / 1000.0;
99          this->HoldSteps    = int(HoldTime * SampleRate);          this->HoldSteps    = int(HoldTime * SampleRate);
100          this->DecayTime    = DecayTime;          this->DecayTime    = DecayTime;
101            this->LinearRelease = LinearRelease;
102    
103          if (ReleaseTime < CONFIG_EG_MIN_RELEASE_TIME) ReleaseTime = CONFIG_EG_MIN_RELEASE_TIME;  // to avoid click sounds at the end of the sample playback          if (ReleaseTime < CONFIG_EG_MIN_RELEASE_TIME) ReleaseTime = CONFIG_EG_MIN_RELEASE_TIME;  // to avoid click sounds at the end of the sample playback
104          ReleaseSlope = -9.226 / (ReleaseTime * SampleRate);          this->ReleaseTime = ReleaseTime * SampleRate;
105          Offset = 0;          Offset = 0;
106          enterFirstStage();          enterFirstStage();
107          enterAttackStage(PreAttack, AttackTime, SampleRate);          enterAttackStage(PreAttack, AttackTime, SampleRate);
# Line 129  namespace LinuxSampler { namespace sfz { Line 130  namespace LinuxSampler { namespace sfz {
130      }      }
131    
132      void EGADSR::enterDecayStage(const uint SampleRate) {      void EGADSR::enterDecayStage(const uint SampleRate) {
133          StepsLeft = (int) (DecayTime * SampleRate);          if (LinearRelease) {
134          if (StepsLeft && Level > SustainLevel) {              StepsLeft = int(DecayTime * SampleRate * (Level - SustainLevel));
135              Stage   = stage_decay;              if (StepsLeft > 0) {
136              Segment = segment_exp;                  Stage = stage_decay;
137              const float slope = -9.226 / StepsLeft;                  Segment = segment_lin;
138              Coeff  = exp(slope);                  Coeff = -1 / (DecayTime * SampleRate);
139              StepsLeft = int(log(std::max(SustainLevel, float(CONFIG_EG_BOTTOM)) / Level) / slope);                  return;
140              if (StepsLeft > 0) return;              }
141            } else {
142                StepsLeft = int(DecayTime * SampleRate);
143                if (StepsLeft && Level > SustainLevel) {
144                    Stage   = stage_decay;
145                    Segment = segment_exp;
146                    const float slope = -9.226 / StepsLeft;
147                    Coeff  = exp(slope);
148                    StepsLeft = int(log(std::max(SustainLevel, float(CONFIG_EG_BOTTOM)) / Level) / slope);
149                    if (StepsLeft > 0) return;
150                }
151          }          }
152          Level = SustainLevel;          Level = SustainLevel;
153          enterSustainStage();          enterSustainStage();
# Line 152  namespace LinuxSampler { namespace sfz { Line 163  namespace LinuxSampler { namespace sfz {
163    
164      void EGADSR::enterReleaseStage() {      void EGADSR::enterReleaseStage() {
165          Stage     = stage_release;          Stage     = stage_release;
166          Segment   = segment_exp;          if (LinearRelease) {
167          StepsLeft = int(log(CONFIG_EG_BOTTOM / Level) / ReleaseSlope);              Segment   = segment_lin;
168          Coeff     = exp(ReleaseSlope);              StepsLeft = int(Level * ReleaseTime);
169                Coeff = -1 / ReleaseTime;
170            } else {
171                Segment   = segment_exp;
172                const float slope = -9.226 / ReleaseTime;
173                StepsLeft = int(log(CONFIG_EG_BOTTOM / Level) / slope);
174                Coeff     = exp(slope);
175            }
176          if (StepsLeft <= 0) enterFadeOutStage();          if (StepsLeft <= 0) enterFadeOutStage();
177      }      }
178    

Legend:
Removed from v.2310  
changed lines
  Added in v.2311

  ViewVC Help
Powered by ViewVC