maketable can be used
for direct RTcmix Instrument envelope, waveform and other
control purposes. It returns
a table 'handle' which can be stored in a scorefile variable. This
'table-handle' can generally operate like other RTcmix scorefile variables,
i.e. it can be treated arithmetically, a single table can
control multiple aspects of an Instrument (without the annoyance of
maintaining the correct makegen "table slot number"), and the syntax of
the maketable command is fairly transparent for
understanding how a particular table is employed in Instrument
control.
maketable was introduced in RTcmix version 4.0, and
you may encounter some very old scores that use the
outdated
makegen
system. Many RTcmix instruments
maintain backwards-compatibility with this older system, but support
for the use of
makegen
constructs was dropped several years ago.
This string value (i.e. enclosed in "double quotes" in the scorefile)
determines the kind of table that will be constructed. This specifier
thus dictates how the rest of the arguments will be interpreted.
Most of the older
makegen
table-creation functions are subsumed by the "table_type".
See
below
for a listing of current table-construction specifiers.
These optional arguments determine global characteristics of how tables
are constructed and subsequently accessed. Presently there are two
sets of string specifiers:
"norm"/"nonorm" -- this option determines whether or
not the table will be normalized; with "norm" specified
the table contents will be scaled to fit within the range 0.0 -- 1.0
or -1.0 -- 1.0. "nonorm" will turn off this scaling, allowing
direct values to be specified when the table is constructed.
"norm" is the default.
"interp"/"interp2"/"nointerp" -- this option dictates
how values will be read from the table. "interp" enables
simple first-order linear interpolation, i.e. if a requested
table value lies between two elements in the table, setting
"interp" will generate an intermediate value based upon
a linear interpolation of nearest sample values. For example,
if the value at table location 314.15 were requested, the value
returned would be 0.15 between the value at location 314 and the
value at location 315. "interp2"
uses a spline-interpolation scheme that may be more accurate
for many curves, but more costly in terms of computation
required. "nointerp" turns off interpolation; the values
returned from the table will be 'rounded-down' (truncated) to the
nearest-lowest point in the table. For example, if the table value
at location 149.78 were requested, the "nointerp" option
would return the value stored at location 149.
NOTE: For instruments that directly access certain table-types,
like
WAVETABLE's
employment of the waveform function table, the interp_type
will probably be ignored because the instrument itself has
coded how it will interpolate an oscillator waveform.
The size of the table: how many numbers it stores. For most interpolated
tables, you can use 1000 or 2000 here. You might want to use more or
less, depending on the specific purpose. (For example, you might want
50 (and only 50) random numbers, so you would use the
random
table type and set the
table size to 50.) There is no requirement that this size be a power
of two.
Any number of arguments that define the table. These depend on the
table type. See documentation for each type below.
Note that the number of arguments used to define the table is independent
of the table size. So, depending on the table type, you can create
a table with a size of 2000 using only one or two arguments.
Fill a table with numbers read from a text file. The syntax is:
table = maketable("textfile", size, "filename")
The function loads as many as size numbers into the table. If there
are not that many numbers in the text file, it zeros out the extra
table values. The function reports one warning if at least one piece
of text (delimited by whitespace) cannot be interpreted as a double.
This means the file may contain any number of free text comments
interspersed with the numbers, as long as the comments themselves
do not contain numbers!
filename should be a string (i.e. enclosed in quotes). The filename
can be a relative pathname to the directory where the scorefile was
invoked, or it may be an absolute pathname within the filesystem.
This replaces the older makegen function
gen 2, except that it does not return
the length of the table created. This can be retrieved using the
new
tablelen scorefile command.
filename is obligatory. As with the filename argument for
the
textfile
table, it is a string that can be a relative or an
absolute pathname to a soundfile. All of the supported RTcmix soundfile
types can be read (aiff, wav, NeXT, bsd, etc.).
The other arguments are optional, but if an
argument further to the right is given, all the ones to its left must also
be given. These optional arguments are:
filename -- the name of a sound file in any of the header
types RTcmix can
read; data formats: 16bit signed int, 32bit float, 24bit
3-byte signed int; either endian.
duration -- duration (in seconds) to read from file.
If negative, its
absolute value is the number of sample frames to read.
If duration is missing, or if it's zero, then the whole
file is read. Beware with large files -- there is no check
on memory consumption!
inskip -- time (in seconds) to skip before reading,
or if negative,
its absolute value is the number of sample frames to skip.
If inskip is missing, it's assumed to be zero.
inchan -- channel number to read (with zero as first channel).
If inchan is missing all channels are read, with samples
from each frame interleaved.
This replaces the older makegen function
gen 1, except that it does not normalize
the sample values. The arguments are slightly different also,
and this does not return the number of frames read. The number of
samples in the table (not frames!) can be retrieved using the new
tablelen scorefile command.
n1, n2, n3, etc. are the numbers that go into the table. The
"nonorm" tag is recommended, unless you want the numbers to be
normalized to [-1.0, 1.0] or [0.0, 1.0] (if no negative values are present).
The function loads as many as size numbers into the table. If there
are not that many number arguments, it sets the extra table values to zero.
If size is zero, the table will be sized to fit the number arguments
exactly. If one (or more) of the n1, n2, ... variables is
an array created in the scripting language, then the array will be
'unpacked' into the table sequentially.
This replaces the older makegen function
gen 2, except that
it has the option to size the table to fit the number of arguments.
It also does not return the number of elements in the table.
This value can be retrieved using the new
tablelen scorefile command.
The function loads as many as size numbers into the table.
This is very similar in function to the
textfile
table type discribed above, except that the file contains 'raw'
binary data, not text-formatted data. If there
are not that many numbers in the file, it zeros out the extra table values.
If size is zero, the table will be sized to fit the data exactly. Be
careful if you use this option with a very large file: you may run out
of memory!
number_type can be any of "float" (the default),
"double", "int", "int64", "int32", "int16" or "byte".
This just means that with the
"double" type, for example, every 8 bytes will be interpreted as one
floating point number; with the "int16" type, every 2 bytes will be
interpreted as one integer; and so on.
"int" is "int32" on a 32-bit
platform and "int64" on a 64-bit platform. No byte-swapping is done.
This replaces the older makegen function
gen 3, except that
it has choices for the type of number, it has the option to
size the table to fit the data, and it does not return the number of
elements in the array.
This value can be retrieved using the new
tablelen scorefile command.
The ampenv table-handle variable will reference a table
containing a straight line from 0 to 1; the table will
have 1000 elements.
wave = maketable("wave", "nonorm", 2000, 0.5)
The wave table-handle variable will reference a table
containing a sine wave at half amplitude, ranging from
-0.5 to 0.5. The "nonorm" optional specifier prevents the
table from being normalized (scaled to fall between -1 and 1). The table
will have 2000 elements.
The following score shows how the table-handle can be used arithmetically
to operate upon other parameters in an instrument (in this case the
WAVETABLE
instrument):
Be aware, though that
memory for these tables is allocated for each use. This is a potential
small memory leak for algorthmic processes that define a large number of
new tables over a long period of time.