<instrument type='blue.orchestra.GenericInstrument'>
  <name>fof_tenor</name>
  <comment>FOF instrument for tenor voice, using formant values from Csound manual</comment>
  <globalOrc>;[once]{
gi_fof_tenor_freq ftgen 0, 0, 32, -2 ,650 ,1080 ,2650 ,2900 ,3250 ,400 ,1700 ,2600 ,3200 ,3580 ,290 ,1870 ,2800 ,3250 ,3540 ,400 ,800 ,2600 ,2800 ,3000 ,350 ,600 ,2700 ,2900 ,3300
gi_fof_tenor_amp ftgen 0, 0, 32, -2 ,0 ,-6 ,-7 ,-8 ,-22 ,0 ,-14 ,-12 ,-14 ,-20 ,0 ,-15 ,-18 ,-20 ,-30 ,0 ,-10 ,-12 ,-12 ,-26 ,0 ,-20 ,-17 ,-14 ,-26
gi_fof_tenor_bw ftgen 0, 0, 32, -2 ,80 ,90 ,120 ,130 ,140 ,70 ,80 ,100 ,120 ,120 ,40 ,90 ,100 ,120 ,120 ,70 ,80 ,100 ,130 ,135 ,40 ,60 ,100 ,120 ,120
;}

;[once]{
gi_sine	ftgen 0, 0, 65537, 10, 1
;}

;[once]{
gi_fof 	ftgen 0, 0, 1024, 19, .5, .5, 270, .5
;}</globalOrc>
  <globalSco></globalSco>
  <instrumentText>ipch 	= p4
ipch2	= p5

ipch 	= (ipch &lt; 15 ? cpspch(ipch) : ipch)
ipch2 	= (ipch2 &lt; 15 ? cpspch(ipch2) : ipch2)

kpchline 	line ipch, p3, ipch2

iamp 	= ampdb(p6)
iSpace	= p7
ienvType	= p8

iStartVowel = p9
iEndVowel = p10

kenv	yiEnvelope ienvType

iIndex1	= iStartVowel * 5
iIndex2	= iEndVowel * 5

;INSERT SOUND GENERATION CODE HERE

/* START SETTINGS */
iamp1	table	iIndex1, gi_fof_tenor_amp
iamp2	table	iIndex1 + 1, gi_fof_tenor_amp
iamp3	table	iIndex1 + 2, gi_fof_tenor_amp
iamp4	table	iIndex1 + 3, gi_fof_tenor_amp
iamp5	table	iIndex1 + 4, gi_fof_tenor_amp

iamp1	= ampdbfs(iamp1)
iamp2	= ampdbfs(iamp2)
iamp3	= ampdbfs(iamp3)
iamp4	= ampdbfs(iamp4)
iamp5	= ampdbfs(iamp5)

iform1	table	iIndex1, gi_fof_tenor_freq
iform2	table	iIndex1 + 1, gi_fof_tenor_freq
iform3	table	iIndex1 + 2, gi_fof_tenor_freq
iform4	table	iIndex1 + 3, gi_fof_tenor_freq
iform5	table	iIndex1 + 4, gi_fof_tenor_freq

iband1	table	iIndex1, gi_fof_tenor_bw
iband2	table	iIndex1 + 1, gi_fof_tenor_bw
iband3	table	iIndex1 + 2, gi_fof_tenor_bw
iband4	table	iIndex1 + 3, gi_fof_tenor_bw
iband5	table	iIndex1 + 4, gi_fof_tenor_bw


/* END SETTINGS */
iamp1end	table	iIndex2, gi_fof_tenor_amp
iamp2end	table	iIndex2 + 1, gi_fof_tenor_amp
iamp3end	table	iIndex2 + 2, gi_fof_tenor_amp
iamp4end	table	iIndex2 + 3, gi_fof_tenor_amp
iamp5end	table	iIndex2 + 4, gi_fof_tenor_amp

iamp1end	= ampdbfs(iamp1end)
iamp2end	= ampdbfs(iamp2end)
iamp3end	= ampdbfs(iamp3end)
iamp4end	= ampdbfs(iamp4end)
iamp5end	= ampdbfs(iamp5end)


iform1end	table	iIndex2, gi_fof_tenor_freq
iform2end	table	iIndex2 + 1, gi_fof_tenor_freq
iform3end	table	iIndex2 + 2, gi_fof_tenor_freq
iform4end	table	iIndex2 + 3, gi_fof_tenor_freq
iform5end	table	iIndex2 + 4, gi_fof_tenor_freq

