tablecopy — Simple, fast table copy opcode.


Simple, fast table copy opcode.


tablecopy kdft, ksft


kdft -- Destination function table.

ksft -- Number of source function table.

tablecopy -- Simple, fast table copy opcode. Takes the table length from the destination table, and reads from the start of the source table. For speed reasons, does not check the source length - just copies regardless - in wrap mode. This may read through the source table several times. A source table with length 1 will cause all values in the destination table to be written to its value.

tablecopy cannot read or write the guardpoint. To read it use table, with ndx = the table length. Likewise use table write to write it.

To write the guardpoint to the value in location 0, use tablegpw.

This is primarily to change function tables quickly in a real-time situation.


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

Example 929. Example of the tablecopy 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 realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o tablecopy.wav -W ;;; for file output any platform

sr  = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1
;after an example from Jonathan Murphy 
gilen = 7
gilist  ftgen 1, 0, gilen + 1, -2, 2, 3, 4, 5, 6, 7	;only 6 elements, so 1 is doubled
gitmp   ftgen 2, 0, gilen + 1, -2, 0			;empty table
gkmax   init gilen

seed 0							;each time different 

instr 1

ktrig metro 3						;trigger values
krnd  random 0, gkmax

if (ktrig == 1) then
  kval    table  krnd, gilist
          tablew 0, krnd, gilist
  kread   = 0
  kwrite  = 0
  knew    table kread, gilist
if (knew != 0) then
          tablew knew, kwrite, gitmp
  kwrite    =  kwrite + 1
  kread   = kread + 1
if (kread <= gilen) kgoto start
          tablecopy gilist, gitmp			;fill with zeroes
  gkmax   = gkmax - 1

printk2 kval

if (gkmax < 0) then
          event "i", 2, 0, 1/kr				;when ready, then stop

asig vco2 .5, 40*kval					;sound generation
outs asig, asig

instr 2

i1 0 5

Its output should include a lines like these:

i1     5.00000
i1     3.00000
i1     2.00000
i1     4.00000
i1     7.00000
i1     6.00000
i1     7.00000

See Also

tablegpw, tablemix, tableicopy, tableigpw, tableimix


Author: Robin Whittle
May 1997

New in version 3.47