ftgen
Generate a score function table from within the orchestra.
Syntax
gir ftgen ifn, itime, isize, igen, iarga [, iargb ] [...]
gir ftgen ifn, itime, isize, igen, iarray
Initialization
gir -- either a requested or automatically assigned table number above 100.
ifn -- requested table number If ifn is zero, the number is assigned automatically and the value placed in gir. Any other value is used as the table number
itime -- is ignored, but otherwise corresponds to p2 in the score f statement.
isize -- table size. Corresponds to p3 of the score f statement.
igen -- function table GEN routine. Corresponds to p4 of the score f statement.
iarga, iargb, ... -- function table arguments. Correspond to p5 through p_n_ of the score f statement.
iarray -- ane dimensionl array holding the function table arguments. Correspond to p5 through pn of the score f statement.
This is equivalent to table generation in the score with the f statement.
Note
Csound was originally designed to support tables with power of two sizes only. Though this has changed in recent versions (you can use any size by using a negative number), many opcodes will not accept them.
Warning
Although Csound will not protest if ftgen is used inside instr-endin statements, this is not the intended or supported use, and must be handled with care as it has global effects. (In particular, a different size usually leads to relocation of the table, which may cause a crash or otherwise erratic behaviour).
Examples
Here is an example of the ftgen opcode. It uses the file ftgen.csd.
Example of the ftgen opcode. |
---|
| <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 ftgen.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs =1
gisine ftgen 1, 0, 16384, 10, 1 ;sine wave
gisquare ftgen 2, 0, 16384, 10, 1, 0 , .33, 0, .2 , 0, .14, 0 , .11, 0, .09 ;odd harmonics
gisaw ftgen 3, 0, 16384, 10, 0, .2, 0, .4, 0, .6, 0, .8, 0, 1, 0, .8, 0, .6, 0, .4, 0,.2 ;even harmonics
instr 1
ifn = p4
asig poscil .6, 200, ifn
outs asig, asig
endin
</CsInstruments>
<CsScore>
i 1 0 2 1 ;sine wave
i 1 3 2 2 ;odd harmonics
i 1 6 2 3 ;even harmonics
e
</CsScore>
</CsoundSynthesizer>
|
Here is another example of the ftgen opcode. It uses the file ftgen-2.csd.
Example of the ftgen opcode. |
---|
| <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 ftgen-2.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 16
nchnls = 2
;Example by Jonathan Murphy 2007
0dbfs = 1
instr 1
Sfile = "drumsMlp.wav"
ilen filelen Sfile ; Find length
isr filesr Sfile ; Find sample rate
isamps = ilen * isr ; Total number of samples
isize init 1
loop:
isize = isize * 2
; Loop until isize is greater than number of samples
if (isize < isamps) igoto loop
itab ftgen 0, 0, isize, 1, Sfile, 0, 0, 0
print isize
print isamps
turnoff
endin
</CsInstruments>
<CsScore>
i1 0 10
e
</CsScore>
</CsoundSynthesizer>
|
See also
GEN routine overview
Orchestra Header Statements
Credits
Author: Barry L. Vercoe
M.I.T., Cambridge, Mass
1997
Added warning April 2002 by Rasmus Ekman