tablekt — Provides k-rate control over table numbers.


k-rate control over table numbers.

The standard Csound opcode table when producing a k- or a-rate result, can only use an init-time variable to select the table number. tablekt accepts k-rate control as well as i-time. In all other respects they are similar to the original opcodes.


ares tablekt xndx, kfn [, ixmode] [, ixoff] [, iwrap]
kres tablekt kndx, kfn [, ixmode] [, ixoff] [, iwrap]


ixmode -- if 0, xndx and ixoff ranges match the length of the table. if non-zero xndx and ixoff have a 0 to 1 range. Default is 0

ixoff -- if 0, total index is controlled directly by xndx, ie. the indexing starts from the start of the table. If non-zero, 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). Default is 0.

iwrap -- if iwrap = 0, Limit mode: when total index is below 0, then final index is 0.Total index above table length results in a final index of the table length - high out of range total indexes stick at the upper limit of the table. If iwrap not equal to 0, Wrap mode: total index is wrapped modulo the table length so that all total indexes map into the table. For instance, in a table of length 8, xndx = 5 and ixoff = 6 gives a total index of 11, which wraps to a final index of 3. Default is 0.


kndx -- 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).

xndx -- matching the table length (ixmode = 0) or a 0 to 1 range (ixmode not equal to 0)

kfn -- 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.

[Caution] Caution with k-rate table numbers

At k-rate, if a table number of < 1 is given, or the table number points to a non-existent table, or to one which has a length of 0 (it is to be loaded from a file later) then an error will result and the instrument will be deactivated. kfn must be initialized at the appropriate rate using init. Attempting to load an i-rate value into kfn will result in an error.


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

Example 1096. Example of the tablekt opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

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

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

seed 0

gift1 ftgen 1, 0, 1024, 10, 1				;sine wave
gift2 ftgen 2, 0, 1024, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1	;pulse

instr 1
andx phasor 400 		;phasor for reading the index
kfn init 1 			;initialize the choice of the function table
kmetro init 1			;initialize the frequency of the metro
knewft metro kmetro		;make a new choice for selecting the function table once a second

if knewft == 1 then
  kfn = (kfn == 1 ? 2 : 1) 	;switch between 1 and 2
  kmetro random .5, 2 		;create new metro frequency
  printk2 kfn

ares tablekt andx, kfn, 1
outs ares,  ares

i 1 0 10

Its output should include lines like these:

 i1     2.00000
 i1     1.00000
 i1     2.00000
 i1     1.00000

See also

Table Reading with Dynamic Selection


Author: Robin Whittle
May 1997

New in version 3.47