/[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 285 by schoenebeck, Thu Oct 14 21:31:26 2004 UTC revision 563 by schoenebeck, Sun May 22 20:43:32 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 61  namespace LinuxSampler { namespace gig { Line 62  namespace LinuxSampler { namespace gig {
62          int Samples = (itKillEvent) ? RTMath::Min(itKillEvent->FragmentPos(), pEngine->MaxFadeOutPos) : (int) TotalSamples;          int Samples = (itKillEvent) ? RTMath::Min(itKillEvent->FragmentPos(), pEngine->MaxFadeOutPos) : (int) TotalSamples;
63    
64          int iSample = TriggerDelay;          int iSample = TriggerDelay;
65    
66            #if CONFIG_DEVMODE
67            if (TriggerDelay > TotalSamples) { // just a sanity check for debugging
68                dmsg(1,("EGADSR: ERROR, TriggerDelay > Totalsamples\n"));
69                int* i = NULL;
70                (*i)++; // force a segfault
71            }
72            #endif // CONFIG_DEVMODE
73    
74          while (iSample < TotalSamples) {          while (iSample < TotalSamples) {
75    
76              // if the voice was killed in this fragment and we already processed the time before this kill event              // if the voice was killed in this fragment and we already processed the time before this kill event
# Line 76  namespace LinuxSampler { namespace gig { Line 86  namespace LinuxSampler { namespace gig {
86                          Level += AttackCoeff;                          Level += AttackCoeff;
87                          pEngine->pSynthesisParameters[ModulationDestination][iSample++] *= Level;                          pEngine->pSynthesisParameters[ModulationDestination][iSample++] *= Level;
88                      }                      }
89                      if (iSample == TotalSamples) { // postpone last transition event for the next audio fragment                      if (iSample == TotalSamples && itTransitionEvent) { // postpone last transition event for the next audio fragment
90                          RTList<Event>::Iterator itLastEvent = pEvents->last();                          RTList<Event>::Iterator itLastEvent = pEvents->last();
91                          if (itLastEvent) ReleasePostponed = (itLastEvent->Type == Event::type_release);                          if (itLastEvent) ReleasePostponed = (itLastEvent->Type == Event::type_release);
92                      }                      }
# Line 132  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 160  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 182  namespace LinuxSampler { namespace gig { Line 192  namespace LinuxSampler { namespace gig {
192              }              }
193          }          }
194    
195          if (itKillEvent && Stage != stage_end) {          #if CONFIG_DEVMODE
196              dmsg(1,("EGADSR: VOICE KILLING NOT COMPLETED !!!\n"));          if (itKillEvent && Stage != stage_end) { // just a sanity check for debugging
197                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 // CONFIG_DEVMODE
201      }      }
202    
203      /**      /**
# Line 205  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 229  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.285  
changed lines
  Added in v.563

  ViewVC Help
Powered by ViewVC