vaset — Write value of into the current buffer of an a-rate variable by index.


Write values into the current buffer of an a-rate variable at the given index. Useful for doing sample-by-sample manipulation at k-rate without using setksmps 1.

[Note] Note

Because this opcode does not do any bounds checking, the user must be careful not to try to write values past ksmps (the size of a buffer for an a-rate variable) by using index values greater than ksmps.

[Note] Note

In Csound6 this opcode does do bounds checking.


vaset kval, kndx, avar


kval - value to write into avar

kndx - index of the sample to write to the current buffer of the given avar variable

avar - a-rate variable to write to


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

Example 1047. Example of the vaset 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
; Audio out   Audio in    No messages
-odac           -iadc     -d     ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o avarset.wav -W ;;; for file output any platform

	instr 1	; Sine Wave
ifreq = (p4 > 15 ? p4 : cpspch(p4))
iamp = ampdb(p5)

kenv adsr 0.1, 0.05, .9, 0.2

aout init 0
ksampnum init 0

kcount = 0

iperiod = sr / ifreq

i2pi = 3.14159 * 2


kphase = (ksampnum % iperiod) / iperiod

knewval = sin(kphase * i2pi)

	vaset knewval, kcount,aout

	ksampnum = ksampnum + 1

loop_lt kcount, 1, ksmps, loopStart

aout = aout * iamp * kenv

outs aout, aout



i1	0.0	2 440 80



See Also



Author: Steven Yi

New in version 5.04

September 2006.