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 library 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 * |
10 |
* the Free Software Foundation; either version 2 of the License, or * |
* the Free Software Foundation; either version 2 of the License, or * |
11 |
* (at your option) any later version. * |
* (at your option) any later version. * |
12 |
* * |
* * |
13 |
* This program is distributed in the hope that it will be useful, * |
* This library is distributed in the hope that it will be useful, * |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
* GNU General Public License for more details. * |
* GNU General Public License for more details. * |
17 |
* * |
* * |
18 |
* You should have received a copy of the GNU General Public License * |
* You should have received a copy of the GNU General Public License * |
19 |
* along with this program; if not, write to the Free Software * |
* along with this library; if not, write to the Free Software * |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
25 |
|
|
26 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
27 |
|
|
28 |
EGDecay::EGDecay(gig::Engine* pEngine, Event::destination_t ModulationDestination) { |
EGDecay::EGDecay() { |
|
this->ModulationDestination = ModulationDestination; |
|
|
this->pEngine = pEngine; |
|
29 |
} |
} |
30 |
|
|
31 |
/** |
void EGDecay::trigger(float Depth, float DecayTime, unsigned int SampleRate) { |
32 |
* Will be called by the voice for every audio fragment to let the EG |
this->Level = Depth; |
|
* queue it's modulation changes for the current audio fragment. |
|
|
* |
|
|
* @param Samples - total number of sample points to be rendered in this |
|
|
* audio fragment cycle by the audio engine |
|
|
* @returns true if there was something to process |
|
|
*/ |
|
|
bool EGDecay::Process(uint Samples) { |
|
|
if (!DecayStepsLeft) return false; |
|
|
|
|
|
int iSample = TriggerDelay; |
|
|
int to_process = RTMath::Min(Samples - iSample, DecayStepsLeft); |
|
|
int process_end = iSample + to_process; |
|
|
DecayStepsLeft -= to_process; |
|
|
while (iSample < to_process) { |
|
|
pEngine->pSynthesisParameters[ModulationDestination][iSample++] *= Level; |
|
|
Level += DecayCoeff; |
|
|
} |
|
|
TriggerDelay = 0; |
|
|
|
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Will be called by the voice when the key / voice was triggered. |
|
|
* |
|
|
* @param Depth - Initial level of the envelope |
|
|
* @param DecayTime - Decay time of the envelope (0.000 - 10.000s) |
|
|
* @param Delay - Number of sample points triggering should be delayed. |
|
|
*/ |
|
|
void EGDecay::Trigger(float Depth, double DecayTime, uint Delay) { |
|
|
this->TriggerDelay = Delay; |
|
|
this->Level = Depth; |
|
33 |
|
|
34 |
// calculate decay parameters (lin. curve) |
// calculate decay parameters (lin. curve) |
35 |
DecayStepsLeft = (long) (DecayTime * pEngine->pAudioOutputDevice->SampleRate()); |
StepsLeft = (int) (DecayTime * SampleRate); |
36 |
DecayCoeff = (1.0 - Depth) / DecayStepsLeft; |
Coeff = (1.0f - Depth) / (float) StepsLeft; |
37 |
|
|
38 |
dmsg(4,("Depth=%d, DecayTime=%f\n", Depth, DecayTime)); |
dmsg(4,("Depth=%d, DecayTime=%f\n", Depth, DecayTime)); |
39 |
} |
} |