# EZDSP Example Patches

All example patches are included with the EZDSP plugin. These examples are the best way to understand how EZDSP works, and provide users with a basic starting point for a various types of digital effects.

## EZ Distortion

#### Complexity: Beginner

A simple distortion unit that applies a sigmoid function to the incoming signal

For this effect we’ll need to create just one slider component:

SLIDER: Variable Name = DRIVE, Min Value = -10, Max Value = 50, Initial Value = 0, Step = 1,

### Step 2: Add digital signal processing

Now let’s add some DSP code to turn these components into a delay unit:

``````let masterGain = pow (10.0f, GAIN * 0.05f); // 
let driveGain = pow (10.0f, DRIVE * 0.05f); // 
let driveSig = driveGain * audioIn; // 

float distSig;

if (driveSig > 0) // 
{
distSig = 1 - pow(2.718f, -driveSig);
} else
{
distSig = -1 + pow(2.718f, driveSig);
}

audioOut << distSig * masterGain / driveGain; // 

``````

: Convert the gain slider’s decibel value into a gain factor multiplier
: Convert the drive slider’s decibel value into a gain factor multiplier
: Multiple the current audio sample by the drive gain
: Check the polarity of the current audio sample so that it can be preserved. Apply the distortion formula: \$f(x) = signalPolarity * (1-e^{-|x|})\$
: Output the distorted audio sample multiplied by the master gain divided by the drive gain.

*We multiply by the drive gain at the beginning, and divide by the drive gain at the end, allowing the drive slider to increase/decrease the distortion level without controlling the overall gain (although applying heavy distortion will audibly decrease the volume).

## EZ Delay

#### Complexity: Intermediate

A simple delay unit with controls for delay length and feedback

For this effect we’ll need to create three components (two sliders and a buffer):

SLIDER: Variable Name = DELAY, Min Value = 0, Max Value = 1, Initial Value = 0, Step = .01
SLIDER: Variable Name = FEEDBACK, Min Value = 0, Max Value = 100, Initial Value = 0, Step = 1
BUFFER: Data Type = Float, Size = 44100, Name = DelayBuffer,

### Step 2: Add digital signal processing

Now let’s add some DSP code to turn these components into a delay unit:

``````let masterGain = pow (10.0f, GAIN * 0.05f); // 

let audioDelayed = (FEEDBACK/100) * DelayBuffer[DelayBufferIndex-int(DELAY*SAMPLERATE)];   // 

DelayBuffer[DelayBufferIndex] = audioIn + audioDelayed; // 

audioOut << (DelayBuffer[DelayBufferIndex-int(DELAY*SAMPLERATE)] + audioIn) * masterGain; // 

++DelayBufferIndex; // 

``````

Here’s what each line of code does:

: Convert the gain slider’s decibel value into a gain factor multiplier
: Multiply a delayed audio sample by a feedback scale factor and store it in a variable
: Add the current audio sample to the delayed audio sample and store in the current position of the delay buffer
: Output the current audio sample and a delayed audio sample from the delay buffer, multiplied by the master gain
: Increase the current position of the delay buffer by one sample

## EZ Filter

A simple filter that can function as either a low-pass or high-pass

For this effect we’ll need to create two components (one slider and one button):

SLIDER: Variable Name = CUTOFF, Min Value = 100, Max Value = 20000, Initial Value = 1000, Step = 100
BUTTON: Variable Name = lowOrHi

### Step 2: Add digital signal processing

Now let’s add some DSP code to turn these components into a delay unit:

``````soul::filters::biquad::State s;  //

loop    //
{
for (wrap<c.size> i)    //
{
soul::filters::rbj_eq::update(c[i], SAMPLERATE, int(lowOrHi), CUTOFF, 0.5, 0.0);    //
c.at (i).setNormalised (c[i]); //
}

let masterGain = pow (10.0f, GAIN * 0.05f); //

}

``````

Here’s what each line of code does:

: Initialize a SOUL object for storing an array of biquad filter states
: Initialize a SOUL object that stores an array of biquad filter coefficients
: Create an infinite loop. Note that while all EZDSP code is executed in an outter loop by default, users can create their own inner loops to process samples in chunks. In this case, an inner loop is initialized to prevent the biquad state/coefficient variables from being reinitialized every sample
: Use a for-loop to iterate through the coefficient array
: Generate an updated set of filter’s coefficients using SOUL’s implementation of Robert Bristow-Johnson’s biquad EQ, 2nd IIR filter.

This function is defined as: void update (biquad::Coeffs& c, float64 sampleRate, int32 mode, float64 freqHz, float64 quality, float64 gaindB)

: Apply the updated filter coefficients
:Convert the gain slider’s decibel value into a gain factor multiplier
:Apply the filter to the current audio sample and output the result multiplied by the master gain