Now for a bit of additive synthesis! Here below is a very simple example of the "poscil" opcode, a "precision oscillator." We have four sound sources that we have called a1, a2, a3 and a4. (The "a" denotes an audio source and must be used.) We then combine these with the "sum" command, calling it "atogether," and specifiying the four sources to be summed together. The "outs" command, being in the plural, denotes a stereo signal and we indicate "atogether" as the signal to be heard in both left and right speakers.
In the Score we have four "f" lines. The sound source "a1" calls f1 (the last number in the "a1" line) and the details of f1 tell us that we are using Gen Code 11, with a single harmonic being produced. Sound source "a2" called f2, etc. etc.
The "p" fields indicate: p1: to play instr 1; p2: to start at time 0; p3: to play for 5 seconds; p4: at an amplitude of .2; p5: 220Hz (used by a1), p6: 440Hz (used by a2), p7: 660Hz (used by p3), and p8: 880Hz (used by p4).
-d -odac
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
instr 1
a1 poscil p4, p5, 1
a2 poscil p4, p6, 2
a3 poscil p4, p7, 3
a4 poscil p4, p8, 4
atogether sum a1,a2,a3,a4
outs atogether,atogether
endin
f 1 0 16384 11 1 1 ;number of harmonics = 1, fundamental = 1
f 2 0 16384 11 10 2 4 ;number of harmonics = 10, fundamental = 2
f 3 0 16384 11 10 5 4 ;number of harmonics = 10, fundamental = 5, amplified 4 times
f 4 0 16384 11 10 7 6 ;number of harmonics = 10, fundamental = 7, amplified 6 times
:p1 p2 p3 p4 p5 p6 p7 p8
i1 0 5 .2 220 440 660 880
Now let's change things slightly:
-d -odac
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
instr 1
a1 poscil p4, p5, 1
outs a1,a1
endin
instr 2
a2 poscil p4, p5, 2
outs a2,a2
endin
instr 3
a3 poscil p4, p5, 3
outs a3,a3
endin
instr 4
a4 poscil p4, p5, 4
outs a4,a4
endin
f 1 0 16384 11 1 1 ;number of harmonics = 1, 1st harmonic is the fundamental
f 2 0 16384 11 20 2 ;number of harmonics = 20, 2nd harmonic is fundamental
f 3 0 16384 11 30 3 ;number of harmonics = 30, 3rd harmonic is fundamental
f 4 0 16384 11 50 3 ;number of harmonics = 50, 3rd harmonic is fundamental
;p1 p2 p3 p4 p5
i1 0 3 .2 220
s
i2 0 3 .2 220
s
i3 0 3 .2 220
s
i4 0 3 .2 220
Here we have created four separate instruments. In fact, in the Score, we now see i1, i2, i3 and i4. Each of these instruments will play in order: i1 for 3 seconds and then stop (using the "s" just after i1), then i2 will play for 3 seconds and stop, then i3, and lastly i4.
Each instrument is utilizing a different function: i1 will play f1, which has a simple wave; i2 will play f2, which has as its fundamental pitch harmonic 2, and with 20 harmonics total; i3 uses f3, which has 30 harmonics; and i4 uses f4, which has 50 harmonics in it.
The pitch is 200Hz, and is used for all four instruments.