Previous Section: Building a Simple Cmix Instrument

A More Complex CMIX Instrument


*funpan* would be much more useful if the amplitude placement between the speakers could track some control function. CMIX has a fairly powerful function-building tool imbedded in the MINC language: *makegen*. *makegen* can be used in the scorefile to create arbitrary functions for envelopes and waveforms by calling upon the library of CMIX *gen* routines (see the previous ARRAY article again for a more complete description of this utility). For example, the following *makegen* commands in a score:

would build a simple sine waveform in function table number 1, a line-segment envelope from 0.0 to 1.0 to 0.3 in function table number 2, and a waveform with a moderate amount of second and third harmonic energy present (0.2 and 0.3 respectively) in function table number 3. Notice that the first argument to the *makegen* is the specification for the function table number. It is this number that will be used in an instrument to access the appropriate *makegen*-built function.

*snazzypan* is an instrument which uses an arbitrary function table as a control envelope to change the placement of the input signal in the output stereo soundfile over time. It also has a p-field for controlling the amplitude of the output signal by a simple multiplication scaling of the input:

The amplitude is specified in p[3], and the function table number to track for panning is specified in p[4].

In order to use a *makegen*-created function table, three pieces of information are needed: the function table number, the length of the function table, and the location in memory of the function table. As noted, the function table number for *snazzypan* is given in p[4]. This value is stored in the integer variable "pfunc":

The CMIX functions for returning the length and location of the function table require an integer value as an argument. These two functions, *fsize* and *floc*, are used in *snazzypan* to store the length of the function table in the variable "plength" and the location of the function table in the variable "pfunc_loc":

"plength" is an integer variable, and "pfunc_loc" is a pointer to a floating point location; the start of the function table data. This data is indeed an array of floating point values.

Some mechanism must exist to access the function table at the appropriate times during computation of the output samples. CMIX provides a number of functions for doing this operation. One of the most popular of these is the *table* function. *table* returns values from a function table over a given duration, 'stretching' or 'compressing' the function table data as necessary. *table* must be initialized with the *tableset* function:

*tableset* takes three arguments, the first being the duration over which the table of values must be active (again, p[2] is the p-field specifying duration in this case). The second argument is the length of the table. The third argument is a two-element array which is used internally by *table* to maintain data pointers, etc. In a user-written instrument, all that is necessary is to declare this array as a floating point array:

The name of this array is arbitrary.

Once the function table has been initialized with *tableset*, values can be retrieved using the *table* function:

The first argument to *table* is the current sample number. This is used so that *table* can find the value in the function table corresponding to the amount of processing done. In other words, it is not necessary to call the *table* function for every sample -- the sample number can be used to track how far to go into the function table for a value. The second argument is the location of the table, and the third is the "tabs" array used in *tableset*. *table* will recall values from the table by rounding to the nearest function table array location. A related function, *tablei*, will interpolate between points in the function table, giving slightly smoother results in the table lookup scheme. In this case, the smoothness is probably not necessary. *table* alone will usually be sufficient for performing a relatively smooth pan with the *snazzypan* instrument.

A typical CMIX scorefile for this instrument might do a pan from channel 0 to channel 1 and back again for the duration of some sound event (in this example, the event is 7.9 seconds long in the input file, starting at time 3.4):


Next Section: Extensions and Variations
What is CMIX? - Index -
Cmix Home Page