tablemix
Prev | Orchestra Opcodes and Operators | Next

## tablemix

tablemix — Mixes two tables.

## Description

Mixes two tables.

## Syntax

    tablemix kdft, kdoff, klen, ks1ft, ks1off, ks1g, ks2ft, ks2off, ks2g

## Performance

kdft -- Destination function table.

kdoff -- Offset to start writing from. Can be negative.

klen -- Number of write operations to perform. Negative means work backwards.

ks1ft, ks2ft -- Source function tables. These can be the same as the destination table, if care is exercised about direction of copying data.

ks1off, ks2off -- Offsets to start reading from in source tables.

ks1g, ks2g -- Gains to apply when reading from the source tables. The results are added and the sum is written to the destination table.

tablemix -- This opcode mixes from two tables, with separate gains into the destination table. Writing is done for klen locations, usually stepping forward through the table - if klen is positive. If it is negative, then the writing and reading order is backwards - towards lower indexes in the tables. This bi-directional option makes it easy to shift the contents of a table sideways by reading from it and writing back to it with a different offset.

If klen is 0, no writing occurs. Note that the internal integer value of klen is derived from the ANSI C floor() function - which returns the next most negative integer. Hence a fractional negative klen value of -2.3 would create an internal length of 3, and cause the copying to start from the offset locations and proceed for two locations to the left.

The total index for table reading and writing is calculated from the starting offset for each table, plus the index value, which starts at 0 and then increments (or decrements) by 1 as mixing proceeds.

These total indexes can potentially be very large, since there is no restriction on the offset or the klen. However each total index for each table is ANDed with a length mask (such as 0000 0111 for a table of length 8) to form a final index which is actually used for reading or writing. So no reading or writing can occur outside the tables. This is the same as “wrap” mode in table read and write. These opcodes do not read or write the guardpoint. If a table has been rewritten with one of these, then if it has a guardpoint which is supposed to contain the same value as the location 0, then call tablegpw afterwards.

The indexes and offsets are all in table steps - they are not normalized to 0 - 1. So for a table of length 256, klen should be set to 256 if all the table was to be read or written.

The tables do not need to be the same length - wrapping occurs individually for each table.

## Examples

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

Example 906. Example of the tablemix 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 tablemix.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

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

    gisinoid ftgen 1, 0, 256, 10, 1, 0, 0, .4		;sinoid
    gisaw    ftgen 2, 0, 1024, 7, 0, 256, 1			;saw
    gimix    ftgen 100, 0, 256, 7, 0, 256, 1		;destination table

    instr 1

    kgain linseg 0, p3*.5, .5, p3*.5, 0
          tablemix 100, 0, 256, 1, 0, 1, 2, 0, kgain
    asig  poscil .5, 110, gimix			;mix table 1 & 2
          outs   asig, asig

    endin
    </CsInstruments>
    <CsScore>

    i1 0 10

    e
    </CsScore>
    </CsoundSynthesizer>

## See Also

tablecopy, tablegpw, tableicopy, tableigpw, tableimix

## Credits

Author: Robin Whittle
Australia
May 1997

New in version 3.47

Prev | Up | Next
tablekt | Home | tableng