| I have checked in code for a compressor/expander/ducker/gater which I
was given by Barry Vercoe yesterday from Extended Csound and the
fixed-point Csound, and also his code for distort (which explains why
the current opcode is called distort1). I have not had time to check
that it all works as expected, but I will be away for a couple of days
so I thought I would let you see it.
Manual pages also checked in.
==John ffitch
========================================================================
ar compress* aasig, acsig, kthresh, kloknee, khiknee, kratio, katt, krel, ilook
Compress, limit, expand, duck or gate an audio signal.
INITIALIZATION
ilook - lookahead time in seconds, by which an internal envelope
release can sense what is coming. This induces a delay between input
and output, but a small amount of lookahead improves the performance
of the envelope detector. Typical value is .05 seconds, sufficient to
sense the peaks of the lowest frequency in acsig.
PERFORMANCE
This unit functions as an audio compressor, limiter, expander, or
noise gate, using either soft-knee or hard-knee mapping, and with
dynamically variable performance characteristics. It takes two audio
input signals, aasig and acsig, the first of which is modified by a
running analysis of the second. Both signals can be the same, or the
first can be modified by a different controlling signal.
compress first examines the controlling acsig by performing envelope
detection. This is directed by two control values katt and krel,
defining the attack and release time constants (in seconds) of the
detector. The detector rides the peaks (not the RMS) of the control
signal. Typical values are .01 and .1, the latter usually being
similar to ilook.
The running envelope is next converted to decibels, then passed
through a mapping function to determine what compresser action (if
any) should be taken. The mapping function is defined by four decibel
control values. These are given as positive values, where 0 db
corresponds to an amplitude of 1, and 90 db corresponds to an
amplitude of 32768.
kthresh - sets the lowest decibel level that will be allowed through.
Normally 0 or less, but if higher the threshold will begin removing
low-level signal energy such as background noise.
kloknee, khiknee - decibel break-points denoting where compression or
expansion will begin. These set the boundaries of a soft-knee curve
joining the low-amplitude 1:1 line and the higher-amplitude
compression ratio line. Typical values are 48 and 60 db. If the two
breakpoints are equal, a hard-knee (angled) map will result.
kratio - ratio of compression when the signal level is above the
knee. The value 2 will advance the output just one decibel for every
input gain of two; 3 will advance just one in three; 20 just one in
twenty, etc. Inverse ratios will cause signal expansion: .5 gives two
for one, .25 four for one, etc. The value 1 will result in no change.
The actions of compress will depend on the parameter settings given.
A hard-knee compressor-limiter, for instance, is obtained from a
near-zero attack time, equal-value break-points, and a very high ratio
(say 100). A noise-gate plus expander is obtained from some positive
threshold, and a fractional ratio above the knee. A voice-activated
music compressor (ducker) will result from feeding the music into
aasig and the speech into acsig. A voice de-esser will result from
feeding the voice into both, with the acsig version being preceded by
a band-pass filter that emphasizes the sibilants. Each application
will require some experimentation to find the best parameter settings;
these have been made k-variable to make this practical.
Example:
aout compress amus, avoc, 0, 40, 60, 3, .1, .5, .02 ; voice-activated compressor
; with low-level sensitivity
ar distort* asig, kdist, ifn[, ihp, istor]
Distort an audio signal via waveshaping and optional clipping.
INITIALIZATION
ifn -- table number of a waveshaping function with extended guard
point. The function can be of any shape, but it should pass through 0
with positive slope at the table mid-point. The table size need not
be large, since it is read with interpolation.
ihp (optional) -- half-power point (in cps) of an internal low-pass
filter. The default value is 10.
istor (optional) -- initial disposition of internal data space (see
reson). The default value is 0.
PERFORMANCE
This unit distorts an incoming signal using a waveshaping function ifn
and a distortion index kdist. The input signal is first compressed
using a running rms, then passed through a waveshaping function which
may modify its shape and spectrum. Finally it is rescaled to
approximately its original power.
The amount of distortion depends on the nature of the shaping function
and on the value of kdist, which generally ranges from 0 to 1. For
low values of kdist, we should like the shaping function to pass the
signal almost unchanged. This will be the case if, at the mid-point
of the table, the shaping function is near-linear and is passing
through 0 with positive slope. A line function from -1 to +1 will
satisfy this requirement; so too will a sigmoid (sinusoid from 270 to
90 degrees). As kdist is increased, the compressed signal is expanded
to encounter more and more of the shaping function, and if this
becomes non-linear the signal is increasingly -Y´bent¡ on
read-through to cause distortion.
When kdist becomes large enough, the read-through process will
eventually hit the outer limits of the table. The table is not read
with wrap-around, but will ´stick¡ at the end-points as the incoming
signal exceeds them; this introduces clipping, an additional form of
signal distortion. The point at which clipping begins will depend on
the complexity (rms-to-peak value) of the input signal. For a pure
sinusoid, clipping will begin only as kdist exceeds 0.7; for a more
complex input, clipping might begin at a kdist of 0.5 or much less.
kdist can exceed the clip point by any amount, and may be greater than
1.
The shaping function can be made arbitrarily complex for extra effect.
It should generally be continuous, though this is not a requirement.
It should also be well-behaved near the mid-point, and roughly
balanced positive-negative overall, else some excessive DC offset may
result. The user might experiment with more aggressive functions to
suit the purpose. A generally positive slope allows the distorted
signal to be mixed with the source without phase cancellation.
distort is useful as an effects process, and is usually combined with
reverb and chorusing on effects busses. However, it can alternatively
be used to good effect within a single instrument.
Example:
gifn ftgen 0,0, 257, 9, .5,1,270 ; define a sigmoid, or better �
gifn ftgen 0,0, 257, 9, .5,1,270,1.5,.33,90,2.5,.2,270,3.5,.143,90,4.5,.111,270
kdist line 0, 10, 1.2 ; and over 10 seconds
aout distort asig, kdist, gifn ; gradually increase the distortion |