
Creating Audio Plugins, Part 12
- Tutorial
All posts in the series:
Part 1. Introduction and configuration
Part 2. Learning the code
Part 3. VST and AU
Part 4. Digital distortion
Part 5. Presets and GUI
Part 6. Signal synthesis
Part 7. Receiving MIDI messages
Part 8. Virtual keyboard
Part 9 Envelopes
Part 10. Refinement of the GUI
Part 11. Filter
Part 12. Low-frequency oscillator
Part 13. Redesign
Part 14. Polyphony 1
Part 15. Polyphony 2
Part 16. Antialiasing
The low-frequency oscillator ( the Low the Frequency Oscillator, the LFO ) - an important part of any classical synthesizer, and we'll add it to your plugin. As the name implies, this is just an oscillator. We use the class
Let's start with Synthesis.h . Add to
Why exactly
Then a triangular wave, a frequency of 6 Hz is simply selected, and the flag is removed
Since this is an oscillator, we must inform it of changes in the sampling frequency in
Now let's set
The value
That's all, actually! Test - the sound should be slightly pulsating, this is especially noticeable if you select a waveform other than the sine.
The project code at this stage can be downloaded from here .
Next time we’ll do a redesign to make the plugin look nicer:
Original post .
Part 1. Introduction and configuration
Part 2. Learning the code
Part 3. VST and AU
Part 4. Digital distortion
Part 5. Presets and GUI
Part 6. Signal synthesis
Part 7. Receiving MIDI messages
Part 8. Virtual keyboard
Part 9 Envelopes
Part 10. Refinement of the GUI
Part 11. Filter
Part 12. Low-frequency oscillator
Part 13. Redesign
Part 14. Polyphony 1
Part 15. Polyphony 2
Part 16. Antialiasing
The low-frequency oscillator ( the Low the Frequency Oscillator, the LFO ) - an important part of any classical synthesizer, and we'll add it to your plugin. As the name implies, this is just an oscillator. We use the class
Oscillator
we wrote earlier and set it to a low frequency. Let's start with Synthesis.h . Add to
private
:Oscillator mLFO;
double lfoFilterModAmount;
lfoFilterModAmount
indicates how much the LFO will affect the filter. This parameter must be initialized in the constructor in Synthesis.cpp :lfoFilterModAmount(0.1)
Why exactly
0.1
? Here we just want to show the fundamental ease of creating an LFO. We will add separate control knobs to this oscillator later in the redesign phase. At the end of the constructor, add:mLFO.setMode(OSCILLATOR_MODE_TRIANGLE);
mLFO.setFrequency(6.0);
mLFO.setMuted(false);
Then a triangular wave, a frequency of 6 Hz is simply selected, and the flag is removed
isMuted
. If you add controls to the LFO in the interface, the first two functions must be called from OnParamChange
. And the flag isMuted
depends on whether the value of the parameter is equal to zero lfoFilterModAmount
. Since this is an oscillator, we must inform it of changes in the sampling frequency in
Synthesis::Reset
:mLFO.setSampleRate(GetSampleRate());
Now let's set
ProcessDoubleReplacing
some LFO values. Replace the loop for
with the following:for (int i = 0; i < nFrames; ++i) {
mMIDIReceiver.advance();
int velocity = mMIDIReceiver.getLastVelocity();
double lfoFilterModulation = mLFO.nextSample() * lfoFilterModAmount;
mOscillator.setFrequency(mMIDIReceiver.getLastFrequency());
mFilter.setCutoffMod((mFilterEnvelopeGenerator.nextSample() * filterEnvelopeAmount) + lfoFilterModulation);
leftOutput[i] = rightOutput[i] = mFilter.process(mOscillator.nextSample() * mEnvelopeGenerator.nextSample() * velocity / 127.0);
}
The value
lfoFilterModulation
varies from -1
to +1
. For the function argument, setCutoffMod
we add the cutoff frequency controlled by the envelope and the value lfoFilterModulation
, that is, the cut now changes under the influence of two parameters. That's all, actually! Test - the sound should be slightly pulsating, this is especially noticeable if you select a waveform other than the sine.
The project code at this stage can be downloaded from here .
Next time we’ll do a redesign to make the plugin look nicer:
Original post .