vmap
Prev | Orchestra Opcodes and Operators | Next

## vmap

vmap — Maps elements from a vector according to indexes contained in another vector.

## Description

Maps elements from a vector onto another according to the indexes of a this vector.

## Syntax

    vmap  ifn1, ifn2, ielements [,idstoffset, isrcoffset]

## Initialization

ifn1 - number of the table where the vectorial signal will be copied, and which contains the mapping vector

ifn2 - number of the table hosting the vectorial signal to be copied

ielements - number of elements to process

idstoffset - index offset for destination table (ifn1)

isrcoffset - index offset for source table (ifn2)

## Performance

vmap maps elements of ifn2 according to the values of table ifn1. Elements of ifn1 are treated as indexes of table ifn2, so element values of ifn1 must not exceed the length of ifn2 table otherwise a Csound will report an error. Elements of ifn1 are treated as integers, so any fractional part will be truncated. There is no interpolation performed on this operation.

In practice, what happens is that the elements of ifn1 are used as indexes to ifn2, and then are replaced by the corresponding elements from ifn2. ifn1 must be different from ifn2, otherwise the results are unpredictable. Csound will produce an init error if they are not.

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 vmap opcode. It uses the file vmap.csd.

Example 1037. Example of the vmap 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 vmap.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>
    ksmps = 256
    nchnls = 2
    gisize = 64

    gitable ftgen 0, 0, gisize, 10, 1  ;Table to be processed
    gimap1 ftgen  0, 0, gisize, -7, gisize-1, gisize-1, 0 ; Mapping function to reverse table
    gimap2 ftgen 0, 0, gisize, -5, 1, gisize-1, gisize-1  ; Mapping function for PWM
    gimap3 ftgen 0, 0, gisize, -7, 1, (gisize/2)-1, gisize-1, 1, 1, (gisize/2)-1, gisize-1  ; Double frequency

    instr 1  ;Hear an oscillator using gitable
    asig oscil 10000, 440, gitable
    outs asig,asig
    endin

    instr 2  ;Reverse the table (no sound change, except for a single click
    vmap gimap1, gitable, gisize
    vcopy_i gitable, gimap1, gisize
    turnoff
    endin

    instr 3  ;Non-interpolated PWM (or phase waveshaping)
    vmap gimap2, gitable, gisize
    vcopy_i gitable, gimap2, gisize
    turnoff
    endin

    instr 4  ;Double frequency
    vmap gimap3, gitable, gisize
    vcopy_i gitable, gimap3, gisize
    turnoff
    endin

    </CsInstruments>
    <CsScore>
    i 1 0 8

    i 2 2 1
    i 3 4 1
    i 4 6 1

    e
    </CsScore>
    </CsoundSynthesizer>

## Credits

Written by Gabriel Maldonado.

New in Csound 5 (Previously available only on CsoundAV)

Prev | Up | Next
vlowres | Home | vmirror