Overdrive Patch

This is the first patch from a series of overdrive / distortion effects.
This one uses a non linear “tube” overdrive curve.
3 parameters: input gain (“drive”), offset, and master level.
You can try and change the overdrive curve to see what it does!```

Class OverdrivePatch : public Patch {

public:
OverdrivePatch();

~OverdrivePatch();

void processAudio(AudioInputBuffer &input, AudioOutputBuffer &output){
int size = input.getSize();
float buf[size];
float gain;
getParameterValue(PARAMETER_D, gain); 		// get output gain value

float drive;
getParameterValue(PARAMETER_A, drive); 		// get input drive value
drive += 0.03;
drive *= 40;
gain/= 2;

float offset;
getParameterValue(PARAMETER_C, offset); 	// get offset value

input.getSamples(0, size, buf);
for(int i=0; i<size; i++)
    buf[i] = gain*nonLinear((buf[i]+offset/10)*drive); // process each sample
output.setSamples(0, size, buf);
}


float nonLinear(float x){ 		// Overdrive curve
if (x<-3)
    return -1;
else if (x>3)
    return 1;
else
    return x * ( 27 + x*x ) / ( 27 + 9*x*x );
}

};

nice to see some distorty effects are already happening :slight_smile:

grokking that overdrive curve is a little tricksy just by looking at it, so something like this may be handy for anyone wanting to fiddle

edit - hmmm, the forum seems not to like this link - http://graphsketch.com/?eqn1_color=1&eqn1_eqn=x%20*%20(%2027%20%2B%20xx%20%29%20%2F%20%28%2027%20%2B%209x*x%20%29&eqn2_color=2&eqn2_eqn=&eqn3_color=3&eqn3_eqn=&eqn4_color=4&eqn4_eqn=&eqn5_color=5&eqn5_eqn=&eqn6_color=6&eqn6_eqn=&x_min=-3&x_max=3&y_min=-1&y_max=1&x_tick=1&y_tick=1&x_label_freq=5&y_label_freq=5&do_grid=0&do_grid=1&bold_labeled_lines=0&bold_labeled_lines=1&line_width=4&image_w=850&image_h=525

Thanks for the graph!
It is actually a CPU friendly approximation of the classical Hyperbolic Tangent (tanh).