Skip to content

dam

A dynamic compressor/expander.

Applies a changing gain to the input signal. Separate compression factors control the target gain above and below a threshold.

Syntax

ares = dam(asig, kthreshold, icomp1, icomp2, irtime, iftime)
ares dam asig, kthreshold, icomp1, icomp2, irtime, iftime

Initialization

icomp1 -- compression ratio above the threshold.

icomp2 -- compression ratio below the threshold.

irtime -- time in seconds to increase gain by one unit. For example, a value of 2 allows gain to rise from 1 to 2 in two seconds, if the target stays at 2 or higher. Zero or negative values apply increases immediately.

iftime -- time in seconds to decrease gain by one unit. Zero or negative values apply decreases immediately.

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)

Gain starts at 1 and moves toward its target without passing it. The rise and fall times set the rate of change, so a smaller gain change takes less time.

The level detector averages the absolute input over 1,000 samples and divides it by the square root of 2. Its response time therefore depends on the sample rate.

A ratio of 1 sets a target gain of 1. Ratios below 1 reduce the level; ratios above 1 raise it. Setting both ratios to 1 leaves the input unchanged.

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 file dam.csd, and drumsMlp.wav.

An example of the dam opcode compressing an audio signal.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac     ;;;RT audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o dam.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1 ;normal audio

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

endin


instr 2 ; compressed audio

kthreshold = 0.2
icomp1 = 0.8
icomp2 = 0.2
irtime = 0.01
iftime = 0.5
asig diskin2 "drumsMlp.wav", 1, 0, 1
asig dam asig, kthreshold, icomp1, icomp2, irtime, iftime
    outs asig, asig
endin

</CsInstruments>
<CsScore>

i 1 0 2
i 2 2.5 8.5

e
</CsScore>
</CsoundSynthesizer>

This example compresses the audio file “drumsMlp.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 file dam_expanded.csd, and drumsMlp.wav.

An example of the dam opcode expanding an audio signal.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac     ;;;RT audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o dam_expanded.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1 

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

endin

instr 2 ;expanded audio

kthreshold = .5
icomp1 = 2
icomp2 = 3
irtime = 0.01
iftime = 0.1

asig diskin2 "drumsMlp.wav", 1, 0, 1
asig dam asig, kthreshold, icomp1, icomp2, irtime, iftime
     outs asig*.2, asig*.2      ;adjust volume of expanded beat

endin

</CsInstruments>
<CsScore>

i 1 0 2
i 2 2.5 6.5

e
</CsScore>
</CsoundSynthesizer>

This example expands the audio file “drumsMlp.wav”. You should hear a drum pattern repeat twice. The second time, the sound should be louder (expanded) than the first. To prevent distortion the volume of the signal has been lowered.

See also

Amplitude Modifiers and Dynamic processing

Credits

Author: Marc Resibois
Belgium
1997

New in version 3.47