@@ -3,7 +3,7 @@ class LFOProcessor::TypeParameter final : public AudioParameterChoice
3
3
{
4
4
public:
5
5
TypeParameter () :
6
- AudioParameterChoice (" type" , TRANS (" Type" ), getChoices(),
6
+ AudioParameterChoice (ParameterID ( " type" , 1 ) , TRANS (" Type" ), getChoices(),
7
7
static_cast <int > (LFOProcessor::LFOType::sine))
8
8
{
9
9
}
@@ -26,20 +26,24 @@ class LFOProcessor::TypeParameter final : public AudioParameterChoice
26
26
};
27
27
28
28
// ==============================================================================
29
- LFOProcessor::LFOProcessor () :
30
- InternalProcessor (false )
29
+ LFOProcessor::LFOProcessor (double minFreqHz, double maxFreqHz,
30
+ double defaultFreqHz, bool isMult) :
31
+ InternalProcessor (false ),
32
+ isMultiplying (isMult)
31
33
{
32
34
auto layout = createDefaultParameterLayout ();
33
35
34
36
auto tp = std::make_unique<TypeParameter>();
35
37
type = tp.get ();
36
38
layout.add (std::move (tp));
37
39
38
- auto pf = std::make_unique<AudioParameterFloat> (" frequency" , " Frequency" , 0 . 1f , 10 . 0f , 0 . 5f );
40
+ auto pf = std::make_unique<AudioParameterFloat> (ParameterID ( " frequency" , 1 ), " Frequency" , minFreqHz, maxFreqHz, defaultFreqHz );
39
41
frequency = pf.get ();
40
42
layout.add (std::move (pf));
41
43
42
44
resetAPVTSWithLayout (std::move (layout));
45
+
46
+ setLFOType (LFOType::sine);
43
47
}
44
48
45
49
// ==============================================================================
@@ -84,9 +88,6 @@ void LFOProcessor::setLFOType (LFOType lfoType)
84
88
void LFOProcessor::setFrequencyHz (const double newFrequency)
85
89
{
86
90
*frequency = (float ) newFrequency;
87
-
88
- floatOsc.setFrequency ((float ) newFrequency);
89
- doubleOsc.setFrequency (newFrequency);
90
91
}
91
92
92
93
void LFOProcessor::setFrequencyFromMidiNote (const int midiNote)
@@ -119,10 +120,8 @@ void LFOProcessor::prepareToPlay (const double newSampleRate, const int samplesP
119
120
120
121
if (isFirstRun)
121
122
{
122
- isFirstRun = false ;
123
-
124
- setFrequencyHz (*frequency);
125
123
setLFOType (static_cast <LFOType> (type->getIndex ()), true );
124
+ isFirstRun = false ;
126
125
}
127
126
}
128
127
@@ -132,23 +131,35 @@ void LFOProcessor::process (dsp::Oscillator<FloatType>& osc,
132
131
juce::AudioBuffer<FloatType>& multer,
133
132
juce::AudioBuffer<FloatType>& buffer)
134
133
{
135
- if (isBypassed ())
136
- return ;
134
+ {
135
+ auto v = getFrequency ();
136
+ floatOsc.setFrequency ((float ) v);
137
+ doubleOsc.setFrequency (v);
138
+ }
137
139
138
- setFrequencyHz (getFrequency ());
140
+ if (isMultiplying)
141
+ {
142
+ multer.setSize (buffer.getNumChannels (), buffer.getNumSamples (), false , true , true );
143
+ multer.clear ();
139
144
140
- multer.setSize (buffer.getNumChannels (), buffer.getNumSamples (), false , true , true );
141
- multer.clear ();
145
+ dsp::AudioBlock<FloatType> abMulter (multer);
142
146
143
- dsp::AudioBlock<FloatType> abMulter (multer);
147
+ {
148
+ dsp::ProcessContextReplacing<FloatType> context (abMulter);
149
+ context.isBypassed = isBypassed ();
150
+ osc.process (context);
151
+ }
144
152
153
+ dsp::AudioBlock<FloatType> (buffer)
154
+ .multiplyBy (abMulter);
155
+ }
156
+ else
145
157
{
146
- dsp::ProcessContextReplacing<FloatType> context (abMulter);
158
+ dsp::AudioBlock<FloatType> audioBlock (buffer);
159
+ dsp::ProcessContextReplacing<FloatType> context (audioBlock);
160
+ context.isBypassed = isBypassed ();
147
161
osc.process (context);
148
162
}
149
-
150
- dsp::AudioBlock<FloatType> (buffer)
151
- .multiplyBy (abMulter);
152
163
}
153
164
154
165
void LFOProcessor::processBlock (juce::AudioBuffer<float >& buffer, MidiBuffer&) { process (floatOsc, floatMulter, buffer); }
0 commit comments