Skip to content

copyf2array

Copies a function table into a one-dimensional numeric array.

Syntax

copyf2array(kArray[], kftbl)
copyf2array(iArray[], iftbl)
copyf2array kArray[], kftbl
copyf2array iArray[], iftbl

Performance

kArray[] or iArray[] is the destination array. kftbl or iftbl is the source function table number. The array comes first, even though it receives the data.

The i-rate form copies once at initialization. The k-rate form copies at initialization and on every control cycle. The source table must exist and its number must be set before initialization reaches the opcode.

If the array has no storage yet, the opcode allocates it at initialization to match the table length. For an existing array, it copies the smaller of the array length and table length. It leaves any remaining array elements unchanged. The copy excludes the table's guard point.

Replacing copy2ttab

copy2ttab is the deprecated performance-only name. Replace copy2ttab(kArray, kftbl) with copyf2array(kArray, kftbl).

The replacement also copies at initialization. Account for that earlier copy if other initialization code reads or changes the array. Use the table number, not a table variable, as the second argument.

Examples

Here is an example of the copyf2array opcode. It uses the file copyf2array-modern.csd.

Example of the copyf2array opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-n
</CsOptions>
<CsInstruments>

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

;8 points sine wave function table
Sine@global:i = ftgen(0, 0, 8, 10, 1)

instr 1
  ;create array
  Arr:k[] = init(8)

  ;copy table values in it
  copyf2array(Arr, Sine)

  ;print values
  ndx:k = 0
  until ndx == lenarray(Arr) do
    printf("kArr[%d] = %f\n", ndx+1, ndx, Arr[ndx])
    ndx += 1
  od

  ;turn instrument off
  turnoff()
endin

</CsInstruments>
<CsScore>
i 1 0 0.1
</CsScore>
</CsoundSynthesizer>

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

Example of the copyf2array opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-n
</CsOptions>
<CsInstruments>

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

;8 points sine wave function table
giSine  ftgen   0, 0, 8, 10, 1


  instr 1
;create array
kArr[]  init    8

;copy table values in it
        copyf2array kArr, giSine

;print values
kndx    =       0
  until kndx == lenarray(kArr) do
        printf  "kArr[%d] = %f\n", kndx+1, kndx, kArr[kndx]
kndx    +=      1
  od

;turn instrument off
        turnoff
  endin

</CsInstruments>
<CsScore>
i 1 0 0.1
</CsScore>
</CsoundSynthesizer>

See also

Array opcodes

Credits

Author: John ffitch
October 2011

New in Csound version 5.15

Renamed in Csound version 6.00