1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck * |
6 |
* * |
7 |
* This program is free software; you can redistribute it and/or modify * |
8 |
* it under the terms of the GNU General Public License as published by * |
9 |
* the Free Software Foundation; either version 2 of the License, or * |
10 |
* (at your option) any later version. * |
11 |
* * |
12 |
* This program is distributed in the hope that it will be useful, * |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
15 |
* GNU General Public License for more details. * |
16 |
* * |
17 |
* You should have received a copy of the GNU General Public License * |
18 |
* along with this program; if not, write to the Free Software * |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
20 |
* MA 02111-1307 USA * |
21 |
***************************************************************************/ |
22 |
|
23 |
#include "eg_d.h" |
24 |
|
25 |
EG_D::EG_D(ModulationSystem::destination_t ModulationDestination) { |
26 |
this->ModulationDestination = ModulationDestination; |
27 |
} |
28 |
|
29 |
/** |
30 |
* Will be called by the voice for every audio fragment to let the EG |
31 |
* queue it's modulation changes for the current audio fragment. |
32 |
* |
33 |
* @param Samples - total number of sample points to be rendered in this |
34 |
* audio fragment cycle by the audio engine |
35 |
*/ |
36 |
void EG_D::Process(uint Samples) { |
37 |
if (!DecayStepsLeft) return; |
38 |
|
39 |
int iSample = TriggerDelay; |
40 |
int to_process = Min(Samples - iSample, DecayStepsLeft); |
41 |
int process_end = iSample + to_process; |
42 |
DecayStepsLeft -= to_process; |
43 |
while (iSample < to_process) { |
44 |
ModulationSystem::pDestinationParameter[ModulationDestination][iSample++] *= Level; |
45 |
Level += DecayCoeff; |
46 |
} |
47 |
TriggerDelay = 0; |
48 |
} |
49 |
|
50 |
/** |
51 |
* Will be called by the voice when the key / voice was triggered. |
52 |
* |
53 |
* @param Depth - Initial level of the envelope |
54 |
* @param DecayTime - Decay time of the envelope (0.000 - 10.000s) |
55 |
* @param Delay - Number of sample points triggering should be delayed. |
56 |
*/ |
57 |
void EG_D::Trigger(float Depth, double DecayTime, uint Delay) { |
58 |
this->TriggerDelay = Delay; |
59 |
this->Level = Depth; |
60 |
|
61 |
// calculate decay parameters (lin. curve) |
62 |
DecayStepsLeft = (long) (DecayTime * ModulationSystem::SampleRate()); |
63 |
DecayCoeff = (1.0 - Depth) / DecayStepsLeft; |
64 |
|
65 |
dmsg(4,("Depth=%d, DecayTime=%f\n", Depth, DecayTime)); |
66 |
} |