/[svn]/linuxsampler/trunk/src/engines/common/LFOBase.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/common/LFOBase.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3625 - (show annotations) (download) (as text)
Thu Oct 3 13:37:25 2019 UTC (4 years, 5 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6244 byte(s)
* gig format extension: Added support for different LFO wave forms
  (currently either sine [default], triangle, saw or square).

* gig format extension: Added support for LFO phase displacement
  (0°..360°).

* gig format extension: Added support for flipping LFO polarity on LFO 3
  (in the original gig format this was only available for LFO 1 and LFO 2).

* Bumped version (2.1.1.svn22).

1 /***************************************************************************
2 * *
3 * Copyright (C) 2005 - 2019 Christian Schoenebeck *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This library is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this library; if not, write to the Free Software *
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
18 * MA 02111-1307 USA *
19 ***************************************************************************/
20
21 #ifndef __LS_LFOBASE_H__
22 #define __LS_LFOBASE_H__
23
24 #include "../LFO.h"
25 #include "../../common/RTMath.h"
26
27 #include <math.h>
28 #include <stdint.h>
29
30 namespace LinuxSampler {
31
32 /** @brief POD base for all LFO implementations.
33 *
34 * This structure acts as POD (Plain Old Data structure) base for all LFO
35 * implementations. For efficiency reasons all our LFOs are C++ template
36 * classes. By deriving all those LFO C++ templase classes from this
37 * POD structure, it allows us to at least do a unified @code delete for
38 * any LFO object, which would not work on @code void* pointers (correctly).
39 *
40 * ATM this is actually only used in LFO.cpp.
41 */
42 struct LFOPOD {
43 };
44
45 /** @brief LFO (abstract base class)
46 *
47 * Abstract base class for all Low Frequency Oscillator implementations.
48 */
49 template<LFO::range_type_t RANGE>
50 class LFOBase : public LFOPOD {
51 public:
52
53 // *************** attributes ***************
54 // *
55
56 uint8_t ExtController; ///< MIDI control change controller number if the LFO is controlled by an external controller, 0 otherwise.
57
58
59 // *************** methods ***************
60 // *
61
62 /**
63 * Constructor
64 *
65 * @param Max - maximum value of the output levels
66 */
67 LFOBase(float Max) {
68 this->ExtController = 0;
69 this->Max = Max;
70 this->InternalDepth = 0;
71 this->Frequency = 20.f;
72 this->ExtControlValue = 0;
73 this->ExtControlDepthCoeff = 0;
74 this->ScriptDepthFactor = 1.f;
75 this->ScriptFrequencyFactor = 1.f;
76 this->pFinalDepth = NULL;
77 this->pFinalFrequency = NULL;
78 }
79
80 /**
81 * Calculates exactly one sample point of the LFO wave. This
82 * inline method has to be implemented by the descendant.
83 *
84 * @returns next LFO level
85 */
86 //abstract inline float render(); //< what a pity that abstract inliners are not supported by C++98 (probably by upcoming C++0x?)
87
88 /**
89 * Update LFO depth with a new external controller value. This
90 * inline method has to be implemented by the descendant.
91 *
92 * @param ExtControlValue - new external controller value
93 */
94 //abstract inline void updateByMIDICtrlValue(const uint16_t& ExtControlValue); //< what a pity that abstract inliners are not supported by C++98 (probably by upcoming C++0x?)
95
96 /**
97 * Will be called by the voice when the key / voice was triggered.
98 *
99 * @param Frequency - frequency of the oscillator in Hz
100 * @param StartLevel - on which level the wave should start
101 * @param InternalDepth - firm, internal oscillator amplitude
102 * @param ExtControlDepth - defines how strong the external MIDI
103 * controller has influence on the
104 * oscillator amplitude
105 * @param FlipPhase - inverts the oscillator wave against
106 * a horizontal axis
107 * @param SampleRate - current sample rate of the engines
108 * audio output signal
109 */
110 virtual void trigger(float Frequency, LFO::start_level_t StartLevel, uint16_t InternalDepth, uint16_t ExtControlDepth, bool FlipPhase, unsigned int SampleRate) = 0;
111
112 protected:
113 float Max;
114 float InternalDepth;
115 float Frequency; ///< Internal base frequency for this LFO.
116 float ExtControlValue; ///< The current external MIDI controller value (0-127).
117 float ExtControlDepthCoeff; ///< A usually constant factor used to convert a new MIDI controller value from range 0-127 to the required internal implementation dependent value range.
118 float ScriptDepthFactor; ///< Usually neutral (1.0), only altered by external RT instrument script functions.
119 float ScriptFrequencyFactor; ///< Usually neutral (1.0), only altered by external RT instrument script functions.
120 float* pFinalDepth; ///< Usually NULL; it may be set to one of above's member variables in order to process that and ignore all other sources for LFO depth.
121 float* pFinalFrequency; ///< Usually NULL; it may be set to one of above's member variables in order to process that and ignore all other sources for LFO frequency.
122 };
123
124 } // namespace LinuxSampler
125
126 #endif // __LS_LFOBASE_H__

  ViewVC Help
Powered by ViewVC