|
|
|
|
parmck kinarg1, kinarg2, kinarg3, ..., kinargN
parmtk koutarg1, koutarg2, koutarg3, ..., koutargN
parmca ainarg1, ainarg2, ainarg3, ..., ainargN
parmta aoutarg1, aoutarg2, aoutarg3, ..., aoutargN
rtrnck koutarg1, koutarg2, koutarg3, ..., koutargN
rtrntk kinarg1, kinarg2, kinarg3, ..., kinargN
rtrnca aoutarg1, aoutarg2, aoutarg3, ..., aoutargN
rtrnta ainarg1, ainarg2, ainarg3, ..., ainargN
These opcodes deal with a-rate and k-rate arguments and signals. They return signals to be sent when using subroutine calls
kinarg1, kinarg2, kinarg3, ..., kinargN - k-rate input arguments
koutarg1, koutarg2, koutarg3, ..., koutargN - k-rate output arguments
ainarg1, ainarg2, ainarg3, ..., ainargN - a-rate input arguments
aoutarg1, aoutarg2, aoutarg3, ..., aoutargN - a-rate output arguments
This opcode family allows the user to define input and output signals to use as arguments (or parameters) and return values when calling a subroutine (together with the call opcode family).
parmck (k-rate parameters handling to be placed in the caller instrument)and parmtk (k-rate parameters handling to be placed in the target instrument) work in pairs.
Also you must put parmck (as well as parmca) immediately after the call opcode.
rtrnck (k-rate return values received by the caller instrument) and rtrntk (k-rate return values sent by the target instrument) work in pairs. The target instrument can return several k-rate signals to the caller instrument by using these two opcodes.
The caller instrument can send several k-rate signals to the target instrument by using these opcodes.
Some k-rate examples will be presented below, the corresponding a-rate oriented opcodes can be used in the same way, the only difference is that the arguments are a-rate variables.
instr 1 ;caller instrument
;calculating the k-rate arguments to be sent to the target instrument
karg1 oscil ...
karg2 linen ...
karg3 expseg ...
karg4 linseg ...
;**** instrno actime dur init-rate arguments sent to instr 2
call 2, 0, 3, iarg1,iarg2,iarg3 ;call the target instr
parmck karg1,karg2,karg3,karg4 ;send the four signals
.....
endin
instr 2 ;target instrument
.....
;receive the four signals from the caller instr
parmtk k1,k2,k3,k4
; using the k-rate arguments...
a1 oscil k1,k2,k3,1
out a1*k4
.....
endin
In this case instr 1 (the caller) calls instr 2 (the target) and sends three i-rate variables (iarg1, iarg2 and iarg3 which are interpreted as p4, p5 and p6 by the target instrument) and four k-rate arguments (karg1, karg2, karg3, karg4 which are interpreted by the target instrument as k1, k2, k3 and k4 local variables) to the target instrument.
IMPORTANT: Notice that the k1, k2, k3 and k4 arguments of parmtk opcode are output arguments, even if they appear on the right of the opcode instead of on the left. This because Csound at the moment doesn't support a variable number of arguments at the left of the opcode.
instr 1 ;caller instrument
;calculating the k-rate arguments....
; to be sent to the target instrument
....
;**** instrno actime dur init-rate arguments sent to instr 2
call 2, 0, 3, iarg1,iarg2,iarg3 ;*** call the target instr
rtrnck karg1,karg2,karg3,karg4 ;*** receive the return signals from the target instr
;using the return signals ...
a1 oscil karg1,karg1,karg1,1
out a1*karg1
.....
endin
instr 2 ;target instrument
.....
;generating k-rate signals to be returned to the caller instr...
k1 oscil ....
k2 linseg ....
k3 oscil1 ....
k4 expseg ....
;return the four signals to the caller instr
rtrntk k1,k2,k3,k4
.....
endin
It is important to be sure that the number of arguments for the pair parmck/parmtk, and rtrnck/rtrntk is the same. Using a-rate opcodes (parmca/parmta and rtrnca/rtrnta) is almost identical.
;An example of parmck, parmca, parmtk, parmta, rtrnck,rtrnca, rtrntk and rtrnta opcodes
sr = 44100
kr = 441
ksmps = 100
nchnls = 2
gifn ftgen 1,0,1024,10 ,1 ,0,0,0,0,0,0,.1,0,0,0,0,0,.05,0,0,0,0,0,0,0,.01
gikfn ftgen 2,0,1024,10 ,1
instr 1 ;caller instrument
iamp ampmidi 2000
ifreq cpsmidi
a1 oscili iamp, ifreq, gifn
a2 oscili iamp, ifreq*1.3, gifn
a3 oscili iamp, ifreq*1.5555, gifn
k1 oscili 1, .5, gikfn
k2 oscili 1, 1.3, gikfn
k3 oscili 1, 2.1.5555, gikfn
xtratim 2 ;when using a-rate arguments in subroutine call,
;you must be sure that the extra time of the instrument
;containing the out opcode is
;greater or equal to that of the target instr
;first call
callm 2,0,4,iamp, ifreq ;call instr 2 as subroutine
parmck k1,k2,k3 ;send k-rate arguments to instr 2
parmca a1,a2,a3 ;send a-rate arguments to instr 2
rtrnca aout1,aout2 ;receive a-signals returned by the first call of instr 2
;second call
callm 2,0,4,iamp, ifreq*2.2 ;call instr 2 as subroutine
parmck k3,k2,k1 ;send k-rate arguments to instr 2
parmca a3,a1,a2 ;send a-rate arguments to instr 2
rtrnck kenv ;receive k-signals returned by the second call of instr 2
rtrnca aout3,aout4 ;receive a-signals returned by the second call of instr 2
outs (aout1+aout3)*kenv, (aout2+aout4)*kenv
endin
instr 2 ;target instrument
parmtk ksig,ksig2,ksig3 ;receive k-signals sent by caller arguments
parmta asig,asig2,asig3 ;receive a-signals sent by caller arguments
k1 linenr 1,p3/2,p3/2,.03
a1 oscili p4*ksig,p5,gifn
a2 oscili p4*ksig2,p5*1.5,gifn
a3 oscili p4*ksig3,p5*1.8,gifn
rtrntk k1 ;return k-signals
rtrnta a1+asig2+asig3, a2+a3+asig ;return a-signals
endin
|
|
|
|