GEN02
Prev | Score Statements and GEN Routines | 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 (the GEN routine number 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. You will usually want to use -2 with this GEN function, so that your values are not normalized.

## Examples

Here is a simple example of the GEN02 routine. It uses the files gen02.csd. 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 610. A simple example of the GEN02 routine.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    ; Audio out   Audio in
    -odac           -iadc    ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o gen02.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; 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

    </CsInstruments>
    <CsScore>

    ; 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

    </CsScore>
    </CsoundSynthesizer>

## See Also

GEN17

## Credits

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

Prev | Up | Next
GEN01 | Home | GEN03