Notes About Makegens



by R. Luke DuBois, with some judicious plagiarism from Chris Bailey and Brad Garton.

some general notes and other silliness:

makegens are often a source of confusion in the wonderful world of cmix. basically, they are arrays of numbers which are drawn into memory in order to be utilized by the cmix instruments. makegens can contain amplitude curves, waveform descriptors, user-defined data, or just about anything. there are a number of pre-defined makegens, as well as a makegen which can read data from an input file or the cmix score itself.

the syntax for basically every single makegen is:

makegen(slot,gen_routine,size,gen_args.........)

slot is determined by the makegen's function in that particular instrument (for example, whatever makegen is assigned to slot 1 in a wavetable score determines the waveform of the notes that follow it). some instruments are hard-wired to look for specific pieces of information in specific makegen slots, whether or not you are explicitly asked to declare them. the manual pages for each instrument should cover this information. this number is often called the local generator number.

gen_routine is the type of makegen, as described below.

size is the number of elements allocated for the array into which makegen will draw its data. the larger the array, the more precision you will have (this is especially true with makegens that draw spectra, for example).

gen_args are the arguments for the makegen, and are in a format determined by the number of the gen_routine.

a useful function to use is fplot(slot), where cmix will draw to the terminal the array defined in the makegen filling that slot.

Gen 2


gen2, which is in a sense the simplest makegen, fills an array with numbers specified by the user that can be called later by a sampfunc() call.

the syntax is:

makegen(slot, 2, size, filenumber)

size refers to the size of the array you want to fill. filenumber is a cmix file descriptor referring to either a file opened with infile() or, if set to 0, the numbers entered on the following line.

example:

makegen(1, 2, 8, 0)
4.3 6.2 60.0 0.3 5.9 7.5 0.24 3.0

note=sampfunc(1,0)


this means that the eight values appearing on the line after the makegen are read into gen slot 1. the first (0th) value in the makegen is then assigned to the variable note.

another example:

infile("../data/start_times", 3)

makegen(1, 2, 50, 3)

this opens the file "../data/start_times" as cmix file number 3 and then loads the first 50 values in the file into gen slot 1.

Gen 5


gen5 draws exponential line segments using a break-point-function (bpf) syntax.

the syntax is:

makegen(slot, 5, size, y1, n_locs, y2, n_locs... yn)

this gen sets it's first value to the value entered at y1, and then interpolates over the number of points set in the next p_field to the value entered at y2, and so on, until a final y value is entered. note that the sum of all the line segments specified in the n_locs fields must add up to the size of the gen.

examples:

makegen(2, 5, 1000, 0.1, 500, 1, 500, 0.1)

this creats a curve which begins at 0.1, rises exponentially over 500 points to one, and then decays over 500 points to 0.1 again. the gen is then assigned to slot 2:

1                                       ---\
                                       /    \
                                     -/      --\
                                  --/           -\
                                -/                -\
                            ---/                    ---\
                         --/                            --\
                    ----/                                  ----\
             ------/                                            ------\
  ----------/                                                          ----------
0 -------------------------------------------------------------------------------

makegen(2, 5, 1000, 0.1, 50, 1, 50, .8, 600, .8, 300, 0.1)

this creates a standard ADSR curve with an attack of 50 points (up to a height of 1), a decay of 50 points (down to .8), a steady state of 600 points, and then a decay down to 0 of 300 points:

1     \
       \
     |  -\
     |    ------------------------------------------------\
     |                                                     \
     /                                                      -\
    |                                                         -\
    |                                                           --\
    /                                                              --\
   |                                                                  ----\
  -/                                                                       ------
0 -------------------------------------------------------------------------------

note: because of the exponential nature of the curves, using a value of absolute 0 with gen5 will typically cause some strange results, since an exponential curve will never really interpolate correctly to nothing.

Gen 7


gen7 draws a series of connected line segments using a bpf syntax, using a straight linear (as opposed to exponential) interpolation.

the syntax is identical to gen5, only the segments connecting the y values are straight lines.

examples:

makegen(2, 5, 1000, 0, 500, 1, 500, 0)

similar to the first example in gen5, only with linear curves (note that values of 0 can be used):
1                                     -------\
                                   --/        --\
                               ---/              ---\
                            --/                      --\
                        ---/                            ---\
                     --/                                    ---\
                 ---/                                           --\
             ---/                                                  ---\
          --/                                                          --\
      ---/                                                                ---\
