The Alternative Csound Reference Manual
Previous |  | Next

# GEN02

GEN02 -- Transfers data from immediate pfields into a function table.

## Description

This subroutine transfers data from immediate pfields into a function table.

## Syntax

f # time size 2 v1 v2 v3 ...

## Initialization

size -- number of points in the table. Must be a power of 2 or a power-of-2 plus 1 (see f statement). The maximum tablesize is 16777216 (224) points.

v1, v2, v3, etc. -- values to be copied directly into the table space. The number of values is limited by the compile-time variable PMAX, which controls the maximum pfields (currently 1000). The values copied may include the table guard point; any table locations not filled will contain zeros.

| Note
| If p4 is positive, the table will be post-normalized (rescaled to a maximum absolute value of 1 after generation). A negative p4 will cause rescaling to be skipped.

## Examples

Here is a simple example of the GEN02 routine. It uses the files gen02.orc and gen02.sco. It places 12 values plus an explicit wrap-around guard value into a table of size next-highest power of 2. Rescaling is inhibited. Here is its diagram:

Diagram of the waveform generated by GEN02.

Example 1. A simple example of the GEN02 routine.

    /* gen02.orc */
    ; Initialize the global variables.
    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 1

    ; Instrument #1.
    instr 1
      ; Create an index over the length of our entire note.
      kcps init 1/p3
      kndx phasor kcps

      ; Read Table #1 with our index.
      ifn = 1
      ixmode = 1
      kamp tablei kndx, ifn, ixmode

      ; Create a sine wave, use the Table #1 values to control
      ; the amplitude. This creates a sound with a long attack.
      a1 oscil kamp*30000, 440, 2
      out a1
    endin
    /* gen02.orc */

    /* gen02.sco */
    ; Table #1: an envelope with a long attack (using GEN02).
    f 1 0 16 2 0 1 2 3 4 5 6 7 8 9 10 11 0
    ; Table #2, a sine wave.
    f 2 0 16384 10 1

    ; Play Instrument #1 for 2 seconds.
    i 1 0 2
    e
    /* gen02.sco */

## See Also

GEN17

## Credits

December 2002. Thanks to Rasmus Ekman, corrected the limit of the PMAX variable.

Previous | Home | Next
GEN01 | Up | GEN03