Skip to content

tablera

Reads successive function-table values into an audio block.

Use it with tablewa to process table values with audio-rate code.

Syntax

asig = tablera(kfn, kstart, koff)
asig tablera kfn, kstart, koff

Performance

asig -- the audio block read from the table.

kfn -- the number of the source table.

kstart -- the starting position in table locations. tablera reads this input on each call and does not change it.

koff -- an offset added to kstart on each call. Use integer positions and offsets. Their sum must be nonnegative.

Each call reads the active samples of one audio block, normally ksmps values, starting at kstart + koff. The index wraps at the table length. This also allows a block to read a short table more than once. Tables can have power-of-two or non-power-of-two lengths.

Positions count table locations, without interpolation or normalization to a 0-to-1 range. tablera does not read the guard point.

To read successive blocks, advance kstart in your code. The companion tablewa opcode keeps its own internal write position. Its returned position can equal the table length, so a processing loop should count the values processed rather than wait for it to return zero.

Examples

tablewa.csd defines a source and destination table. It reads four values at a time with tablera, takes their natural logarithms and writes them with tablewa. A bounded loop processes all 16 values once.

Read and process a whole table
<CsoundSynthesizer>
<CsOptions>
-n -d -m0
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 4
nchnls = 1
0dbfs = 1

; Based on the table-processing examples by Robin Whittle.
; GEN02 with a negative generator number keeps the supplied values.
giSource ftgen 0, 0, 16, -2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
giDestination ftgen 0, 0, 16, -2, 0

instr 1
  kDone init 0
  if kDone == 0 then
    kRead = 0
    ; Process four samples per pass, stopping after all 16 values.
    while kRead < ftlen(giSource) do
      aValues tablera giSource, kRead, 0
      aLogs = log(aValues)
      kNext tablewa giDestination, aLogs, 0
      kRead += ksmps
    od

    ; kNext is 16 here. It is not a zero-valued end marker.
    printf "Next write position = %.0f\n", 1, kNext
    kIndex = 0
    while kIndex < ftlen(giDestination) do
      kValue table kIndex, giDestination
      printf "table[%2.0f] = %.6f\n", kIndex + 1, kIndex, kValue
      kIndex += 1
    od
    kDone = 1
  endif
endin
</CsInstruments>
<CsScore>
i 1 0 0.01
e
</CsScore>
</CsoundSynthesizer>

See tablewa's audio-block example for a complete example that writes an audio block to a table, processes each sample in a k-rate loop and reads the block back with tablera.

See also

tablewa, Read/Write Operations