dam

dam --  A dynamic compressor/expander.

Description

This opcode dynamically modifies a gain value applied to the input sound ain by comparing its power level to a given threshold level. The signal will be compressed/expanded with different factors regarding that it is over or under the threshold.

Syntax

ar dam asig, kthreshold, icomp1, icomp2, irtime, iftime

Initialization

icomp1 -- compression ratio for upper zone.

icomp2 -- compression ratio for lower zone

irtime -- gain rise time in seconds. Time over which the gain factor is allowed to raise of one unit.

iftime -- gain fall time in seconds. Time over which the gain factor is allowed to decrease of one unit.

Performance

asig -- input signal to be modified

kthreshold -- level of input signal which acts as the threshold. Can be changed at k-time (e.g. for ducking)

Note on the compression factors: A compression ratio of one leaves the sound unchanged. Setting the ratio to a value smaller than one will compress the signal (reduce its volume) while setting the ratio to a value greater than one will expand the signal (augment its volume).

Examples

Because the results of the dam opcode can be subtle, I recommend looking at them in a graphical audio editor program like audacity. audacity is available for Linux, Windows, and the MacOS and may be downloaded from http://audacity.sourceforge.net.

Here is an example of the dam opcode. It uses the files dam.orc, dam.sco, and beats.wav.

Example 1. An example of the dam opcode compressing an audio signal.

/* dam.orc */
/* Written by Kevin Conder */
; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

; Instrument #1, uncompressed signal.
instr 1
  ; Use the "beats.wav" audio file.
  asig soundin "beats.wav"

  out asig
endin

; Instrument #2, compressed signal.
instr 2
  ; Use the "beats.wav" audio file.
  asig soundin "beats.wav"

  ; Compress the audio signal.
  kthreshold init 25000
  icomp1 = 0.5
  icomp2 = 0.763
  irtime = 0.1
  iftime = 0.1
  a1 dam asig, kthreshold, icomp1, icomp2, irtime, iftime

  out a1
endin
/* dam.orc */
        
/* dam.sco */
/* Written by Kevin Conder */
; Play Instrument #1 for 2 seconds.
i 1 0 2
; Play Instrument #2 for 2 seconds.
i 2 2 2
e
/* dam.sco */
        
This example compresses the audio file "beats.wav". You should hear a drum pattern repeat twice. The second time, the sound should be quieter (compressed) than the first.

Here is another example of the dam opcode. It uses the files dam_expanded.orc, dam_expanded.sco, and mary.wav.

Example 2. An example of the dam opcode expanding an audio signal.

/* dam_expanded.orc */
/* Written by Kevin Conder */
; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

; Instrument #1, normal audio signal.
instr 1
  ; Use the "mary.wav" audio file.
  asig soundin "mary.wav"

  out asig
endin

; Instrument #2, expanded audio signal.
instr 2
  ; Use the "mary.wav" audio file.
  asig soundin "mary.wav"

  ; Expand the audio signal.
  kthreshold init 7500
  icomp1 = 2.25
  icomp2 = 2.25
  irtime = 0.1
  iftime = 0.6
  a1 dam asig, kthreshold, icomp1, icomp2, irtime, iftime

  out a1
endin
/* dam_expanded.orc */
        
/* dam_expanded.sco */
/* Written by Kevin Conder */
; Play Instrument #1.
i 1 0.0 3.5
; Play Instrument #2.
i 2 3.5 3.5
e
/* dam_expanded.sco */
        
This example expands the audio file "mary.wav". You should hear a melody repeat twice. The second time, the sound should be louder (expanded) than the first.

Credits

Author: Marc Resibois

Belgium

1997