<CsoundSynthesizer>
<CsInstruments>
sr = 44100
kr = 441
ksmps = 100
nchnls = 1

;========================================================
; Example FOF instrument 
;
;This uses 5 fof units to simulate vowel formants. The
;formant data is taken from the Dodge book, pp. 230-231
;RP
;========================================================


instr 1 ;basic vowel formant generation instrument
knewpitch invalue "newpitch"

idur = p3
igain = p4 ;gain factor, usually between 0 - 1
ibasedb = dbamp(32767) ;max amp for 16-bit - use as 0dB reference
ifund = cpspch(p5)
ivibdel = p6
ivibwth = p7
ivibrte = p8
iform1 = p9  ;fof1 formant freq
iamp1 = ampdb(ibasedb+p10) ;amp relative to 0dB
ibw1 = p11
iform2 = p12  ;fof2 formant freq
iamp2 = ampdb(ibasedb+p13) ;amp relative to 0dB
ibw2 = p14
iform3 = p15  ;fof3 formant freq
iamp3 = ampdb(ibasedb+p16) ;amp relative to 0dB
ibw3 = p17
iform4 = p18  ;fof4 formant freq
iamp4 = ampdb(ibasedb+p19) ;amp relative to 0dB
ibw4 = p20
iform5 = p21  ;fof5 formant freq
iamp5 = ampdb(ibasedb+p22) ;amp relative to 0dB
ibw5 = p23
ilrise = p24  ;local envelope settings
ildur = p25
ildec = p26
irise = p27  ;global envelope settings
idecay = p28
iolaps = (p29 == 0 ? 10 * ifund*ildur+1 : p29) ;compute overlaps
ioct = p30  ;octaviation
kvibdepth = ivibwth
knewpitch invalue "newpitch" ;k rate update of incoming pitch value -- added by Bob
krealpitch = ifund + knewpitch
kformant1 invalue "formant1"
kformant2 invalue "formant2"
kformant3 invalue "formant3"
kformant4 invalue "formant4"
kformant5 invalue "formant5"
kformant1amp invalue "formant1amp"
kformant2amp invalue "formant2amp"
kformant3amp invalue "formant3amp"
kformant4amp invalue "formant4amp"
kformant5amp invalue "formant5amp"
kvibdepth invalue "vibDepth"

;bob saved this incase we need to go back
;kenv linen igain,irise,idur,idecay
;kvibctl oscil1i ivibdel,1,.25,3 ;fn3 is vib control function
;kvib oscili kvibctl*ivibwth,kvibctl*ivibrte,1
;kfund = (ifund + knewpitch)*(1+kvib)
;ar1 fof iamp1, kfund, kformant1, ioct, ibw1, ilrise, ildur, ildec, iolaps, 1, 2, idur
;ar2 fof iamp2, kfund, kformant2, ioct, ibw2, ilrise, ildur, ildec, iolaps, 1, 2, idur
;ar3 fof iamp3, kfund, kformant3, ioct, ibw3, ilrise, ildur, ildec, iolaps, 1, 2, idur
;ar4 fof iamp4, kfund, kformant4, ioct, ibw4, ilrise, ildur, ildec, iolaps, 1, 2, idur
;ar5 fof iamp5, kfund, kformant5, ioct, ibw5, ilrise, ildur, ildec, iolaps, 1, 2, idur

kenv linen igain,irise,idur,idecay
kvibctl oscil1i ivibdel,1,.25,3 ;fn3 is vib control function

kranddep randi 0.015, .5, p2/1000;
krandspeed randi 0.5, .2, p2/1000;

;kvib oscili kvibctl*ivibwth,kvibctl*ivibrte,1
kvib oscili kvibctl*(kvibdepth+ kranddep),kvibctl*(ivibrte+ krandspeed),1
kfund = (ifund + knewpitch)*(1+kvib)
ioct = 0
ar1 fof iamp1 + kformant1amp, kfund, kformant1, ioct, ibw1, ilrise, ildur, ildec, iolaps, 1, 2, idur
ar2 fof iamp1 + kformant2amp, kfund, kformant2, ioct, ibw2, ilrise, ildur, ildec, iolaps, 1, 2, idur
ar3 fof iamp1 + kformant3amp, kfund, kformant3, ioct, ibw3, ilrise, ildur, ildec, iolaps, 1, 2, idur
ar4 fof iamp1 + kformant4amp, kfund, kformant4, ioct, ibw4, ilrise, ildur, ildec, iolaps, 1, 2, idur
ar5 fof iamp1 + kformant5amp, kfund, kformant5, ioct, ibw5, ilrise, ildur, ildec, iolaps, 1, 2, idur
 out (ar1+ar2+ar3+ar4+ar5)*kenv
 endin 

</CsInstruments>
<CsScore>
;Test score for fofdemo orchestra. Test all the vowel formants from Dodge pp. 230-231. RP
f1 0 8192 10 1
;generate a "sigmoid" for use in local envelope rise/decay
f2 0 8192 19 .5 .5 270 .5
;linear rise for vibrato onset
f3 0 513 7 0 513 1
;male voice singing A
; st dur gain fund vibdel vibwth vibrte

f0 600				; null function to keep running for realtime events
e					; indicates the end of the score



</CsScore>

</CsoundSynthesizer>
