📜 ⬆️ ⬇️

Creating audio plug-ins, part 12

All posts series:
Part 1. Introduction and setup
Part 2. Learning Code
Part 3. VST and AU
Part 4. Digital Distortion
Part 5. Presets and GUI
Part 6. Signal synthesis
Part 7. Receive MIDI Messages
Part 8. Virtual Keyboard
Part 9. Envelopes
Part 10. Refinement 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 (LFO ) is an important component of any classical synthesizer, and we will add it to our 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 basic ease of creating an LFO. We will add individual control knobs to this oscillator later, at the redesign stage. Add to the end of the constructor:

 mLFO.setMode(OSCILLATOR_MODE_TRIANGLE); mLFO.setFrequency(6.0); mLFO.setMuted(false); 


A triangular wave, a frequency of 6 Hz, is simply selected and the isMuted flag is isMuted . If you add controls for the LFO to the interface, the first two functions must be called from OnParamChange . And the isMuted flag depends on whether the value of the lfoFilterModAmount parameter is equal to zero.

Since this is an oscillator, we have to inform him about the changes in the sampling frequency in Synthesis::Reset :

 mLFO.setSampleRate(GetSampleRate()); 


Now let's set some LFO values ​​in ProcessDoubleReplacing . Replace the for loop 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 of lfoFilterModulation varies from -1 to +1 . For the argument to the setCutoffMod function setCutoffMod we add the cut-off frequency controlled by the envelope and the value of lfoFilterModulation , that is, the cut is now changed by two parameters.
That's all! Test - the sound should be slightly pulsating, this is especially noticeable if you choose a waveform that is different from the sine.

The project code at this stage can be downloaded from here .

Next time, let's do some redesign to make the plugin look nicer:



Original post .

Source: https://habr.com/ru/post/227827/


All Articles