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