/[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 3612 - (show annotations) (download) (as text)
Mon Sep 30 18:03:43 2019 UTC (4 years, 6 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6292 byte(s)
Added new LFO implementations:

* Added int math square LFO implementation.

* Added int math saw LFO implementation.

* Added numeric complex nr sine LFO implementation.

* Added public API C++ class "LFO", which is a cluster class
  encapsulating all the sampler's LFO implementations to be used by
  3rd party applications (e.g. by Gigedit).

* Marked class LFOTriangleDiHarmonic as deprecated
  (will be removed in future).

* Added LFOAll.h which includes all LFO implementation's header files.

* Fixed benchmarks/triang.cpp falsely having favoured "int math abs"
  algorithm (since result of 2nd run was not accumulated).

* Added benchmark for saw wave (benchmarks/saw.cpp).

* Added benchmark for sine wave (benchmarks/sine.cpp).

* Added benchmark for square wave (benchmarks/square.cpp).

* Increased amount of benchmarks runs by factor 6 to achieve benchmark
  times which are large enough on modern systems.

* Cleanup of LFO APIs.

* Bumped version (2.1.1.svn18).

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

  ViewVC Help
Powered by ViewVC