Author: | Christopher Arndt |
---|---|
Date: | 2018-08-11 |
Let's create a plug-in, which generates some audio output itself. It will output a sawtooth wave, whose frequency can be controlled via a plug-in parameter. We'll call the plug-in "SimpleSaw".
We can simply generate the same project as for the SimpleGain plug-in and then change the source code in a few places to make the plug-in do something different. You can see all the changes in detail in this commit in the GitHub repository for the plug-in.
Initialize a new DSP audio plug-in project with cookiecutter and name it
SimpleSaw
.Copy the following files from this repository into the
plugins/SimpleSaw
directory:WaveTableOsc.{c,h}pp
WaveUtils.{c,h}pp
If you download the files via the GitHub web interface, make sure you get the actual raw files, not the HTML pages displaying the source code of the files (use the "Raw" button on the source disply page of each file).
Add these objects to the
OBJ_DSP
list in the Makefile inplugins/SimpleSaw
beforePluginSimpleSaw.cpp.o
(don't forget the backslashes to keep the whole assignment on one logical line):WaveTableOsc.cpp.o \ WaveUtils.cpp.o \
Add
#include "WaveUtils.hpp"
toplugins/SimpleSaw/PluginSimpleSaw.hpp
after the#include
that's already in there.Add
WaveTableOsc *osc;
to theprivate
Section of thePluginSimpleSaw
class inplugins/SimpleSaw/PluginSimpleSaw.hpp
and remove thedouble fSampleRate;
line there.Add
osc = sawOsc();
in the constructor method of thePluginSimpleSaw
class inplugins/SimpleSaw/PluginSimpleSaw.cpp
before theloadProgram(0);
line and remove thesampleRateChanged(getSampleRate());
line.Change every occurence of
paramVolume
toparamFrequency
inplugins/SimpleSaw/PluginSimpleSaw.hpp
andplugins/SimpleSaw/PluginSimpleSaw.cpp
.Change the
initParameter
method of thePluginSimpleSaw
class to set the name and symbol of the parameter to "Frequency" resp. "frequency" and its min/max/default values to20.0
/10000.0
and440.0
;Change the for loop in the
run
method of thePluginSimpleSaw
class to the following:// output the oscillator waveform for (uint32_t i=0; i < frames; ++i) { outL[i] = osc->getOutput() * 0.8; outR[i] = osc->getOutput() * 0.8; osc->updatePhase(); }
and remove the lines initializing the
inpL
,inpR
andvol
variables.Optionally, remove the
input
name from the method parameters, since the plug-in doesn't use the audio inputs.Change the body of the
setParametervalue
method of thePluginSimpleSaw
class to the following:fParams[index] = value; switch (index) { case paramFrequency: osc->setFrequency(value / getSampleRate()); break; }
Change the body of the
loadProgram
method of thePluginSimpleSaw
class to the following:switch (index) { case 0: setParameterValue(paramFrequency, 440.0f); break; }
(Only the second parameter in the call to
setParameterValue
changes.)Change the body of the
sampleRateChanged
method of the PluginSimpleSaw` class to the following single line:osc->setFrequency(fParams[paramFrequency] / newSampleRate);
Set the value of the
DISTRHO_PLUGIN_NUM_INPUTS
pre-processor definition inDistrhoPluginInfo.h
to0
.Compile the plug-in, copy or symlink the LV2 plug-in to
~/.lv2
and test it withjalv
or another LV2 host of your liking.