/[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 3118 - (show annotations) (download) (as text)
Fri Apr 21 13:33:03 2017 UTC (7 years ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6289 byte(s)
* NKSP: Fixed crash when using built-in script array variable "%ALL_EVENTS".
* NKSP: Added built-in function "change_amp_lfo_depth()".
* NKSP: Added built-in function "change_amp_lfo_freq()".
* NKSP: Added built-in function "change_pitch_lfo_depth()".
* NKSP: Added built-in function "change_pitch_lfo_freq()".
* Bumped version (2.0.0.svn44).

1 /***************************************************************************
2 * *
3 * Copyright (C) 2005 - 2017 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 "../../common/global.h"
25 #include "../../common/RTMath.h"
26
27 // IDs of the two possible implementations
28 // we get the implementation to pick from config.h
29 // the implementation IDs should be the same like in benchmarks/triang.cpp !
30 #define INT_MATH_SOLUTION 2
31 #define DI_HARMONIC_SOLUTION 3
32 #define INT_ABS_MATH_SOLUTION 5
33
34 #include <math.h>
35 #include <stdint.h>
36
37 namespace LinuxSampler {
38
39 // *************** types ***************
40 // *
41
42 /**
43 * Whether the LFO should have positive AND negative value range
44 * (signed) or only a positive value range (unsigned).
45 */
46 enum range_type_t {
47 range_signed, ///< LFO's level will wave between -max ... +max
48 range_unsigned ///< LFO's level will wave between 0 ... +max
49 };
50
51 /**
52 * Defines the start level of the LFO wave within the given value range.
53 */
54 enum start_level_t {
55 start_level_max, ///< wave starts from given max. level
56 start_level_mid, ///< wave starts from the middle of the given value range
57 start_level_min ///< wave starts from given min. level
58 };
59
60 /** @brief LFO (abstract base class)
61 *
62 * Abstract base class for all Low Frequency Oscillator implementations.
63 */
64 template<range_type_t RANGE>
65 class LFOBase {
66 public:
67
68 // *************** attributes ***************
69 // *
70
71 uint8_t ExtController; ///< MIDI control change controller number if the LFO is controlled by an external controller, 0 otherwise.
72
73
74 // *************** methods ***************
75 // *
76
77 /**
78 * Constructor
79 *
80 * @param Max - maximum value of the output levels
81 */
82 LFOBase(float Max) {
83 this->ExtController = 0;
84 this->Max = Max;
85 this->InternalDepth = 0;
86 this->Frequency = 20.f;
87 this->ExtControlValue = 0;
88 this->ExtControlDepthCoeff = 0;
89 this->ScriptDepthFactor = 1.f;
90 this->ScriptFrequencyFactor = 1.f;
91 }
92
93 virtual ~LFOBase() {
94 }
95
96 /**
97 * Calculates exactly one sample point of the LFO wave. This
98 * inline method has to be implemented by the descendant.
99 *
100 * @returns next LFO level
101 */
102 //abstract inline float render(); //< what a pity that abstract inliners are not supported by C++98 (probably by upcoming C++0x?)
103
104 /**
105 * Update LFO depth with a new external controller value. This
106 * inline method has to be implemented by the descendant.
107 *
108 * @param ExtControlValue - new external controller value
109 */
110 //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?)
111
112 /**
113 * Will be called by the voice when the key / voice was triggered.
114 *
115 * @param Frequency - frequency of the oscillator in Hz
116 * @param StartLevel - on which level the wave should start
117 * @param InternalDepth - firm, internal oscillator amplitude
118 * @param ExtControlDepth - defines how strong the external MIDI
119 * controller has influence on the
120 * oscillator amplitude
121 * @param FlipPhase - inverts the oscillator wave against
122 * a horizontal axis
123 * @param SampleRate - current sample rate of the engines
124 * audio output signal
125 */
126 virtual void trigger(float Frequency, start_level_t StartLevel, uint16_t InternalDepth, uint16_t ExtControlDepth, bool FlipPhase, unsigned int SampleRate) = 0;
127
128 protected:
129 float Max;
130 float InternalDepth;
131 float Frequency; ///< Internal base frequency for this LFO.
132 float ExtControlValue; ///< The current external MIDI controller value (0-127).
133 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.
134 float ScriptDepthFactor; ///< Usually neutral (1.0), only altered by external RT instrument script functions.
135 float ScriptFrequencyFactor; ///< Usually neutral (1.0), only altered by external RT instrument script functions.
136 };
137
138 } // namespace LinuxSampler
139
140 #endif // __LS_LFOBASE_H__

  ViewVC Help
Powered by ViewVC