/[svn]/linuxsampler/trunk/src/engines/common/EG.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/common/EG.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2055 - (hide annotations) (download)
Sat Jan 30 10:30:02 2010 UTC (14 years, 3 months ago) by persson
File size: 3169 byte(s)
* sfz engine: added support for v2 multiple stage envelope generators
* sfz engine: added a fine-tuned v1 envelope generator instead of
  using the one from the gig engine

1 persson 2055 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * 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 *
9     * it under the terms of the GNU General Public License as published by *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
21     * MA 02110-1301 USA *
22     ***************************************************************************/
23    
24     #include "EG.h"
25    
26     namespace LinuxSampler {
27    
28     EG::EG() {
29     enterEndStage();
30     Level = 0.0;
31     CalculateFadeOutCoeff(CONFIG_EG_MIN_RELEASE_TIME, 44100.0); // even if the sample rate will be 192kHz it won't hurt at all
32     }
33    
34     void EG::CalculateFadeOutCoeff(float FadeOutTime, float SampleRate) {
35     const float killSteps = FadeOutTime * SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE;
36     FadeOutCoeff = -1.0f / killSteps;
37     }
38    
39     void EG::enterFadeOutStage() {
40     Stage = stage_fadeout;
41     Segment = segment_lin;
42     StepsLeft = int(Level / (-FadeOutCoeff));
43     Coeff = FadeOutCoeff;
44     if (StepsLeft <= 0) enterEndStage();
45     }
46    
47     void EG::enterFadeOutStage(int maxFadeOutSteps) {
48     Stage = stage_fadeout;
49     Segment = segment_lin;
50     StepsLeft = int(Level / (-FadeOutCoeff));
51     if (StepsLeft > maxFadeOutSteps) {
52     StepsLeft = maxFadeOutSteps;
53     Coeff = -Level / maxFadeOutSteps;
54     } else {
55     Coeff = FadeOutCoeff;
56     }
57     if (StepsLeft <= 0) enterEndStage();
58     }
59    
60     bool EG::atEnd(event_t Event) {
61     if (Stage == stage_end) return true;
62     if (Stage == stage_fadeout) {
63     if (Event == event_stage_end) enterEndStage();
64     return true;
65     }
66     return false;
67     }
68    
69     void EG::enterEndStage() {
70     Stage = stage_end;
71     Segment = segment_end;
72     Level = 0;
73     }
74     }

  ViewVC Help
Powered by ViewVC