; example instruments for some game noises
;

<CsoundSynthesizer> 
 
<CsOptions> 
-g -W -o sound.wav
</CsOptions> 
 
<CsInstruments> 

; an instrument that sounds like a shot
;
; white noise with a spline envelope
instr 1

kcps  init  1
kndx  phasor kcps
kenv  table kndx, 4, 1

a1    oscil p4*kenv*0.5, 1, 3
a2    oscil p4*kenv*0.1, 10, 1
a3    oscil p4*kenv*0.1, 20, 1
a4    oscil p4*kenv*0.1, 40, 1
a5    oscil p4*kenv*0.1, 60, 1
a6    oscil p4*kenv*0.1, 80, 1
aout  = a1+a2+a3+a4+a5+a6
out   aout
endin

; an instrument that sounds like an explosion
;
; several white noise oscillators with different envelopes
;
instr 2

kcps  init  1
kndx  phasor kcps
kenv  table kndx, 4, 1

; first envelope starts fast
k1   linen  1, 0.05*p3, p3, 0.45*p3

; second envelope starts a little later
k2   linen  1, 0.1*p3, p3, 0.5*p3

; third envelope is faster
k3   linen  1, 0.01*p3, p3, 0.2*p3

a10  oscil p4*k1*0.1*kenv, 1, 3
a11  oscil p4*k1*0.1*kenv, 40, 1
a12  oscil p4*k1*0.1*kenv, 60, 1
a13  oscil p4*k1*0.1*kenv, 20, 1

a20  oscil p4*k2*0.1*kenv, 1, 2
a21  oscil p4*k2*0.1*kenv, 30, 1
a22  oscil p4*k2*0.1*kenv, 50, 1

a30  oscil p4*k3*0.1*kenv, 2, 2
a31  oscil p4*k3*0.1*kenv, 30, 1
a32  oscil p4*k3*0.1*kenv, 45, 1

aout = a10+a11+a12+a13+a20+a21+a22+a30+a31+a32
out  aout
endin

</CsInstruments> 
 
<CsScore> 

; function tables here, these are reference shapes

; function table 1: a sine wave
; table number, start time, size (power of 2), function type, harmonic partials
f  1  0  8192  10 1

; function table 2: Gaussian noise (range [-1, 1])
f 2 0 4096 21 6 1

; function table 3: uniform noise (range [0, 1])
f 3 0 4096 21 1 1

; function table 4: spline that rises quickly and falls slowly
f 4 0 1025 8 0.5 32 1 64 0.5 128 0.25 512 0.01 160 0.0

; Note  Instr  Start  Dur(p3)  Amp(p4) 
i       1      0      0.5        20000
i       1      1.5    0.5	 20000
i       2      2.5    1.0        20000
i       2      2.53   1.0        20000
i       2      2.59   1.0        20000
i       2      4.0    1.0	 20000
i       2      4.07   1.0	 20000
i       2      4.11   1.0	 20000

</CsScore> 
</CsoundSynthesizer> 