User Defined Opcodes (UDO)

Csound allows the definition of opcodes inside the orchestra header using the opcodes opcode and endop. The defined opcode may run with a different number of control samples (ksmps) using setksmps.

To connect inputs and outputs for the UDO, use xin and xout.

An UDO looks like this:

        opcode Lowpass, a, akk

        setksmps 1              ; need sr=kr
ain, ka1, ka2   xin             ; read input parameters
aout    init 0                  ; initialize output
aout    =  ain*ka1 + aout*ka2   ; simple tone-like filter
        xout aout               ; write output

        endop

This UDO called Lowpass takes 3 inputs (the first is a-rate, and the next two are k-rate), and delivers 1 a-rate output. Notice the use of xin to receive inputs and xout to deliver outputs. Also note the use of setksmps, which is needed for the filter to work properly.

To use this UDO within an instrument, you would do something like:

afiltered Lowpass asource, kvalue1, kvalue2

See the entry for opcode for detailed information on UDO definition.

You can find many ready made UDO's (or contribute your own) at Csounds.com's User Defined Opcode Database.