iband1end	table	iIndex2, gi_fof_tenor_bw
iband2end	table	iIndex2 + 1, gi_fof_tenor_bw
iband3end	table	iIndex2 + 2, gi_fof_tenor_bw
iband4end	table	iIndex2 + 3, gi_fof_tenor_bw
iband5end	table	iIndex2 + 4, gi_fof_tenor_bw

/* LINE */

kamp1	line	iamp1, p3, iamp1end
kamp2	line	iamp2, p3, iamp2end
kamp3	line	iamp3, p3, iamp3end
kamp4	line	iamp4, p3, iamp4end
kamp5	line	iamp5, p3, iamp5end

kform1	line	iform1, p3, iform1end
kform2	line	iform2, p3, iform2end
kform3	line	iform3, p3, iform3end
kform4	line	iform4, p3, iform4end
kform5	line	iform5, p3, iform5end


kband1	line	iband1, p3, iband1end
kband2	line	iband2, p3, iband2end
kband3	line	iband3, p3, iband3end
kband4	line	iband4, p3, iband4end
kband5	line	iband5, p3, iband5end

/* VOICE GENERATION */

ioct	=	0
iris	=	.003
idur	=	.01	
idec	=	.007
iolaps	=	20
ifna	=	gi_sine
ifnb	=	gi_fof
itotdur	=	p3

asig1	fof    	kamp1, kpchline, kform1, ioct, kband1, iris, idur, idec, iolaps, ifna, ifnb, itotdur 
asig2	fof    	kamp2, kpchline, kform2, ioct, kband2, iris, idur, idec, iolaps, ifna, ifnb, itotdur 
asig3	fof    	kamp3, kpchline, kform3, ioct, kband3, iris, idur, idec, iolaps, ifna, ifnb, itotdur 
asig4	fof    	kamp4, kpchline, kform4, ioct, kband4, iris, idur, idec, iolaps, ifna, ifnb, itotdur 
asig5	fof    	kamp5, kpchline, kform5, ioct, kband5, iris, idur, idec, iolaps, ifna, ifnb, itotdur 


aout	sum 	asig1, asig2, asig3, asig4, asig5

iampMod	= iamp / 0dbfs * .25

aout	= aout * kenv * iampMod

;END SOUND GENERATION CODE

iSpace	= iSpace * 3.14159265359 * .5
krtl     	= sqrt(2) / 2 * (cos(iSpace) + sin(iSpace)) ; CONSTANT POWER PANNING
krtr     	= sqrt(2) / 2 * (cos(iSpace) - sin(iSpace)) ; FROM C.ROADS &quot;CM TUTORIAL&quot; pp460

aLeft 	=	aout * krtl
aRight	=	aout * krtr

blueMixerOut aLeft, aRight
</instrumentText>
  <opcodeList>
    <udo>
      <opcodeName>yiEnvelope</opcodeName>
      <outTypes>k</outTypes>
      <inTypes>ioooooo</inTypes>
      <codeBody>ienvType, iattack, idecay, isus, irel, iOldAmp, iNewAmp	xin

itie	tival
idur = p3

iEndAmp = iNewAmp / iOldAmp


if (ienvType == 0) then
	kenv	adsr	iattack, idecay, isus, irel
elseif (ienvType == 1) then	
	kenv 	linseg	0, p3 * .5, 1, p3 * .5, 0
	kenv logcurve kenv, 1.5
elseif (ienvType == 2) then	
	kenv	linseg 	0, p3 - .1, 1, .1, 0	

elseif (ienvType == 3) then

    if (itie == 0 &amp;&amp; p3 &lt; 0) then
        ; this is an initial note within a group of tied notes
        kenv	linseg	0, .2, 1,  .2, 1
       
    elseif (p3 &gt; 0 &amp;&amp; itie == 1) then
        ; this is an end note out of a group of tied notes
        kenv linseg	1, p3 - 1, 1, 1, 0
 
    elseif (p3 &gt; 0 &amp;&amp; itie == 0) then
        ; this is a stand alone note
        kenv adsr iattack, idecay, isus, irel
    else
        ; this is a middle note within a group of tied notes (p3 &lt; 0 &amp;&amp; itie == 1)
        kenv line 1, abs(p3), iEndAmp
    endif  

endif

	xout 	kenv
</codeBody>
    </udo>
  </opcodeList>
</instrument>