/[svn]/linuxsampler/trunk/src/lfo.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/lfo.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 39 - (show annotations) (download) (as text)
Sun Mar 21 16:09:43 2004 UTC (20 years, 1 month ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 5770 byte(s)
* implemented all three low frequency oscillators (LFO1 = volume,
  LFO2 = filter cutoff frequency, LFO3 = pitch) for accurate .gig playback

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 #ifndef __LFO_H__
24 #define __LFO_H__
25
26 #include "global.h"
27 #include "rtelmemorypool.h"
28 #include "modulationsystem.h"
29 #include "gig.h"
30
31 /**
32 * Low Frequency Oscillator
33 *
34 * Synthesizes a triangular wave for modulating arbitrary synthesis
35 * parameters.
36 */
37 class LFO {
38 public:
39 /**
40 * Defines how the LFO applies it's values to the synthesis
41 * parameter matrix.
42 */
43 enum manipulation_type_t {
44 manipulation_type_add, ///< Add LFO's values to the synthesis paramter matrix.
45 manipulation_type_multiply ///< Multiply LFO's values with the ones from the synthesis parameter matrix.
46 };
47 /**
48 * Defines the position of the LFO wave within the given value range
49 * and from which value to start when the LFO is triggered.
50 */
51 enum propagation_t {
52 propagation_top_down, ///< Wave level starts from given max. and grows down with growing oscillator depth.
53 propagation_middle_balanced, ///< Wave level starts from the middle of the given value range and grows in both directions with growing oscillator depth.
54 propagation_bottom_up ///< Wave level starts from given min. and grows up with growing oscillator depth.
55 };
56
57 uint8_t ExtController; ///< MIDI control change controller number if the LFO is controlled by an external controller, 0 otherwise.
58
59 LFO(ModulationSystem::destination_t ModulationDestination, manipulation_type_t ManipulationType, float Min, float Max, propagation_t Propagation, RTELMemoryPool<ModulationSystem::Event>* pEventPool);
60 void Process(uint Samples);
61 void Trigger(float Frequency, uint16_t InternalDepth, uint16_t ExtControlDepth, uint16_t ExtControlValue, bool FlipPhase, uint Delay);
62 void Reset();
63 /**
64 * Will be called by the voice to inform the LFO about a change of
65 * the external controller's value.
66 *
67 * @param pEvent - control change event of external controller
68 */
69 inline void SendEvent(ModulationSystem::Event* pEvent) {
70 if (ExtController && pEvent->FragmentPos() >= this->TriggerDelay) pEvents->alloc_assign(*pEvent);
71 }
72 ~LFO();
73 protected:
74 RTEList<ModulationSystem::Event>* pEvents;
75 ModulationSystem::destination_t ModulationDestination;
76 manipulation_type_t ManipulationType;
77 propagation_t Propagation;
78 int TriggerDelay;
79 float Min;
80 float Max;
81 float CurrentMin;
82 float CurrentMax;
83 float FrequencyCoeff;
84 float ExtControlDepthCoeff;
85 float InternalDepth;
86 float Range;
87 float Coeff;
88 float Level;
89
90 inline void RecalculateCoeff(uint16_t ExtControlValue) {
91 float currentrange = InternalDepth + ExtControlValue * ExtControlDepthCoeff;
92 if (currentrange > Range) currentrange = Range;
93 Coeff = (Coeff < 0) ? -(currentrange * FrequencyCoeff)
94 : currentrange * FrequencyCoeff;
95 switch (Propagation) {
96 case propagation_top_down: {
97 CurrentMax = Max;
98 CurrentMin = Max - currentrange;
99 break;
100 }
101 case propagation_middle_balanced: {
102 float rangediff = (Range - currentrange) * 0.5f;
103 CurrentMax = Max - rangediff;
104 CurrentMin = Min + rangediff;
105 break;
106 }
107 case propagation_bottom_up: {
108 CurrentMax = Max - currentrange;
109 CurrentMin = Min;
110 break;
111 }
112 }
113 }
114 };
115
116 #endif // __LFO_H__

  ViewVC Help
Powered by ViewVC