clip
Clips an a-rate signal to a predefined limit, in a “soft” manner, using one of three methods.
Syntax
ares clip asig, imeth, ilimit [, iarg]
Initialization
imeth -- selects the clipping method. The default is 0. The methods are:
- 0 = Bram de Jong method (default)
- 1 = sine clipping
- 2 = tanh clipping
ilimit -- limiting value
iarg (optional, default=0.5) -- when imeth = 0, indicates the point at which clipping starts, in the range 0 - 1. Not used when imeth = 1 or imeth = 2. Default is 0.5.
asig -- a-rate input signal
The Bram de Jong method (imeth = 0) applies the algorithm (denoting ilimit as limit and iarg as a):
\[
|x| \ge 0 \: \mathrm{and} \: |x| \le (limit \times a): f(x) = f(x)
\]
\[
|x| \gt (limit \times a) \: \mathrm{and} \: |x| \le limit: f(x) = sign(x) \times (limit \times a+ \frac{x - limit \times a}{1 + ((x-limit \times a)/(limit \times (1-a)))^2})
\]
\[
|x| \gt limit: f(x) = sign(x) \times \frac{(limit\times(1+a))}{2}
\]
The second method (imeth = 1) is the sine clip:
\[
|x| \lt limit: f(x) = limit \times sin(\pi x/(2 \times limit)), \; |x| \ge limit: f(x) = limit \times sign(x)
\]
The third method (imeth = 2) is the tanh clip:
\[
|x| \lt limit: f(x) = limit \times tanh(x/limit)/tanh(1), \; |x| \ge limit: f(x) = limit \times sign(x)
\]
Note
Method 1 appears to be non-functional at release of Csound version 4.07.
Examples
Here is an example of the clip opcode. It uses the file clip.csd.
Example of the clip opcode. |
---|
| <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 clip.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
instr 1 ; white noise
arnd rand 1 ; full amlitude
; Clip the noisy waveform's amplitude to 0.5
a1 clip arnd, p4, 0.5
outs a1, a1
endin
instr 2 ; white noise
arnd rand 1 ; full amlitude
; Clip the noisy waveform's amplitude to 0.1
a1 clip arnd, p4, 0.1
outs a1, a1
endin
</CsInstruments>
<CsScore>
; Play Instrument #1 for one second.
i 1 0 1 2
; Play Instrument #2 for one second.
i 2 1 1 2
s 3
; Play Instrument #1 for one second.
i 1 0 1 0
; Play Instrument #2 for one second.
i 2 1 1 0
s 3
; Play Instrument #1 for one second.
i 1 0 1 1
; Play Instrument #2 for one second.
i 2 1 1 1
e
</CsScore>
</CsoundSynthesizer>
|
See also
Amplitude Modifiers and Dynamic processing
Waveshaping
Credits
Author: John ffitch
University of Bath, Codemist Ltd.
Bath, UK
August, 2000
New in Csound version 4.07
September 2009: Thanks to a note from Paolo Dell'Osso, corrected the formula.