vpow

vpow — Raises each element of a vector to a scalar power.

Description

Raises each element of a vector to a scalar power.

Syntax

vpow  ifn, kval, kelements [, kdstoffset] [, kverbose]

Initialization

ifn - number of the table hosting the vectorial signal to be processed

Performance

kval - scalar value to which the elements of ifn will be raised

kelements - number of elements of the vector

kdstoffset - index offset for the destination table (Optional, default = 0)

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

vpow raises each element of the vector contained in the table ifn to the power of kval, starting from table index kdstoffset. This enables you to process a specific section of a table by specifying the offset and the number of elements to be processed. Offset is counted starting from 0, so if no offset is specified (or set to 0), the table will be modified from the beginning.

Note that this opcode runs at k-rate so the value of kval is processed every control period. Use with care or you will end up with very large (or small) numbers (or use vpow_i).

These opcodes (vadd, vmult, vpow and vexp) perform numeric operations between a vectorial control signal (hosted by the table ifn), and a scalar signal (kval). Result is a new vector that overrides old values of ifn. All these opcodes work at k-rate.

Negative values for kdstoffset are valid. Elements from the vector that are outside the table, will be discarded, and they will not wrap around the table.

If the optional kverbose argument is different to 0, the opcode will print warning messages every k-pass if table lengths are exceeded.

In all these opcodes, the resulting vectors are stored in ifn, overriding the intial vectors. If you want to keep initial vector, use vcopy or vcopy_i to copy it in another table. All these operators are designed to be used together with other opcodes that operate with vectorial signals such as vcella, adsynt, adsynt2, etc. They can also be useful in conjunction with the spectral opcodes pvsftw and pvsftr.

[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

Examples

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

Example 985. Examples of the vpow 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     ;;;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

	instr 1
ifn1 = p4
ival = p5
ielements = p6
idstoffset = p7
kval init 25
vpow ifn1, ival, ielements, idstoffset, 1
	endin

	instr 2	;Printtable
itable = p4
isize = ftlen(itable)
kcount init 0
kval table kcount, itable
printk2 kval

if (kcount == isize) then
  turnoff
endif

kcount = kcount + 1 
	endin


</CsInstruments>
<CsScore>

f 1 0 16 -7 1 16 17

i2	0.0	0.2	1
i1	0.4	0.01	1	2	3	4
i2	0.8	0.2	1
i1	1.0	0.01	1	0.5	5	-3
i2	1.2	0.2	1
i1	1.4	0.01	1	1.5	10	12
i2	1.6	0.2	1
e

</CsScore>
</CsoundSynthesizer>


Here is another example of the vpow opcode. It uses the file vpow-2.csd.

Example 986. 

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac  ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o vpow-2.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

instr 1

ain   diskin2 "fox.wav", 1				;soundfile
fsrc  pvsanal ain, 1024, 256, 1024, 1
ifn   ftgen   0, 0, 1024/2, 2, 0			;create empty function table for the 513 bins
kflag pvsftw fsrc,ifn					;export only amplitudes to table	
kval  line .001, p3, 1					;start with big distortion, cahnge over note duration to clean sound
kbin  line p4, p3, p5					;vary the bins
vpow  ifn, kval, kbin, 0				;note that this operation is applied each k-cycle!
;vpow ifn, kval, kbin, 10				;if you set kdstoffset to 10 it will affect bins 10+(kbin line p4, p3, p5)
      pvsftr  fsrc,ifn					;read modified data back to fsrc
aout  pvsynth fsrc					;and resynth
      outs aout*p6, aout*p6				;adjust volume to compensate

endin
</CsInstruments>
<CsScore>

i 1 0 4 100 100 .02	;first 100 bins are affected
i 1 + 4 10  10  .1	;first 10 bins
i 1 + 4 1 400	.05	;sweep from bin 1 to 400
e
</CsScore>
</CsoundSynthesizer>


See also

vadd_i, vmult, vpow and vexp.

Credits

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

New in Csound 5 (Previously available only on CsoundAV)