ConstantGainDistortion:
Filter:
ddwCommon/Classes (extension) | UGens > Distortion

ConstantGainDistortion
ExtensionExtension

Applies a distortion function with volume compensation

Description

ConstantGainDistortion applies a distortion function of your choosing, and adjusts the output gain to match the input signal (by RMS).

Rationale: Distortion effects are usually volume-dependent, resulting in a wide output dynamic range. This complicates mixing in a live situation; as you increase the distortion preamp, you may need to reduce channel volume simultaneously. By matching output volume to the input, you get the spectral effect of the distortion without a large increase in volume.

It is not recommended to modulate preamp very rapidly (because the RMS calculations need a little time to catch up). Slow modulation is fine.

The RMS quotient may introduce a small amount of amplitude modulation. Large rmsSize values will reduce the amount of amplitude modulation, but may affect envelope transients. Small rmsSize values may exhibit greater amplitude modulation.

Class Methods

.ar

Add the distortion UGens, at audio rate.

Arguments:

in

Input signal.

preamp

Pre-distortion gain factor, as a simple multiplier (1.0 = 0 dB; 2.0 ~= +6 dB).

distFunc

A function, whose argument will receive in * preamp, and whose output should be the desired distortion effect. The default is _.tanh (see Partial Application for details on the underscore syntax).

rmsSize

The number of samples for RMS calculation.

.kr

Same functionality, just at control rate.

Examples

The example shows you the measured volume of two signals: 1/ simple distortion = (sig * preamp).tanh, and 2/ ConstantGainDistortion. Without volume compensation, the dynamic range is over 20 dB (for preamp ranging -20 dB to +40 dB). With volume compensation, the dynamic range is about half a dB. (The output audio signal is the volume-compensated distortion.)