# Audio Envelopes

It is often necessary to map an audio parameter to a specific value range over a specific time duration. The most common example is to control the amplitude of an audio event. Time-dependent functions are typically designed to follow linear or exponential trajectories.

## Linear Envelopes

• A linear mapping of parameters can be determined from the equation for a line:

y(t) = m t + b

where m is the slope of the line and b is the point where the line crosses the vertical axis (t=0).

• The line slope is found by .

• In a system such as Matlab, we can plot this expression as y(t) = m (t - t0) + y0, where t0 is the initial time value and y0 is the value of y at t0.

• In an audio processing system, our sample rate is constant and this allows us to simply increment our parameter value by a fixed rate (i.e. slope) value at each time step:

y[n] = m Ts + y[n-1],

where Ts is the sampling period.

• A C language implementation is shown below for each time step:

  if ( state != 0 ) {
if (target > value) {
value += rate;
if (value >= target) {
value = target;
state = 0;
}
}
else {
value -= rate;
if (value <= target) {
value = target;
state = 0;
}
}
}
return value;


## Exponential Envelopes

• Exponential parameter decay and growth patterns are typically perceived as sounding more natural.

• One approach to mapping parameters with "exponential" curves is to make use of the equation:

y(t) = m tb,

where m is a scale factor calculated in a similar way to the linear line slope given above and b is a curvature constant greater than zero.

• Values of the curve parameter b less than 1.0 produce "logarithmic" growth and exponential decay patterns. Values of b greater than 1.0 produce exponential growth and "logarithmic" decay patterns. A value of b = 1.0 corresponds to linear growth and decay.

• The Matlab script curve.m demonstrates the use of the above equation for generating exponential envelopes.

• Another approach to exponential envelopes is to use the general exponential function, , remembering that exponential curves increase/decrease in equal proportion to their current value. This suggests an algorithm of the form:

where , T is the sample period, and is a user provided time constant.

• The Matlab script asymp.m demonstrates the use of this last equation for generating exponential envelopes.

• Note that these curves never actually reach their target value (though a threshold value can be used, within which the current value is simply set equal to the target). This algorithm is especially convenient in situations where a specific time duration is not known.