0 -------------------------------------------------------------------------------
makegen(1, 7, 1000, 0, 1, 1, 498, 1, 1, 0, 1, -1, 498, -1, 1, 0)

this draws a square wave into gen slot 1. note that the n_locs values all add up to the total size of the array:
1  --------------------------------------\
  |                                      | 
  |                                      |
  |                                      |
  |                                      |
  |                                      |
  |                                      |
  |                                      |
  |                                      |
  |                                      |
  |                                      |
0 -------------------------------------------------------------------------------
                                         |                                      |
                                         |                                      |
                                         |                                      |
                                         |                                      |
                                         |                                      |
                                         |                                      |
                                         |                                      |
                                         |                                      |
                                         |                                      |
                                         |                                      |
-1                                        --------------------------------------/

Gen 9


gen9 draws a waveform that can be made up of partials of different amplitudes, phase values, and harmonic ratios to the fundamental.

the syntax is:

makegen(slot, 9, size, harmonic1, amplitude1, phase1, harmonic2, amplitude2, phase2... etc.)

the harmonic value refers to the harmonic multiple of the waveform fundamental, assuming that a makegen stores one full cycle of a waveform. thus, a value of 2 will draw a wave with a period of one-half the size of the makegen (i.e. twice the frequency of the fundamental in relative terms), and a value of .5 will draw only half of a sine wave (since it's full period will be outside the bounds of the makegen).

amplitude refers to the relative amplitude of the harmonic described.

phase refers to the phase offset (in degrees) of the harmonic.

example:

makegen(1, 9, 1000, 1, 1, 0, 2, .5, 90, 3.2, .3, 0)

this draws a waveform with a fundamental of amplitude 1 with no phase offset, and two partials, the first of which is harmonic (an even multiple), at amplitude .5 and 90 degrees out of phase, and the second of which is inharmonic (3.2 times the fundamental frequency) at amplitude .3, and in phase with the fundamental:
1


 
      -----\                   -----\
     /      \                 /      \
    /        -\             -/        \
   /           \           /           \                                        /
  /             \        -/             -\                                     /
                 -\     /                |                                    /
                   ----/                  \                                  /
0 -------------------------------------------------------------------------------
                                            \                               /
                                             -\                            /
                                               \                          |
                                                \                         /
                                                 -\                      |
                                                   --\                   /
                                                      -\                /
                                                        -\             /
                                                          -\          /
                                                            -\       /
-1                                                            ------/

Gen 10


gen10 draws a waveform restricted to harmonic partials of different amplitudes.

the syntax is:

makegen(slot, 10, size, amp1, amp2... ampn)

the amp fields correspond to the relative amplitudes of the partials of the waveform.

example:

makegen(1, 10, 1000, 1)

draws a simple sine wave into gen slot 1:
1                ----------\
               -/           -\
             -/               -\
           -/                   \
          /                      -\
         /                         \
       -/                           \
      /                              -\
     /                                 \
    /                                   \
0 -------------------------------------------------------------------------------
                                          \                                     -
                                           \                                   /
                                            \                                 /
                                             -\                              /
                                               \                            /
                                                \                         -/
                                                 -\                      /
                                                   \                   -/
                                                    -\               -/
                                                      -\           -/
-1                                                      ----------/

makegen(1, 10, 1000, 1, .5, .3, .2)

draws a waveform where the fundamental is at amplitude one, and successive harmonics are at amplitudes .5, .3, and .2, respectively:
1       -----\
       /      \
      |        \
      /         -\
     /            \
    |              -------\
    /                      --\
   |                          -\
   /                            -\
  |                               --\
0 -------------------------------------------------------------------------------
                                          -----\
                                                -\                              |
                                                  -\                            /
                                                    -\                         |
                                                      ---\                     /
                                                          ------\             |
                                                                 \            /
                                                                  -\         /
                                                                    \       |
                                                                     -\     /
-1                                                                     ----/

Gen 17


gen17 solves a chebyshev polynomial and draws it into the gen slot. this gen comes in handy for transfer functions such as those used in waveshaping.

syntax:

makegen(slot, 17, size, index, harm1... harmn)

where index is the index number of the polynomial to be solved, and successive arguments define the harmonics for the function.

example:

makegen(3, 17, 1000, 0.9, 0.3, -0.2, 0.6, -0.7)

solves a chebyshev polynomial with an index of 0.9 and three harmonics, mapping out the following function and placing it in gen slot 3:
1                 ---\
                 /    -\
                /       \
               /         -\
              /            \
             |              \                                        --\
             /               \                                    --/   -\
            |                 \                                  /        \
            /                  \                               -/          \
           |                    \                             /            |
           |                     \                           /              \
0 -------------------------------------------------------------------------------
          |                        \                       /                 |
          |                         \                    -/                  |
          /                          \                  /                     \
         |                            \                /                      |
         |                             -\            -/                        \
         /                               -\        -/                          |
        |                                  -------/                            |
        |                                                                       \
        |                                                                       |
        |                                                                       |
-1      /

Gen 20


gen20 fills a gen with random numbers between 0 and 1 according to one of six different distribution algorithms.

syntax:

makegen(slot, 20, size, algorithm)

the possible algorithms are: 0 (even distribution), 1 (linear distribution weighted low), 2 (linear distribution weighted high), 3 (triangular distribution weighted towards 0.5), 4 (gaussian distribution with mean of 0.5 and std deviation of .166666), and 5 (cauchy distribution with mean of 0.5 and alpha of .00628338).

example:

makegen(1, 20, 1000, 0)

fills a 1000-point makegen with random numbers distributed evenly:
1 
              \        \          \ -\ \  -\                      \          \
             ||     \ ||    \    | / ||| | |    \                ||       \ ||
             ||    || | \  /|   \|   || \| | \ ||    \           /| \ \  | \||
            \||    || | | | |  |||   || || ||| || \ ||  \       | |||||  | |||
  \ \      ||||    || / | | | -/||   || || ||| /||| || ||       | |||| -\| |||  \
  |||      ||| -\  |||   \| ||   /   ||  /  /|| || \|| | --\    | ||||  || ||| |
  |||  \  \| /  |  |||   || ||       ||      || || ||| |    \   / ||||  || ||| |
  || \|| /||     \ | /    / ||       ||      ||  / ||| |    |  /  ||||   / || \|
  || ||||  /     | |        ||       ||       /     /| /    | /   ||||     || ||
   /  / /        | /        ||       ||               /     ||     /||     || ||
1 -------------------------------------------------------------------------------

Gen 24


gen24 creates a series of connected line segments using a setline syntax. in some instruments, this gen has been replaced by an actual setline() call.

syntax:

makegen(slot, 24, size, time11, amplitude1, time2, amplitude2... etc.)

where the line is drawn in time / amplitude pairs which are rescaled to fit the size of the makegen.

example:

makegen(2, 24, 1000, 0, 0, 1, 1, 9, 1, 10, 0)

creates a trapezoidal envelope that rises from 0 to 1, remains at 1 for nine times as long as the rise time, and decays back down to 0 in the same amount of time it took to rise:
1         ---------------------------------------------------------------\
         /                                                                \
        /                                                                  \
       |                                                                    \
       /                                                                    |
      /                                                                      \
     /                                                                        \
    |                                                                         |
    /                                                                          \
   /                                                                            \
0 -------------------------------------------------------------------------------

Gen 25


gen25 fills a gen slot with either a hanning or a hamming window for an fft analysis.

syntax:

makegen(slot, 25, size, window_type)

window_type is either 1 (hanning) or 2 (hamming):
1                                 ---------------\
                               --/                --\
                            --/                      --\
                          -/                            -\
                       --/                                --\
                     -/                                      -\
                   -/                                          -\
                --/                                              --\
              -/                                                    -\
          ---/                                                        ---\
0 -------------------------------------------------------------------------------
(hanning window)


1                                 ---------------\
                              ---/                ---\
                            -/                        --\
                         --/                             -\
                      --/                                  --\
                    -/                                        -\
                 --/                                            --\
               -/                                                  --\
           ---/                                                       --\
     -----/                                                              -----\
0 -------------------------------------------------------------------------------
(hamming window - slightly wider)

of course, there are other makegens, but most of them seem to be redundant. gen6, for example, is another setline curve generator, and gen3 reads in an array of numbers from a file.

good luck!