The Alternative Csound Reference Manual
Previous |  | Next

# GEN01

GEN01 -- Transfers data from a soundfile into a function table.

## Description

This subroutine transfers data from a soundfile into a function table.

## Syntax

f# time size 1 filcod skiptime format channel

## Performance

size -- number of points in the table. Ordinarily a power of 2 or a power-of-2 plus 1 (see f statement); the maximum tablesize is 16777216 (224) points. The allocation of table memory can be deferred by setting this parameter to 0; the size allocated is then the number of points in the file (probably not a power-of-2), and the table is not usable by normal oscillators, but it is usable by a loscil unit. The soundfile can also be mono or stereo.

filcod -- integer or character-string denoting the source soundfile name. An integer denotes the file soundin.filcod ; a character-string (in double quotes, spaces permitted) gives the filename itself, optionally a full pathname. If not a full path, the file is sought first in the current directory, then in that given by the environment variable SSDIR (if defined) then by SFDIR. See also soundin.

skiptime -- begin reading at skiptime seconds into the file.

channel -- channel number to read in. 0 denotes read all channels.

format -- specifies the audio data-file format:

1 - 8-bit signed character 4 - 16-bit short integers
2 - 8-bit A-law bytes 5 - 32-bit long integers
3 - 8-bit U-law bytes 6 - 32-bit floats

If format = 0 the sample format is taken from the soundfile header, or by default from the CSound -o command-line flag.

| Note
| Reading stops at end-of-file or when the table is full. Table locations not filled will contain zeros. 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 GEN01 routine. It uses the files gen01.orc, gen01.sco, and beats.wav. It uses the audio file "beats.wav", here is its diagram:

Diagram of the waveform generated by GEN01.

Example 1. A simple example of the GEN01 routine.

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

    ; Instrument #1.
    instr 1
       kamp = 30000
       kcps = 1
       ifn = 1
       ibas = 1

       ; Play the audio sample stored in Table #1.
       a1 loscil kamp, kcps, ifn, ibas
       out a1
    endin
    /* gen01.orc */

    /* gen01.sco */
    ; Table #1: read an audio file (using GEN01).
    f 1 0 131072 1 "beats.wav" 0 4 0

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

Here is another example of the GEN01 routine. Csound will automatically compute the tablesize because we have set it to 0. This example uses the files gen01computed.orc, gen01computed.sco, and beats.wav.

Example 2. An example of the GEN01 routine with a computed tablesize.

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

    ; Instrument #1.
    instr 1
       kamp = 30000
       kcps = 1
       ifn = 1
       ibas = 1

       ; Play the audio sample stored in Table #1.
       a1 loscil kamp, kcps, ifn, ibas
       out a1
    endin
    /* gen01computed.orc */

    /* gen01computed.sco */
    ; Table #1: an audio file (using GEN01).
    ; Since our table size is 0, Csound will compute it.
    f 1 0 0 1 "beats.wav" 0 0 0

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

## Credits

Examples written by Kevin Conder

December 2002. Thanks goes to Kanata Motohashi for fixing mistakes in the examples.

September 2003. Thanks goes to Dr. Richard Boulanger for pointing out the references to the AIFF file format. GEN01 also works with WAV files.

Previous | Home | Next
GEN Routines | Up | GEN02