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 Oscillatorwe wrote earlier and set it to a low frequency.

Let's start with Synthesis.h . Add to private:

Oscillator mLFO;
double lfoFilterModAmount;

lfoFilterModAmountindicates how much the LFO will affect the filter. This parameter must be initialized in the constructor in Synthesis.cpp :


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:


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 isMuteddepends 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:


Now let's set ProcessDoubleReplacingsome LFO values. Replace the loop forwith the following:

for (int i = 0; i < nFrames; ++i) {
    int velocity = mMIDIReceiver.getLastVelocity();
    double lfoFilterModulation = mLFO.nextSample() * lfoFilterModAmount;
    mFilter.setCutoffMod((mFilterEnvelopeGenerator.nextSample() * filterEnvelopeAmount) + lfoFilterModulation);
    leftOutput[i] = rightOutput[i] = mFilter.process(mOscillator.nextSample() * mEnvelopeGenerator.nextSample() * velocity / 127.0);

The value lfoFilterModulationvaries from -1to +1. For the function argument, setCutoffModwe 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 .

Also popular now: