/[svn]/linuxsampler/trunk/src/eg_d.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/eg_d.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 40 - (show annotations) (download)
Tue Mar 30 13:14:58 2004 UTC (20 years ago) by schoenebeck
File size: 3117 byte(s)
* added Envelope Generator 2 and 3 (filter cutoff EG and pitch EG) for
  accurate .gig playback
* fixed accuracy of pitch calculation
* changed filter cutoff range to 100Hz..10kHz with exponential curve, this
  value range can also be adjusted on compile time by setting
  FILTER_CUTOFF_MIN and FILTER_CUTOFF_MAX in src/voice.h to desired
  frequencies
* src/lfo.h: lfo is now generalized to a C++ template, which will be useful
  especially when we implement further engines

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 }

  ViewVC Help
Powered by ViewVC