vaddv

vaddv — Performs addition between two vectorial control signals.

Description

Performs addition between two vectorial control signals.

Syntax

vaddv  ifn1, ifn2, kelements [, kdstoffset] [, ksrcoffset] [,kverbose]

Initialization

ifn1 - number of the table hosting the first vector to be processed

ifn2 - number of the table hosting the second vector to be processed

Performance

kelements - number of elements of the two vectors

kdstoffset - index offset for the destination (ifn1) table (Default=0)

ksrcoffset - index offset for the source (ifn2) table (Default=0)

kverbose - Selects whether or not warnings are printed (Default=0)

vaddv adds two vectorial control signals, that is, each element of the first vector is processed (only) with the corresponding element of the other vector. Each vectorial signal is hosted by a table (ifn1 and ifn2). The number of elements contained in both vectors must be the same.

The result is a new vectorial control signal that overrides old values of ifn1. If you want to keep the old ifn1 vector, use vcopy_iopcode to copy it in another table. You can use kdstoffset and ksrcoffset to specify vectors in any location of the tables.

Negative values for kdstoffset and ksrcoffset are acceptable. If kdstoffset is negative, the out of range section of the vector will be discarded. If ksrcoffset is negative, the out of range elements will be assumed to be 0 (i.e. the destination elements will not be changed). If elements for the destination vector are beyond the size of the table (including guard point), these elements are discarded (i.e. elements do not wrap around the tables). If elements for the source vector are beyond the table length, these elements are taken as 0 (i.e. the destination vector will not be changed for these elements).

[Warning] Warning

Using the same table as source and destination table in versions earlier than 5.04, might produce unexpected behavior, so use with care.

This opcode works at k-rate (this means that every k-pass the vectors are added). There is an i-rate version of this opcode called vaddv_i.

[Note] Note

Please note that the elements argument has changed in version 5.03 from i-rate to k-rate. This will change the opcode's behavior in the unusual cases where the i-rate variable ielements is changed inside the instrument, for example in:

    instr 1
ielements  =        10
           vadd     1, 1, ielements
ielements  =        20
           vadd     2, 1, ielements
           turnoff
    endin

All these operators (vaddv,vsubv,vmultv,vdivv,vpowv,vexpv, vcopy and vmap) are designed to be used together with other opcodes that operate with vectorial signals such as vcella, adsynt, adsynt2 etc.

Examples

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

Example 1161. Example of the vaddv 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
-odac           -iadc     -nm0 ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o cigoto.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>


sr=44100
ksmps=128
nchnls=2

  opcode TableDumpSimp, 0, ijo
;prints the content of a table in a simple way
ifn, iprec, ippr   xin; function table, float precision while printing (default = 3), parameters per row (default = 10, maximum = 32)
iprec		=		(iprec == -1 ? 3 : iprec)
ippr		=		(ippr == 0 ? 10 : ippr)
iend		=		ftlen(ifn)
indx		=		0
Sformat	sprintf	"%%.%df\t", iprec
Sdump		=		""
loop:
ival		tab_i		indx, ifn
Snew		sprintf	Sformat, ival
Sdump		strcat		Sdump, Snew
indx		=		indx + 1
imod		=		indx % ippr
	if imod == 0 then
		puts		Sdump, 1
Sdump		=		""
	endif
	if indx < iend igoto loop
		puts		Sdump, 1
  endop

	instr 1
ifn1 = p4
ifn2 = p5
ielements = p6
idstoffset = p7
isrcoffset = p8
kval init 25
vaddv ifn1, ifn2, ielements, idstoffset, isrcoffset, 1
turnoff
	endin

	instr 2
TableDumpSimp p4, 3, 16
	endin

</CsInstruments>
<CsScore>

f 1 0 16 -7 1 15 16

f 2 0 16 -7 1 15 2


i2	0.0	0.2	1
i2	0.2	0.2	2
i1	0.4	0.01	1	2	5	3	8	
i2	0.8	0.2	1
i1	1.0	0.01	1	2	5	10	-2	
i2	1.2	0.2	1
i1	1.4	0.01	1	2	8	14	0	
i2	1.6	0.2	1
i1	1.8	0.01	1	2	8	0	14	
i2	2.0	0.2	1	
i1	2.2	0.002	1	1	8	5	2	
i2	2.4	0.2	1
e


</CsScore>
</CsoundSynthesizer>


See also

Operations Between two Vectorial Signals

Credits

Written by Gabriel Maldonado. Optional arguments added by Andres Cabrera and Istvan Varga.

New in Csound 5 (Previously available only on CsoundAV)