init

init — Puts the value of the i-time expression into a k-, a-rate or t- variable.

Syntax

ares init iarg
ires init iarg
kres init iarg
ares, ...  init iarg, ...
ires, ... init iarg, ...
kres, ... init iarg, ...
tab init isize[, ival]

Description

Put the value of the i-time expression into a k- or a-rate variable.

Initialization

Puts the value of the i-time expression iarg into a k-, a-rate or t- variable, i.e., initialize the result. Note that init provides the only case of an init-time statement being permitted to write into a perf-time (k- or a-rate) result cell; the statement has no effect at perf-time.

Since version 5.13 it is possible to initialise upto 24 variables of the same class in one statement. If there are more output variables than input expressions then the last one is repeated. It is an error to have more inputs than outputs.

The t-variable form was introduced in 5.14 and allocated space for a vector or the given size, initialised to the given value (default value is zero).

Examples

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

Example 472. Example of the init opcode.

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

<CsoundSynthesizer> 
<CsOptions>
; Select audio/midi flags here according to platform
-n  ;no sound output
</CsOptions>
<CsInstruments> 

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

instr 1 ;shows what init does
        kinit init 0 
        kinit = kinit + 1 
        printk .1, kinit 
endin 

instr 2 ;shows what an assignment does
        knoinit = 0 
        knoinit = knoinit + 1 
        printk .1, knoinit 
endin 
</CsInstruments> 
<CsScore> 
;play one second each
i1 0 1 
i2 2 1 
e
</CsScore> 
</CsoundSynthesizer> 


Its output should include lines like these:

 i   1 time     0.00073:     1.00000
 i   1 time     0.10014:   138.00000
 i   1 time     0.20027:   276.00000
 i   1 time     0.30041:   414.00000
 i   1 time     0.40054:   552.00000
 i   1 time     0.50068:   690.00000
 i   1 time     0.60009:   827.00000
 i   1 time     0.70023:   965.00000
 i   1 time     0.80036:  1103.00000
 i   1 time     0.90050:  1241.00000

 i   2 time     2.00054:     1.00000
 i   2 time     2.09995:     1.00000
 i   2 time     2.20009:     1.00000
 i   2 time     2.30023:     1.00000
 i   2 time     2.40036:     1.00000
 i   2 time     2.50050:     1.00000
 i   2 time     2.59991:     1.00000
 i   2 time     2.70005:     1.00000
 i   2 time     2.80018:     1.00000
 i   2 time     2.90032:     1.00000
      

See also

Initialization and Reinitialization

Array opcodes

Credits

Init first appeared in the original Csound, but the extension to multiple values is by

Author: John ffitch
University of Bath, and Codemist Ltd.
Bath, UK
February 2010

Multiple form new in version 5.13; t-variable form new in 5.14.