compress
Prev | Orchestra Opcodes and Operators | Next

## compress

compress — Compress, limit, expand, duck or gate an audio signal.

## Description

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 0dbfs/32768, and 90 db corresponds to an amplitude of 0dbfs.

## Syntax

    ar compress aasig, acsig, kthresh, kloknee, khiknee, kratio, katt, krel, ilook

## 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

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.

## Examples

Here is an example of the compress opcode. It uses the file compress.csd.

Example 157. Example of the compress opcode.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    -odac  -iadc    ;;;RT audio out and in
    ; For Non-realtime ouput leave only the line below:
    ; -o compress.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 32
    nchnls = 2
    nchnls_i = 1    ; assume only one mono signal for audio input!
    0dbfs  = 1

    instr 1	; uncompressed signal

    asig diskin2 "drumsMlp.wav", 1, 0, 1
         outs asig, asig
    endin

    instr 2	; compressed signal, use the "drumsMlp.wav" audio file and a soundfile

    avoice  diskin2 "Mathews.wav", 1, 0, 1
    asig   diskin2 "drumsMlp.wav", 1, 0, 1
    prints "***compressing according to Mathews.wav***\n\n"
      kthresh = 0
      kloknee = 40
      khiknee = 60
      kratio  = 5
      katt    = 0.01
      krel    = .1
      ilook   = .02
    asig  compress asig, avoice, kthresh, kloknee, khiknee, kratio, katt, krel, ilook	; voice-activated compressor
          outs asig, asig
    endin

    instr 3	; compressed signal, use the "drumsMlp.wav" audio file and a mic

    avoice in                                     ; duck the audio signal "drumsMlp.wav" with your voice.
    asig   diskin2 "drumsMlp.wav", 1, 0, 1
    prints "***compressing according to your mic -- if present***\n\n"
      kthresh = 0
      kloknee = 40
      khiknee = 60
      kratio  = 3
      katt    = 0.1
      krel    = .5
      ilook   = .02
    asig  compress asig, avoice, kthresh, kloknee, khiknee, kratio, katt, krel, ilook	; voice-activated compressor
          outs asig, asig
    endin

    </CsInstruments>
    <CsScore>
    s
    i1 0 4
    s
    i2 0 16
    s
    i3 0 30
    e
    </CsScore>
    </CsoundSynthesizer>

## See also

Amplitude Modifiers and Dynamic processing

## Credits

Written by Barry L. Vercoe for Extended Csound and released in csound5.02.

Prev | Up | Next
compilestr | Home | compress2