/[svn]/linuxsampler/trunk/src/engines/gig/EGDecay.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/gig/EGDecay.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 319 - (hide annotations) (download)
Mon Dec 13 00:46:42 2004 UTC (19 years, 5 months ago) by schoenebeck
File size: 3493 byte(s)
* introduced 'synthesis mode' to reduce the amount of code and conditionals
  for the current synthesis case in the main synthesis loop
* support for MMX and SSE(1) in the core synthesis algorithms (CPU feature
  detection at runtime, only x86 so far)

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 53 * *
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 schoenebeck 319 * @returns true if there was something to process
39 schoenebeck 53 */
40 schoenebeck 319 bool EGDecay::Process(uint Samples) {
41     if (!DecayStepsLeft) return false;
42 schoenebeck 53
43     int iSample = TriggerDelay;
44     int to_process = RTMath::Min(Samples - iSample, DecayStepsLeft);
45     int process_end = iSample + to_process;
46     DecayStepsLeft -= to_process;
47     while (iSample < to_process) {
48     pEngine->pSynthesisParameters[ModulationDestination][iSample++] *= Level;
49     Level += DecayCoeff;
50     }
51     TriggerDelay = 0;
52 schoenebeck 319
53     return true;
54 schoenebeck 53 }
55    
56     /**
57     * Will be called by the voice when the key / voice was triggered.
58     *
59     * @param Depth - Initial level of the envelope
60     * @param DecayTime - Decay time of the envelope (0.000 - 10.000s)
61     * @param Delay - Number of sample points triggering should be delayed.
62     */
63     void EGDecay::Trigger(float Depth, double DecayTime, uint Delay) {
64     this->TriggerDelay = Delay;
65     this->Level = Depth;
66    
67     // calculate decay parameters (lin. curve)
68     DecayStepsLeft = (long) (DecayTime * pEngine->pAudioOutputDevice->SampleRate());
69     DecayCoeff = (1.0 - Depth) / DecayStepsLeft;
70    
71     dmsg(4,("Depth=%d, DecayTime=%f\n", Depth, DecayTime));
72     }
73    
74     }} // namespace LinuxSampler::gig

  ViewVC Help
Powered by ViewVC