vaget

vaget — Access values of the current buffer of an a-rate variable by indexing.

Description

Access values of the current buffer of an a-rate variable by indexing. 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 read 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.

Syntax

kval vaget kndx, avar

Performance

kval - value read from avar

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

avar - a-rate variable to read from

Examples

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

Example 968. Example of the vaget 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
; Audio out   Audio in    No messages
-odac           -iadc     -d     ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o avarget.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>
sr=44100
ksmps=16
nchnls=2

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

aout init 0
ksampnum init 0

kenv	linseg 0, p3 * .5, 1, p3 * .5, 0

aout1	vco2	1, ifreq
aout2	vco2	.5, ifreq * 2
aout3	vco2	.2, ifreq * 4

aout	sum 	aout1, aout2, aout3

;Take Sqrt of signal, checking for negatives
kcount = 0

loopStart:

	kval vaget kcount,aout

	if (kval > .0) then
		kval = sqrt(kval)
	elseif (kval < 0) then
		kval = sqrt(-kval) * -1
	else
		kval = 0
	endif

	vaset kval, kcount,aout

loop_lt kcount, 1, ksmps, loopStart

aout = aout * kenv

aout	moogladder aout, 8000, .1

aout = aout * iamp

outs aout, aout
	endin

</CsInstruments>
<CsScore>

i1	0.0	2 440 80
e

</CsScore>
</CsoundSynthesizer>


See Also

vaset

Credits

Author: Steven Yi

New in version 5.04

September 2006.