GEN01
Prev | Score Statements and GEN Routines | 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 -- if positive it is ignored, but if negative specifies the audio format of a raw file.

-1 - 8-bit signed character
-2 - 8-bit A-law bytes
-3 - 8-bit U-law bytes
-4 - 16-bit short integers
-5 - 32-bit long integers
-6 - 32-bit floats
-7 - 8-bit unsigned character
-8 - 24-bit integers
-9 - 64-bit doubles

| Note
This list is not the same as in diskin2

If format = 0 the sample format is taken from the soundfile header.

| 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-normalised (rescaled to a maximum absolute value of 1 after generation). A negative p4 will cause rescaling to be skipped.

- GEN01 also works with WAV and OGG and a dozen and more other sound formats; these file formats depend on libsndfile, see http://www.mega-nerd.com/libsndfile/

## Examples

Here is an example of the GEN01 routine. It uses the files gen01.csd and several sound files.

Example 1281. An example of the GEN01 routine.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    -odac     ;;;realtime audio out
    ;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o gen01.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 32
    nchnls = 2
    0dbfs  = 1

    instr 1	;plays deferred and non-deferred sounds with loscil

    ifn = p4
    ibas = 1

    asig loscil 1, 1, ifn, ibas
         outs asig, asig

    endin

    instr 2	;plays only non-deffered sound

    isnd  = p4
    aread line   sr*p3, p3, 0				;play this backward
    asig  tablei aread, isnd				;use table 1
          outs   asig, asig

    endin
    </CsInstruments>
    <CsScore>
    f 1 0 131072 1 "drumsMlp.wav" 0 0 0			;non-deferred sound
    f 2 0    0   1 "flute.aiff" 0 0 0			;& deferred sounds in
    f 3 0    0   1 "drumsMlp.ogg" 0 0 0			;different formats

    i 1 0 1 1
    i 1 + 1 2
    i 1 + 1 3

    i 2 4 2 1	;non-deffered sound for instr. 2
    e
    </CsScore>
    </CsoundSynthesizer>

These are the diagrams of the waveforms of the GEN01 routines, as used in the example:

f 1 0 131072 1 "drumsMlp.wav" 0 0 0 - non-deferred sound

f 2 0 0 1 "flute.aiff" 0 0 0 - deferred sound

f 3 0 0 1 "drumsMlp.ogg" 0 0 0 - deferred sound

## Credits

September 2003. Thanks goes to Dr. Richard Boulanger for pointing out the references to the AIFF file format.

Revised in v6.11 and v6.12 to clarify status of headers and raw files, and to add three more sample formats.

Prev | Up | Next
GEN Routines | Home | GEN02