tableiw
Prev | Deprecated Orchestra Opcodes and GEN Routines | Next

## tableiw

tableiw — Deprecated.

## Description

Deprecated as of version 3.49. Use the tablew opcode instead.

## Syntax

    tableiw isig, indx, ifn [, ixmode] [, ixoff] [, iwgmode]

## Initialization

isig -- Input value to write to the table.

indx -- Index into table, either a positive number range matching the table length (ixmode = 0) or a 0 to 1 range (ixmode not equal to 0)

ifn -- Table number. Must be >= 1. Floats are rounded down to an integer. If a table number does not point to a valid table, or the table has not yet been loaded (GEN01) then an error will result and the instrument will be de-activated.

ixmode (optional, default=0) -- index mode.

- 0 = indx and ixoff ranges match the length of the table.

- not equal to 0 = indx and ixoff have a 0 to 1 range.

ixoff (optional, default=0) -- index offset.

- 0 = Total index is controlled directly by indx, i.e. the indexing starts from the start of the table.

- Not equal to 0 = Start indexing from somewhere else in the table. Value must be positive and less than the table length (ixmode = 0) or less than 1 (ixmode not equal to 0).

iwgmode (optional, default=0) -- Wrap and guard point mode.

- 0 = Limit mode.

- 1 = Wrap mode.

- 2 = Guardpoint mode.

## Performance

### Limit mode (0)

Limit the total index (indx + ixoff) to between 0 and the guard point. For a table of length 5, this means that locations 0 to 3 and location 4 (the guard point) can be written. A negative total index writes to location 0.

### Wrap mode (1)

Wrap total index value into locations 0 to E, where E is either one less than the table length or the factor of 2 number which is one less than the table length. For example, wrap into a 0 to 3 range - so that total index 6 writes to location 2.

### Guardpoint mode (2)

The guardpoint is written at the same time as location 0 is written - with the same value.

This facilitates writing to tables which are intended to be read with interpolation for producing smooth cyclic waveforms. In addition, before it is used, the total index is incremented by half the range between one location and the next, before being rounded down to the integer address of a table location.

Normally (iwgmode = 0 or 1) for a table of length 5 - which has locations 0 to 3 as the main table and location 4 as the guard point, a total index in the range of 0 to 0.999 will write to location 0. ("0.999" means just less than 1.0.) 1.0 to 1.999 will write to location 1 etc. A similar pattern holds for all total indexes 0 to 4.999 (igwmode = 0) or to 3.999 (igwmode = 1). igwmode = 0 enables locations 0 to 4 to be written - with the guardpoint (4) being written with a potentially different value from location 0.

With a table of length 5 and the iwgmode = 2, then when the total index is in the range 0 to 0.499, it will write to locations 0 and 4. Range 0.5 to 1.499 will write to location 1 etc. 3.5 to 4.0 will also write to locations 0 and 4.

This way, the writing operation most closely approximates the results of interpolated reading. Guard point mode should only be used with tables that have a guardpoint.

Guardpoint mode is accomplished by adding 0.5 to the total index, rounding to the next lowest integer, wrapping it modulo the factor of two which is one less than the table length, writing the table (locations 0 to 3 in our example) and then writing to the guard point if index = 0.

## Examples

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

Example 1328. Example of the tableiw 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
    -odac     ;;;realtime audio out
    ;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o tableiw.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

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

    seed 0	;generate new values every time the instr is played

    instr 1

    ifn = p4
    isize = p5
    ithresh = 0.5

    itemp ftgen ifn, 0, isize, 21, 2

    iwrite_value = 0
    i_index = 0

    loop_start:
        iread_value tablei i_index, ifn

        if iread_value > ithresh then
             iwrite_value = 1
        else
             iwrite_value = -1
        endif
    tableiw iwrite_value, i_index, ifn
    loop_lt i_index, 1, isize, loop_start
        turnoff

    endin

    instr 2

    ifn = p4
    isize = ftlen(ifn)
    prints "Index\tValue\n"

    i_index = 0
    loop_start:
        ivalue tablei i_index, ifn
        prints "%d:\t%f\n", i_index, ivalue

      loop_lt i_index, 1, isize, loop_start		;read table 1 with our index

    aout oscili .5, 100, ifn			;use table to play the polypulse
         outs   aout, aout

    endin
    </CsInstruments>
    <CsScore>
    i 1 0 1 100 16
    i 2 0 2 100
    e
    </CsScore>
    </CsoundSynthesizer>

## See Also

tablew, tablewkt

More information on this opcode: http://www.csoundjournal.com/issue12/genInstruments.html , written by Jacob Joaquin

## Credits

Author: Robin Whittle
Australia
May 1997

New in version 3.47

Updated August 2002, thanks go to Abram Hindle for pointing out the correct syntax.

Prev | Up | Next
tb | Home | Deprecated Gen Routines