tableikt — Provides k-rate control over table numbers.
k-rate control over table numbers. Function tables are read with linear interpolation.
The standard Csound opcode tablei, when producing a k- or a-rate result, can only use an init-time variable to select the table number. tableikt accepts k-rate control as well as i-time. In all other respects they are similar to the original opcodes.
ares tableikt xndx, kfn [, ixmode] [, ixoff] [, iwrap]
kres tableikt kndx, kfn [, ixmode] [, ixoff] [, iwrap]
ixmode -- if 0, xndx and ixoff ranges match the length of the table. if non-zero xndx and ixoff have a 0 to 1 range. Default is 0
ixoff -- if 0, total index is controlled directly by xndx, ie. the indexing starts from the start of the table. If non-zero, start indexing from somewhere else in the table. Value must be positive and less than the table length (ixmode = 0) or less than 1 (ixmode not equal to 0). Default is 0.
iwrap -- if iwrap = 0, Limit mode: when total index is below 0, then final index is 0.Total index above table length results in a final index of the table length - high out of range total indexes stick at the upper limit of the table. If iwrap not equal to 0, Wrap mode: total index is wrapped modulo the table length so that all total indexes map into the table. For instance, in a table of length 8, xndx = 5 and ixoff = 6 gives a total index of 11, which wraps to a final index of 3. Default is 0.
kndx -- Index into table, either a positive number range matching the table length (ixmode = 0) or a 0 to 1 range (ixmode not equal to 0).
xndx -- matching the table length (ixmode = 0) or a 0 to 1 range (ixmode not equal to 0)
kfn -- Table number. Must be >= 1. Floats are rounded down to an integer. If a table number does not point to a valid table, or the table has not yet been loaded (GEN01) then an error will result and the instrument will be de-activated.
Caution with k-rate table numbers | |
---|---|
At k-rate, if a table number of < 1 is given, or the table number points to a non-existent table, or to one which has a length of 0 (it is to be loaded from a file later) then an error will result and the instrument will be deactivated. kfn must be initialized at the appropriate rate using init. Attempting to load an i-rate value into kfn will result in an error. |
Here is an example of the tableikt opcode. It uses the file tableikt.csd.
Example 1084. Example of the tableikt opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform -odac ;;;realtime audio out ;-iadc ;;;uncomment -iadc if RT audio input is needed too ; For Non-realtime ouput leave only the line below: ; -o tableikt.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 instr 1 ilowfn = p4 ;lowest ftable wave ihighfn = p5 ;highest ftable wave kswpenv line 1, p3, 0 ;sweep envelope, calculate current table pair and interpolation amount inumtables = ihighfn - ilowfn ;1 less than number of tables kfn1 = int(kswpenv*inumtables) + ilowfn printks "play table no: %d\n", 1, kfn1 kfn2 = kfn1 + 1 kinterp = frac(kswpenv*inumtables) ixmode = 1 ;read tables with phasor aphase phasor 40 asig tableikt aphase, kfn1, ixmode ;normalized index if kswpenv == 1.0 kgoto skipfn2 ;if kfn1 is last table, there is no kfn2 asig2 tableikt aphase, kfn2, ixmode skipfn2: amix ntrpol asig, asig2, kinterp ;interpolate between tables and output outs amix*.5, amix*.5 endin </CsInstruments> <CsScore> f 1 0 16384 10 1 f 2 0 16384 10 1 .5 f 3 0 16384 1 "fox.wav" 0 0 0 ;a sample f 4 0 16384 10 1 .5 .3 .25 .2 .16 .14 .125 .111 ;sawtooth f 5 0 16384 10 1 .4 .3 .25 .2 f 6 0 16384 10 1 .3 .3 .25 .2 .16 f 7 0 16384 10 1 1 1 1 .7 .5 .3 .1 ;pulse f 8 0 16384 1 "drumsMlp.wav" 0 0 0 ;a sample i 1 0 10 1 8 e </CsScore> </CsoundSynthesizer>
Its output should include lines like these:
play table no: 8 play table no: 7 play table no: 6 ..... play table no: 2 play table no: 1