Now that we have a functioning Slider to control our saturation, we need to add a Parameter for the slider to change which we be used to control the amount of saturation.  The amountSlider that we added in the last tutorial will function as a dry/wet control. You will see why we gave it a range of 0 to 1 soon.

Creating A New Parameter

Create a Parameter Pointer

The first thing that we will do is create a pointer for a float parameter in the AudioProcessor.h file like above.  We can also create bool, int, or choice parameters, but for controlling the amount of saturation, we want a float value.  Be sure to declare any parameters as public because we need to be able to access them from the AudioProcessorEditor.  The next thing we need to do is initialize the pointer and create parameter.

Initialize the Parameter

  1. We initialize the AudioParameterFloat to a nullptr.
  2. We add a new parameter by creating a new AudioParameterFloat and assigning it to the pointer. This is all done inside the addParameter function call which will register a parameter for the plugin to manipulate.

The next thing to do is to actually use this parameter to control the amount of saturation that is being applied to the audio signal.

More DSP Theory

processBlock

Inside the processBlock() method where we applied the saturation, we need to make a few changes.  To access the value of a parameter you must de-reference it using an asterisk(*amountParam).  The code above shows how we can make a wet/dry mix for our saturation which will allow us to control the amount. But first, it’s time for a little more simple DSP theory.

As we already know, each sample is represented as a number from -1 to 1.  If we wanted to decrease the volume of the audio by one half, we would just multiply each sample by 0.5 or 1/2.  If we wanted to mute the audio, we would multiply the samples by 0, and if we wanted the full volume we would multiply each sample by 1 which would leave them unaltered.  Now let’s say we had two signals that we want to add together equally, how would we do this?  Since each signal will make up half of the output, we just multiply each signal by 0.5 and then add them together.

Applying The Knowledge

Now it’s time for the tricky part.  How can we take this concept and make a wet/dry mix.  First we have to look at the basics.  We have one output, and two inputs: wet and dry.  So the equation should be something along the lines of output = wet + dry.  The wet part of the signal will be the part that is being saturated and the dry part is the original unaltered data.  So a more refined equation is output = cbrtf(input) + input.  We are almost to what we need but we need a way to calculate how much of each input will be added based on the value of our parameter amountParam.  The parameter is in the range of 0 to 1 for a very specific reason.  To calculate the amount of the wet signal to be used, we just simply multiply the signal by the value of amountParam.  When the parameter is equal to 0 the wet signal will also be 0.  When it is equal to 1, the wet signal will be at full volume.  Calculating the dry signal amount is a little more tricky to understand.  Basically, when amountParam is equal to 0, we want the dry signal to be equal to 1, and when it is equal to 1, we want the dry signal to be equal to 0.  We can do this by multiplying the dry signal by 1 – amountParam.  This makes it so that the sum of the wet and dry signals are always balanced.  The coefficient of the dry signal + the coefficient of the wet signal will add up to 1 for any value of amountParam.

Changing the Value Of The Parameter

Update the Parameter value

The last thing to do is to change the value of the parameter when the value of the slider is changed.  To do this we need to go back to sliderValueChanged() method of the AudioProcessorEditor.  The code above shows how simple this part is.  We can access the AudioProcessor and it’s member variables using processor as a shortcut.  We assign the parameter a new value using the slider->getValue() method which will return the current value of slider.

Conclusion

Parameters are a bit tricky to get the hang of at first, but they are essential in control your plug-in.  I hope this tutorial has been useful to you in understanding how to use a parameter in JUCE.  As always, if you have any questions feel free to leave a comment, post in the forums, or send me an email.  Thanks for reading and I’ll see you next time when we talk about how to add custom graphics to your plug-in!

Sign up for our newsletter so you dont miss new deals and anouncements!

Please follow and like us:
Categories: AudioJUCEProgramming

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Audio

EpicPRESS – Coming Soon!

Keep an eye out for our newest plugin EpicPRESS which will be released by January 1st 2017!  EpicPRESS is a stereo compressor with all of the controls you would expect: threshold, attack, release, ratio, knee, Read more…

Audio

Entropy II Released – VST and AU Plug-in

If you have been using Entropy and enjoy it’s features then I have good news for you.  Entropy II is out!  This version adds many new features such as tempo syncing, feedback filtering, and saturation.  Read more…

Audio

M4 Is Released – VST & AU Plug-in

M4 is finally finished and can now be purchased by heading over to our products page here! http://www.modernmetalproduction.com/products/ If you didn’t see our previous post, let me fill you in. M4 is a Multiband Compressor Read more…