Table of Contents:
In this chapter, we will create a distortion plugin. It will be an emulator of a Boss OD-1

Similar to the gain knob, we will create the project, this time titled OD-1. You will add two parameters this time, if you do not remember how to do this reference back to chapter one. The two parameters we will add are Level and drive. Level will be the same as gain from the chapter one, however we will learn something new, being drive.
After you have implemented your parameters and checked for parameter changes, we can start processing again. The way we make distortion is with clipping, which is like giving the wave a haircut, we clip the extremes off to a threshold. There are two types of clipping being soft, and hard clipping. See examples below:
https://www.desmos.com/calculator/yzshjy7pgc
These are implemented as:
//Hard Clipping
float max(float A, float B) {
if (A >= B) { return A; }
else { return B; }
}
float max(float A, float B) {
if (A <= B) { return A; }
else { return B; }
}
float Hard_Clipper(float Sample, float Drive) {
return min(1, max(-1, Drive * Sample));
}
//Soft Clipping
#define float_pi 3.14159
float Soft_Clipper(float Sample, float Drive) {
return (2.f/float_pi) * atan(Drive * Sample);
}
In our processing we have to make sure the gain happens after clipping.
Vst::Sample32* input = data.inputs[0].channelBuffers32[0]
Vst::Sample32* output = data.outputs[0].channelBuffers32[0]
//only left channel processing, remember to do right as well
for (i = 0; i < data.numSamples; i++) {
output = ClippingFunction(input[i], 1 + (9 * mDrive));
output *= 1 + (9 * mLevel);
}