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. 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.
Performance
asig -- a-rate input signal
The Bram de Jong method (imeth = 0) applies the algorithm (denoting ilimit as limit and iarg as a):
<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>