1 |
iliev |
2223 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* Copyright (C) 2005 Christian Schoenebeck * |
4 |
|
|
* Copyright (C) 2011 Christian Schoenebeck and Grigor Iliev * |
5 |
|
|
* * |
6 |
|
|
* This library is free software; you can redistribute it and/or modify * |
7 |
|
|
* it under the terms of the GNU General Public License as published by * |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
9 |
|
|
* (at your option) any later version. * |
10 |
|
|
* * |
11 |
|
|
* This library is distributed in the hope that it will be useful, * |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 |
|
|
* GNU General Public License for more details. * |
15 |
|
|
* * |
16 |
|
|
* You should have received a copy of the GNU General Public License * |
17 |
|
|
* along with this library; if not, write to the Free Software * |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
19 |
|
|
* MA 02111-1307 USA * |
20 |
|
|
***************************************************************************/ |
21 |
|
|
|
22 |
|
|
#ifndef __LS_SINELFO_H__ |
23 |
|
|
#define __LS_SINELFO_H__ |
24 |
|
|
|
25 |
|
|
#include "LFOBase.h" |
26 |
|
|
|
27 |
|
|
namespace LinuxSampler { |
28 |
|
|
|
29 |
|
|
/** @brief sine LFO |
30 |
|
|
*/ |
31 |
|
|
template<range_type_t RANGE> |
32 |
|
|
class SineLFO : public LFOBase<RANGE> { |
33 |
|
|
public: |
34 |
|
|
|
35 |
|
|
/** |
36 |
|
|
* Constructor |
37 |
|
|
* |
38 |
|
|
* @param Max - maximum value of the output levels |
39 |
|
|
*/ |
40 |
|
|
SineLFO(float Max) : LFOBase<RANGE>::LFOBase(Max) { |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
/** |
44 |
|
|
* Calculates exactly one sample point of the LFO wave. |
45 |
|
|
* |
46 |
|
|
* @returns next LFO level |
47 |
|
|
*/ |
48 |
|
|
inline float render() { |
49 |
|
|
uiLevel += c; |
50 |
|
|
if (RANGE == range_unsigned) |
51 |
|
|
return normalizer * (sin(c2 * (float)uiLevel) + 1.0f); |
52 |
|
|
else /* signed range */ |
53 |
|
|
return normalizer * sin(c2 * (float)uiLevel); |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
/** |
57 |
|
|
* Update LFO depth with a new external controller value. |
58 |
|
|
* |
59 |
|
|
* @param ExtControlValue - new external controller value |
60 |
|
|
*/ |
61 |
|
|
inline void update(const uint16_t& ExtControlValue) { |
62 |
|
|
const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF... |
63 |
|
|
const float max = this->InternalDepth + ExtControlValue * this->ExtControlDepthCoeff; |
64 |
|
|
if (RANGE == range_unsigned) { |
65 |
|
|
normalizer = max / 2.0f; |
66 |
|
|
} else { // signed range |
67 |
|
|
normalizer = max; |
68 |
|
|
} |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
/** |
72 |
|
|
* Will be called by the voice when the key / voice was triggered. |
73 |
|
|
* |
74 |
|
|
* @param Frequency - frequency of the oscillator in Hz |
75 |
|
|
* @param StartLevel - not implemented |
76 |
|
|
* @param InternalDepth - firm, internal oscillator amplitude |
77 |
|
|
* @param ExtControlDepth - defines how strong the external MIDI |
78 |
|
|
* controller has influence on the |
79 |
|
|
* oscillator amplitude |
80 |
|
|
* @param FlipPhase - not implemented |
81 |
|
|
* @param SampleRate - current sample rate of the engines |
82 |
|
|
* audio output signal |
83 |
|
|
*/ |
84 |
|
|
virtual void trigger(float Frequency, start_level_t StartLevel, uint16_t InternalDepth, uint16_t ExtControlDepth, bool FlipPhase, unsigned int SampleRate) { |
85 |
|
|
this->InternalDepth = (InternalDepth / 1200.0f) * this->Max; |
86 |
|
|
this->ExtControlDepthCoeff = (((float) ExtControlDepth / 1200.0f) / 127.0f) * this->Max; |
87 |
|
|
|
88 |
|
|
const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF... |
89 |
|
|
const float r = Frequency / (float) SampleRate; // frequency alteration quotient |
90 |
|
|
c = (int) (intLimit * r); |
91 |
|
|
c2 = (2.0f * M_PI) / (float) intLimit; |
92 |
|
|
|
93 |
|
|
uiLevel = 0; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
protected: |
97 |
|
|
unsigned int uiLevel; |
98 |
|
|
int c; |
99 |
|
|
float c2; |
100 |
|
|
float normalizer; |
101 |
|
|
}; |
102 |
|
|
|
103 |
|
|
} // namespace LinuxSampler |
104 |
|
|
|
105 |
|
|
#endif // __LS_SINELFO_H__ |