1
+ // ==============================================================================
1
2
namespace oscillatorFunctions
2
3
{
3
4
/* * */
@@ -29,8 +30,77 @@ namespace oscillatorFunctions
29
30
constexpr auto one = static_cast <FloatType> (1 );
30
31
return phase > static_cast <FloatType> (0 ) ? one : -one;
31
32
}
33
+
34
+ // ==============================================================================
35
+ /* * */
36
+ struct NoiseFunctionGenerator
37
+ {
38
+ NoiseFunctionGenerator () noexcept = default ;
39
+ virtual ~NoiseFunctionGenerator () noexcept = default ;
40
+ };
41
+
42
+ /* * White noise generator using Gaussian distribution. */
43
+ struct WhiteNoiseGenerator final : NoiseFunctionGenerator
44
+ {
45
+ WhiteNoiseGenerator () noexcept = default ;
46
+
47
+ template <typename FloatType>
48
+ FloatType process (FloatType) noexcept { return static_cast <FloatType> (dist (generator)); }
49
+
50
+ private:
51
+ std::default_random_engine generator;
52
+ std::normal_distribution<double > dist;
53
+
54
+ JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WhiteNoiseGenerator)
55
+ };
56
+
57
+ /* * Pink noise generator. */
58
+ struct PinkNoiseGenerator final : NoiseFunctionGenerator
59
+ {
60
+ PinkNoiseGenerator () noexcept = default ;
61
+
62
+ template <typename FloatType>
63
+ FloatType process (FloatType) noexcept { return static_cast <FloatType> (dist (generator)); }
64
+
65
+ private:
66
+ std::default_random_engine generator;
67
+ std::normal_distribution<double > dist;
68
+
69
+ JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PinkNoiseGenerator)
70
+ };
71
+
72
+ /* * Blue noise generator. */
73
+ struct BlueNoiseGenerator final : NoiseFunctionGenerator
74
+ {
75
+ BlueNoiseGenerator () noexcept = default ;
76
+
77
+ template <typename FloatType>
78
+ FloatType process (FloatType) noexcept { return static_cast <FloatType> (dist (generator)); }
79
+
80
+ private:
81
+ std::default_random_engine generator;
82
+ std::normal_distribution<double > dist;
83
+
84
+ JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BlueNoiseGenerator)
85
+ };
86
+
87
+ /* * Brownian noise generator. */
88
+ struct BrownianNoiseGenerator final : NoiseFunctionGenerator
89
+ {
90
+ BrownianNoiseGenerator () noexcept = default ;
91
+
92
+ template <typename FloatType>
93
+ FloatType process (FloatType) noexcept { return static_cast <FloatType> (dist (generator)); }
94
+
95
+ private:
96
+ std::default_random_engine generator;
97
+ std::normal_distribution<double > dist;
98
+
99
+ JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BrownianNoiseGenerator)
100
+ };
32
101
}
33
102
103
+ // ==============================================================================
34
104
/* * A processor that can act as an LFO or a function generator.
35
105
36
106
This acts as an LFO by default. You may want to use its
@@ -65,23 +135,32 @@ class LFOProcessor final : public InternalProcessor
65
135
triangle,
66
136
ramp,
67
137
sawtooth,
68
- square
138
+ square,
139
+ whiteNoise,
140
+ pinkNoise,
141
+ blueNoise,
142
+ brownianNoise
69
143
};
70
144
71
- /* * */
145
+ /* * Changes the current LFO function. */
72
146
void setLFOType (LFOType);
73
147
74
- /* * */
148
+ /* * @returns the currently used LFO function. s */
75
149
LFOType getLFOType () const ;
76
150
77
- /* * */
151
+ /* * Changes the frequency of the LFO in Hz. */
78
152
void setFrequencyHz (double );
79
153
80
- /* * */
154
+ /* * Changes the frequency of the LFO using a MIDI note pitch. */
81
155
void setFrequencyFromMidiNote (int );
82
156
83
- /* * */
84
- double getFrequency () const ;
157
+ /* * Changes the frequency of the LFO using a simple pitch. */
158
+ void setFrequency (const Pitch&);
159
+
160
+ /* * @returns the currently set frequency in Hz. */
161
+ double getFrequencyHz () const ;
162
+ /* * @returns the currently set frequency as a Pitch object. */
163
+ Pitch getFrequencyPitch () const ;
85
164
86
165
// ==============================================================================
87
166
/* * @internal */
@@ -100,6 +179,11 @@ class LFOProcessor final : public InternalProcessor
100
179
const bool isMultiplying = true ;
101
180
bool isFirstRun = true ;
102
181
182
+ oscillatorFunctions::WhiteNoiseGenerator whiteNoiseGenerator;
183
+ oscillatorFunctions::PinkNoiseGenerator pinkNoiseGenerator;
184
+ oscillatorFunctions::BlueNoiseGenerator blueNoiseGenerator;
185
+ oscillatorFunctions::BrownianNoiseGenerator brownianNoiseGenerator;
186
+
103
187
juce::AudioBuffer<float > floatMulter;
104
188
juce::AudioBuffer<double > doubleMulter;
105
189
0 commit comments