Now another example, adding a new type of sound. Create a new file (with a different name!) using the .csd extension and paste the following instrument into it, save, and run it in your terminal. 

<CsoundSynthesizer>

<CsOptions>
-d -odac
</CsOptions>

<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
asound    rand    1	; white noise
out    asound
endin

instr 2
asound	oscil    1,440   ; single tone
out    asound
endin
</CsInstruments>

<CsScore>
i1	0	5
i2	6	5
</CsScore>

</CsoundSynthesizer>


This time we have added a second instrument, "instr 2." And while we have used the same "asound" argument in this second instrument, the "opcode" used to make the sound is called "oscil." This produces a sinewave, with amplitude of 1 and a pitch of 440 (Hz). NB: Audio signals in Csound will be denoted as amplitude (in this case an amplitude of 1), frequency (in this case "440") and function (see the next example).

In the score, we have shortened our noise signal to 5 seconds starting at 0, and told "i2" to start this new instrument at 6 seconds and last for 5 seconds. (Notice the 1 second of silence from second 5 to second 6.)

We also added comments next to each instrument, marked with a semicolon (;). Comments made this way can be useful for us when making long scripts, and won't be seen by Csound. However, when using long comments, write your comments between these instead:  /*  and  */ 

Now let's take control of the tone that "oscil" is giving us. Try this file: 


<CsoundSynthesizer>

<CsOptions>
-d -odac
</CsOptions>

<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
ifn = p4
asound    oscil    1,440,ifn	; read the f numbers below
outs    asound,asound
endin

</CsInstruments>

<CsScore>

f1	0	16384	10	1                                          ; Sine
f2	4	16384	10	1 0.5 0.3 0.25 0.2 0.167 0.14 0.125 .111   ; Sawtooth
f3	8	16384	10	1 0   0.3 0    0.2 0     0.14 0     .111   ; Square
f4	12	16384	10	1 1   1   1    0.7 0.5   0.3  0.1          ; Pulse

;p1	p2	p3	p4

i1	0	3	1
i1	4	3	2
i1	8	3	3
i1	12	3	4
</CsScore>

</CsoundSynthesizer>


For this example, we went back to using just one instrument, but with some improvements. For starters, we added an argument "ifn = p4." This tells Csound that when "oscil" produces a sound at 440 Hz, to use one of the waveforms that we have listed down in the score as f1, f2, f3 and f4. Which one? The one listed under the heading "p4." Under p1 we have the first instance of instrument 1, starting at 0 and lasting for 3 seconds. Csound will use f1 as this first tone. The second instance of instrument 1 will start at 4 seconds and last for 3 seconds, using the sawtooth tone (f2). And so on.

What is each of these f numbers telling us? They show the time that the waveform will start, the precision of the waveform in terms of quality (16384 is very precise), the "Gen code" (in this case, Gen10), and the harmonics to be used to form the wave signal. The sine wave, as we know, has in fact only one harmonic. F2, f3 and f4 are other types of waveforms we might be familiar with: the sawtooth wave, the square wave and the pulse wave. 

Lastly, instead of a single "out," we have used "outs" and "asound,asound" to specify which speaker will reproduce which sound. So, we can imagine sending separate signals to each speaker, or percentages thereof, or whatever you might desire...

(This example was taken mostly from the "oscil" Opcode page at the Csound.com website, here: https://csound.com/docs/manual/index.html )

For a "bit crush" example using four sawtooth waveforms, try the instrument below. (When using the opcode "oscil," it is necessary to use powers of two when indicating the precision of a waveform. A different opcode, "poscil," doesn't require the number to be a power of two.)

<CsoundSynthesizer>

<CsOptions>
-d -odac
</CsOptions>

<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
ifn = p4
asound    oscil    1,440,ifn	; read the f numbers below
outs    asound,asound
endin

</CsInstruments>

<CsScore>

f1	0	16384	10	1 0.5 0.3 0.25 0.2 0.167 0.14 0.125 .111   ; Sawtooth 2^14
f2	4	256	10	1 0.5 0.3 0.25 0.2 0.167 0.14 0.125 .111   ; Sawtooth 2^8
f3	8	16	10	1 0.5 0.3 0.25 0.2 0.167 0.14 0.125 .111   ; Sawtooth 2^4
f4	12	8	10	1 0.5 0.3 0.25 0.2 0.167 0.14 0.125 .111   ; Sawtooth 2^3

;p1	p2	p3	p4

i1	0	3	1
i1	4	3	2
i1	8	3	3
i1	12	3	4
</CsScore>

</CsoundSynthesizer>


