/[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 3561 - (show annotations) (download) (as text)
Fri Aug 23 11:44:00 2019 UTC (4 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6723 byte(s)
NKSP: Added standard units support for numbers and final "!" operator:

* NKSP strictness: Variable names, function names and preprocessor condition
  names must start with a regular character (a-z or A-Z); starting them with
  a digit or underscore is no longer allowed.

* NKSP parser fix: equal comparison operator "=" and not equal comparison
  operator "#" must only accept integer operands.

* NKSP language: Implemented support for standard units like Hertz, seconds,
  Bel including support for metric unit prefixes; so one can now e.g.
  conveniently use numbers in scripts like "5us" meaning "5 microseconds",
  or e.g. "12kHz" meaning "12 kilo Hertz", or e.g. "-14mdB" meaning
  "minus 14 Millidecibel", or e.g. "28c" meaning "28 cents" (for tuning).

* NKSP language: Introduced "final" operator "!" which is specifically
  intended for synthesis parameter values to denote that the synthesis
  parameter value is intended to be the "final" value for that synthesis
  parameter that should explicitly be used by the engine and thus causing
  the sampler engine to ignore all other modulation sources for the same
  synthesis parameter (like e.g. LFO, EG); by simply prefixing a value,
  variable or formula with this new "!" operator the expression is marked as
  being "final".

* Bumped version (2.1.1.svn4).

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 "../../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 this->pFinalDepth = NULL;
92 this->pFinalFrequency = NULL;
93 }
94
95 virtual ~LFOBase() {
96 }
97
98 /**
99 * Calculates exactly one sample point of the LFO wave. This
100 * inline method has to be implemented by the descendant.
101 *
102 * @returns next LFO level
103 */
104 //abstract inline float render(); //< what a pity that abstract inliners are not supported by C++98 (probably by upcoming C++0x?)
105
106 /**
107 * Update LFO depth with a new external controller value. This
108 * inline method has to be implemented by the descendant.
109 *
110 * @param ExtControlValue - new external controller value
111 */
112 //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?)
113
114 /**
115 * Will be called by the voice when the key / voice was triggered.
116 *
117 * @param Frequency - frequency of the oscillator in Hz
118 * @param StartLevel - on which level the wave should start
119 * @param InternalDepth - firm, internal oscillator amplitude
120 * @param ExtControlDepth - defines how strong the external MIDI
121 * controller has influence on the
122 * oscillator amplitude
123 * @param FlipPhase - inverts the oscillator wave against
124 * a horizontal axis
125 * @param SampleRate - current sample rate of the engines
126 * audio output signal
127 */
128 virtual void trigger(float Frequency, start_level_t StartLevel, uint16_t InternalDepth, uint16_t ExtControlDepth, bool FlipPhase, unsigned int SampleRate) = 0;
129
130 protected:
131 float Max;
132 float InternalDepth;
133 float Frequency; ///< Internal base frequency for this LFO.
134 float ExtControlValue; ///< The current external MIDI controller value (0-127).
135 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.
136 float ScriptDepthFactor; ///< Usually neutral (1.0), only altered by external RT instrument script functions.
137 float ScriptFrequencyFactor; ///< Usually neutral (1.0), only altered by external RT instrument script functions.
138 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.
139 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.
140 };
141
142 } // namespace LinuxSampler
143
144 #endif // __LS_LFOBASE_H__

  ViewVC Help
Powered by ViewVC