1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 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 "EGDecay.h" |
24 |
|
25 |
namespace LinuxSampler { namespace gig { |
26 |
|
27 |
EGDecay::EGDecay(gig::Engine* pEngine, Event::destination_t ModulationDestination) { |
28 |
this->ModulationDestination = ModulationDestination; |
29 |
this->pEngine = pEngine; |
30 |
} |
31 |
|
32 |
/** |
33 |
* Will be called by the voice for every audio fragment to let the EG |
34 |
* queue it's modulation changes for the current audio fragment. |
35 |
* |
36 |
* @param Samples - total number of sample points to be rendered in this |
37 |
* audio fragment cycle by the audio engine |
38 |
*/ |
39 |
void EGDecay::Process(uint Samples) { |
40 |
if (!DecayStepsLeft) return; |
41 |
|
42 |
int iSample = TriggerDelay; |
43 |
int to_process = RTMath::Min(Samples - iSample, DecayStepsLeft); |
44 |
int process_end = iSample + to_process; |
45 |
DecayStepsLeft -= to_process; |
46 |
while (iSample < to_process) { |
47 |
pEngine->pSynthesisParameters[ModulationDestination][iSample++] *= Level; |
48 |
Level += DecayCoeff; |
49 |
} |
50 |
TriggerDelay = 0; |
51 |
} |
52 |
|
53 |
/** |
54 |
* Will be called by the voice when the key / voice was triggered. |
55 |
* |
56 |
* @param Depth - Initial level of the envelope |
57 |
* @param DecayTime - Decay time of the envelope (0.000 - 10.000s) |
58 |
* @param Delay - Number of sample points triggering should be delayed. |
59 |
*/ |
60 |
void EGDecay::Trigger(float Depth, double DecayTime, uint Delay) { |
61 |
this->TriggerDelay = Delay; |
62 |
this->Level = Depth; |
63 |
|
64 |
// calculate decay parameters (lin. curve) |
65 |
DecayStepsLeft = (long) (DecayTime * pEngine->pAudioOutputDevice->SampleRate()); |
66 |
DecayCoeff = (1.0 - Depth) / DecayStepsLeft; |
67 |
|
68 |
dmsg(4,("Depth=%d, DecayTime=%f\n", Depth, DecayTime)); |
69 |
} |
70 |
|
71 |
}} // namespace LinuxSampler::gig |