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])
aresclipasig,imeth,ilimit[,iarg]
Initialization
imeth -- selects the clipping method. This argument is required. The methods are:
0 = Bram de Jong method
1 = sine clipping
2 = tanh clipping
Other method codes use method 0.
ilimit -- a finite, non-negative clipping limit. A limit of 0 produces silence.
iarg (optional, default=0.5) -- for method 0, the fraction of ilimit at which soft clipping starts. Use a value from 0 to 1. A value of 1 gives hard clipping at ilimit. Methods 1 and 2 ignore this argument.
Performance
asig -- a-rate input signal
For a positive ilimit, the curves below use L for ilimit and x for the input sample.
The Bram de Jong method (imeth = 0) uses a for iarg and u for the input magnitude, \(u = |x|\):
\[
u \le La: \quad f(x) = x
\]
\[
La < u \le L: \quad f(x) = \operatorname{sign}(x)
\left(La + \frac{u-La}{1 + \left(\frac{u-La}{L(1-a)}\right)^2}\right)
\]
\[
u > L: \quad f(x) = \operatorname{sign}(x)\frac{L(1+a)}{2}
\]
The curved segment is empty when a = 1. For smaller values of a, the output stops at \(\pm L(1+a)/2\), below the clipping limit.
<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=44100ksmps=32nchnls=20dbfs=1instr1; white noiseRnd:a=rand(1); full amlitude; Clip the noisy waveform's amplitude to 0.5a1=clip(Rnd,p4,0.5)outs(a1,a1)endininstr2; white noiseRnd:a=rand(1); full amlitude; Clip the noisy waveform's amplitude to 0.1a1=clip(Rnd,p4,0.1)outs(a1,a1)endin</CsInstruments><CsScore>; Play Instrument #1 for one second.i1012; Play Instrument #2 for one second.i2112s; Play Instrument #1 for one second.i1010; Play Instrument #2 for one second.i2110s; Play Instrument #1 for one second.i1011; Play Instrument #2 for one second.i2111e</CsScore></CsoundSynthesizer>
Here is an example of the clip opcode. It uses the file clip.csd.
<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=44100ksmps=32nchnls=20dbfs=1instr1; white noisearndrand1; full amlitude; Clip the noisy waveform's amplitude to 0.5a1cliparnd,p4,0.5outsa1,a1endininstr2; white noisearndrand1; full amlitude; Clip the noisy waveform's amplitude to 0.1a1cliparnd,p4,0.1outsa1,a1endin</CsInstruments><CsScore>; Play Instrument #1 for one second.i1012; Play Instrument #2 for one second.i2112s; Play Instrument #1 for one second.i1010; Play Instrument #2 for one second.i2110s; Play Instrument #1 for one second.i1011; Play Instrument #2 for one second.i2111e</CsScore></CsoundSynthesizer>