kmeth / 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.
klimit / ilimit -- a finite, non-negative clipping limit. A limit of 0 produces silence.
karg / iarg (optional, default=0.5) -- for method 0, the fraction of klimit at which soft
clipping starts. Use a value from 0 to 1. A value of 1 gives hard clipping at klimit. Methods
1 and 2 ignore this argument.
All three arguments are k-rate, so they can change at each control cycle. They may also be given
as i-rate values.
For a positive klimit, the curves below use L for klimit and x for the input sample.
The Bram de Jong method (kmeth = 0) uses a for karg 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>
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.
November 2026 (csound 7): The method, limit and shape arguments are k-rate, de Jong method heavily optimized (Eduardo Moguillansky)