Skip to content

ftresizei

Changes a function table's size at initialization.

This is the initialization-time form of ftresize. Both use the same experimental implementation and have the same current limits. For new code, prefer creating a separate table with ftgen and copying the wanted range with ftslicei.

Syntax

iunused = ftresizei(ifn, isize)
iunused ftresizei ifn, isize

Initialization

ifn is the number of an existing function table.

isize is the requested size in sample points. Use a positive whole number. The negative-size convention used by ftgen does not apply here.

iunused is required by the opcode's syntax, but the current implementation does not assign it. Do not use it as a table length or a success code.

The resize runs when initialization reaches the call. It keeps the table number and does not resample the contents. Shrinking keeps the allocated storage, and growing does not zero the added memory.

The current implementation records a length one point larger than requested and does not rebuild the guard point or table lookup information. Running at initialization does not remove those limits. Other active instruments may also be using the table, so avoid resizing a shared table while they are running.

Examples

The first instrument in ftresize.csd requests a smaller size for an unused scratch table, then prints its recorded length. The second instrument shows the performance-time form. The current implementation reports 9 after a request for 8.

Inspect initialization and performance-time resize behavior
<CsoundSynthesizer>
<CsOptions>
-n -d -m0
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 1
0dbfs = 1

// These opcodes are experimental. No oscillator or table reader uses
// these scratch tables. We inspect only their recorded lengths.
instr ResizeAtInit
  iTable = ftgen(0, 0, 16, -2, 1, 2, 3, 4)
  iBefore = ftlen(iTable)

  // The output is not assigned by the current implementation.
  iUnused = ftresizei(iTable, 8)
  iAfter = ftlen(iTable)
  prints("ftresizei requested 8. Recorded length changed from %d to %d.\n", iBefore, iAfter)
  ftfree(iTable, 1)
endin

instr ResizeAtPerf
  iTable = ftgen(0, 0, 16, -2, 1, 2, 3, 4)

  // Run once, on the first control cycle.
  if timeinstk() == 1 then
    kUnused = ftresize(iTable, 8)

    // ftlen is init-rate. A new note can read the changed length.
    event("i", "ReportLength", 0, 0.01, iTable)
  endif

  // Keep the table until ReportLength has finished.
  ftfree(iTable, 1)
endin

instr ReportLength
  iLength = ftlen(p4)
  prints("ftresize requested 8. Recorded length is %d.\n", iLength)
endin
</CsInstruments>
<CsScore>
i "ResizeAtInit" 0   0.1
i "ResizeAtPerf" 0.2 0.1
e
</CsScore>
</CsoundSynthesizer>

See also

ftresize, ftgen, ftlen, ftslicei, ftfree, Function Table Control

Credits

Author John ffitch, 2011.