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

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

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

revision 396 by persson, Sun Feb 20 20:32:24 2005 UTC revision 554 by schoenebeck, Thu May 19 19:25:14 2005 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                              *
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 28  namespace LinuxSampler { namespace gig { Line 29  namespace LinuxSampler { namespace gig {
29    
30      float EGADSR::CalculateFadeOutCoeff() {      float EGADSR::CalculateFadeOutCoeff() {
31          const float sampleRate = 44100.0; // even if the sample rate will be 192kHz it won't hurt at all          const float sampleRate = 44100.0; // even if the sample rate will be 192kHz it won't hurt at all
32          const float killSteps  = EG_MIN_RELEASE_TIME * sampleRate;          const float killSteps  = CONFIG_EG_MIN_RELEASE_TIME * sampleRate;
33          return -1.0f / killSteps;          return -1.0f / killSteps;
34      }      }
35    
# Line 62  namespace LinuxSampler { namespace gig { Line 63  namespace LinuxSampler { namespace gig {
63    
64          int iSample = TriggerDelay;          int iSample = TriggerDelay;
65    
66          #if DEVMODE          #if CONFIG_DEVMODE
67          if (TriggerDelay > TotalSamples) { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging)          if (TriggerDelay > TotalSamples) { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging)
68              dmsg(1,("EGADSR: ERROR, TriggerDelay > Totalsamples\n"));              dmsg(1,("EGADSR: ERROR, TriggerDelay > Totalsamples\n"));
69              int* i = NULL;              int* i = NULL;
70              (*i)++; // force a segfault              (*i)++; // force a segfault
71          }          }
72          #endif // DEVMODE          #endif // CONFIG_DEVMODE
73    
74          while (iSample < TotalSamples) {          while (iSample < TotalSamples) {
75    
# Line 141  namespace LinuxSampler { namespace gig { Line 142  namespace LinuxSampler { namespace gig {
142                          Level += Level * Decay2Coeff;                          Level += Level * Decay2Coeff;
143                          pEngine->pSynthesisParameters[ModulationDestination][iSample++] *= Level;                          pEngine->pSynthesisParameters[ModulationDestination][iSample++] *= Level;
144                      }                      }
145                      if (Level <= EG_ENVELOPE_LIMIT) Stage = stage_fadeout;                      if (Level <= CONFIG_EG_BOTTOM) Stage = stage_fadeout;
146                      break;                      break;
147                  }                  }
148                  case stage_sustain: {                  case stage_sustain: {
# Line 169  namespace LinuxSampler { namespace gig { Line 170  namespace LinuxSampler { namespace gig {
170                          Level += Level * ReleaseCoeff;                          Level += Level * ReleaseCoeff;
171                          pEngine->pSynthesisParameters[ModulationDestination][iSample++] *= Level;                          pEngine->pSynthesisParameters[ModulationDestination][iSample++] *= Level;
172                      }                      }
173                      if (Level <= EG_ENVELOPE_LIMIT) Stage = stage_fadeout;                      if (Level <= CONFIG_EG_BOTTOM) Stage = stage_fadeout;
174                      break;                      break;
175                  }                  }
176                  case stage_fadeout: {                  case stage_fadeout: {
# Line 191  namespace LinuxSampler { namespace gig { Line 192  namespace LinuxSampler { namespace gig {
192              }              }
193          }          }
194    
195          #if DEVMODE          #if CONFIG_DEVMODE
196          if (itKillEvent && Stage != stage_end) { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging)          if (itKillEvent && Stage != stage_end) { // FIXME: should be removed before the final release (purpose: just a sanity check for debugging)
197              dmsg(1,("EGADSR: ERROR, voice killing not completed !!!\n"));              dmsg(1,("EGADSR: ERROR, voice killing not completed !!!\n"));
198              dmsg(1,("EGADSR: Stage=%d,iSample=%d,Samples=%d, TotalSamples=%d, MaxFadoutPos=%d\n",Stage,iSample,Samples,TotalSamples,pEngine->MaxFadeOutPos));              dmsg(1,("EGADSR: Stage=%d,iSample=%d,Samples=%d, TotalSamples=%d, MaxFadoutPos=%d\n",Stage,iSample,Samples,TotalSamples,pEngine->MaxFadeOutPos));
199          }          }
200          #endif // DEVMODE          #endif // CONFIG_DEVMODE
201      }      }
202    
203      /**      /**
# Line 216  namespace LinuxSampler { namespace gig { Line 217  namespace LinuxSampler { namespace gig {
217      void EGADSR::Trigger(uint PreAttack, double AttackTime, bool HoldAttack, long LoopStart, double Decay1Time, double Decay2Time, bool InfiniteSustain, uint SustainLevel, double ReleaseTime, uint Delay) {      void EGADSR::Trigger(uint PreAttack, double AttackTime, bool HoldAttack, long LoopStart, double Decay1Time, double Decay2Time, bool InfiniteSustain, uint SustainLevel, double ReleaseTime, uint Delay) {
218          this->TriggerDelay     = Delay;          this->TriggerDelay     = Delay;
219          this->Stage            = stage_attack;          this->Stage            = stage_attack;
220          this->SustainLevel     = (SustainLevel) ? (SustainLevel > EG_ENVELOPE_LIMIT) ? (float) SustainLevel / 1000.0 : EG_ENVELOPE_LIMIT : 1.0;          this->SustainLevel     = (SustainLevel) ? (SustainLevel > CONFIG_EG_BOTTOM) ? (float) SustainLevel / 1000.0 : CONFIG_EG_BOTTOM : 1.0;
221          this->InfiniteSustain  = InfiniteSustain;          this->InfiniteSustain  = InfiniteSustain;
222          this->HoldAttack       = HoldAttack;          this->HoldAttack       = HoldAttack;
223          this->LoopStart        = LoopStart;          this->LoopStart        = LoopStart;
# Line 240  namespace LinuxSampler { namespace gig { Line 241  namespace LinuxSampler { namespace gig {
241    
242          // calculate decay2 stage parameters (exp. curve)          // calculate decay2 stage parameters (exp. curve)
243          if (!InfiniteSustain) {          if (!InfiniteSustain) {
244              if (Decay2Time < EG_MIN_RELEASE_TIME) Decay2Time = EG_MIN_RELEASE_TIME;              if (Decay2Time < CONFIG_EG_MIN_RELEASE_TIME) Decay2Time = CONFIG_EG_MIN_RELEASE_TIME;
245              long Decay2Steps = (long) (Decay2Time * pEngine->pAudioOutputDevice->SampleRate());              long Decay2Steps = (long) (Decay2Time * pEngine->pAudioOutputDevice->SampleRate());
246              Decay2Coeff      = (Decay2Steps) ? exp((log(EG_ENVELOPE_LIMIT) - log(this->SustainLevel)) / Decay2Steps + log(this->SustainLevel)) - this->SustainLevel              Decay2Coeff      = (Decay2Steps) ? exp((log(CONFIG_EG_BOTTOM) - log(this->SustainLevel)) / Decay2Steps + log(this->SustainLevel)) - this->SustainLevel
247                                               : 0.0;                                               : 0.0;
248          }          }
249    
250          // calculate release stage parameters (exp. curve)          // calculate release stage parameters (exp. curve)
251          if (ReleaseTime < EG_MIN_RELEASE_TIME) ReleaseTime = 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
252          ReleaseStepsLeft = (long) (ReleaseTime * pEngine->pAudioOutputDevice->SampleRate());          ReleaseStepsLeft = (long) (ReleaseTime * pEngine->pAudioOutputDevice->SampleRate());
253          ReleaseCoeff     = exp((log(EG_ENVELOPE_LIMIT) - log(this->SustainLevel)) / ReleaseStepsLeft + log(this->SustainLevel)) - this->SustainLevel;          ReleaseCoeff     = exp((log(CONFIG_EG_BOTTOM) - log(this->SustainLevel)) / ReleaseStepsLeft + log(this->SustainLevel)) - this->SustainLevel;
254    
255          dmsg(4,("PreAttack=%d, AttackLength=%d, AttackCoeff=%f, Decay1Coeff=%f, Decay2Coeff=%f, ReleaseLength=%d, ReleaseCoeff=%f\n",          dmsg(4,("PreAttack=%d, AttackLength=%d, AttackCoeff=%f, Decay1Coeff=%f, Decay2Coeff=%f, ReleaseLength=%d, ReleaseCoeff=%f\n",
256                  PreAttack, AttackStepsLeft, AttackCoeff, Decay1Coeff, Decay2Coeff, ReleaseStepsLeft, ReleaseCoeff));                  PreAttack, AttackStepsLeft, AttackCoeff, Decay1Coeff, Decay2Coeff, ReleaseStepsLeft, ReleaseCoeff));

Legend:
Removed from v.396  
changed lines
  Added in v.554

  ViewVC Help
Powered by ViewVC