nGen Home Page

The following example illustrates several of nGen's basic features. The top part of the example is the nGen file and the bottom the CsoundĀ score file output.

Each nGen instrument block starts with a header (stating the number of pfields, the start and end time, and the number of beats or events to be created). "Parameters" (pfields) are then listed between {}s (pfields can be listed in any order). In this example, P2 (start times) loops a set of rhythmic values listed in reciprocal duration code (2 16ths, an 8th, and 3 quarters). P3, which calculates the duration of each event, "moves" over time. P4 selects pitches from a given range using a bilateral exponential distribution (i.e., most of the values occurring will be from the center of the distribution). (The "x" in [x c3 c5]is a "flag" telling the program to use the bilateral exponential distribution.) Notice also that the note names in P4 encoded in the "no" input mode will be output as octave.pitch-class (p4(op)) in the resulting score file. The output in P4 of the score file (below) will fall between 7.00 (C3) and 9.00 (C5) but will be centric around 8.00 (C4). Due to the sharp exponential roll-off of this distribution most values that occur will be closest to 8.00.

nGenĀ File:

 i1 = 4 0 -25 ;instrument 1 has 4 pfields, starts at beat 0 and makes 25 events 
{ ;i-block start
p2 rh < 16//8/4x3 > ;start times use "rh" input mode in a loop
p3 mo(-12 1. E .25 2) ;durations move over 12 events exponentially
mo(-13 1. L 2 .25) ;then durations move over 12 events logarithmically
p4(op) no ra(-25 1 [x c3 c5]) ;p4 uses the "notes" input mode and chooses randomly within a range
} ;i-block end

Output Score:

 
i1 0.000 0.062 8.06
i1 0.250 0.066 8.01
i1 0.500 0.154 7.11
i1 1.000 0.380 7.11
i1 2.000 0.481 7.11
i1 3.000 0.612 8.00
i1 4.000 0.193 8.01
i1 4.250 0.240 8.00
i1 4.500 0.588 7.09
i1 5.000 1.421 8.03
i1 6.000 1.696 8.00
i1 7.000 2.000 8.00
i1 8.000 0.500 8.01
i1 8.250 0.382 7.11
i1 8.500 0.625 7.11
i1 9.000 1.054 7.05
i1 10.000 0.902 7.11
i1 11.000 0.778 8.00
i1 12.000 0.168 8.00
i1 12.250 0.145 8.00
i1 12.500 0.250 7.11
i1 13.000 0.429 8.01
i1 14.000 0.364 8.06
i1 15.000 0.305 7.11
i1 16.000 0.062 8.00
e

N.B. There are many more examples in the HTML Manual.