limit — Sets the lower and upper limits of the value it processes.


Sets the lower and upper limits of the value it processes.


ares limit asig, klow, khigh
ires limit isig, ilow, ihigh
kres limit ksig, klow, khigh
ires[] limit isig[], ilow, ihigh
kres[] limit ksig[], klow, khigh


isig -- input signal

ilow -- low threshold

ihigh -- high threshold


xsig -- input signal

klow -- low threshold

khigh -- high threshold

limit sets the lower and upper limits on the xsig value it processes. If xhigh is lower than xlow, then the output will be the average of the two - it will not be affected by xsig.

This opcode is useful in several situations, such as table indexing or for clipping and modeling a-rate, i-rate or k-rate signals.


Here is an example of the limit opcode. It uses the file limit.csd.

Example 518. Example of the limit opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

; Select audio/midi flags here according to platform
-odac   ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o limit.wav -W  ;;; for file output any platform

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

instr    1 ; Limit / Mirror / Wrap

igain    = p4				;gain
ilevl1   = p5				; + level
ilevl2   = p6				; - level
imode    = p7				;1 = limit, 2 = mirror, 3 = wrap

ain   soundin  "fox.wav"
ain   = ain*igain

if    imode = 1 goto limit
if    imode = 2 goto mirror

asig  wrap  ain, ilevl2, ilevl1
goto  outsignal

asig  limit  ain, ilevl2, ilevl1
goto  outsignal

asig  mirror  ain, ilevl2, ilevl1

outs  asig*.5, asig*.5			;mind your speakers


;           Gain  +Levl -Levl Mode
i1  0  3    4.00  .25  -1.00   1	;limit
i1  4  3    4.00  .25  -1.00   2	;mirror
i1  8  3    4.00  .25  -1.00   3	;wrap

See also

Signal Limiters

Array opcodes


Author: Robin Whittle

New in Csound version 3.46