;WRITTEN BY IAIN MCCURDY, 2008

<CsoundSynthesizer>

<CsOptions>
-idevaudio -odevaudio -b400
</CsOptions>

<CsInstruments>
sr	=	44100	
kr	=	441	
ksmps	=	100
nchnls	=	2

;FLTK INTERFACE CODE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FLcolor	255, 255, 255, 0, 0, 0
		FLpanel	"Formant Filter", 500, 700, 0, 0

;SWITCHES                       			ON | OFF | TYPE | WIDTH | HEIGHT | X | Y | OPCODE | INS | STARTTIM | IDUR
gkOnOff,ihOnOff		FLbutton	"On/Off",	1,    0,    22,    140,     25,    5,  5,    0,      1,      0,      3600
FLsetColor2	255, 255, 50, ihOnOff		;SET SECONDARY COLOUR TO YELLOW

;VALUE DISPLAY BOXES		LABEL | WIDTH | HEIGHT | X  | Y
idBWMlt			FLvalue	"",	 50,      16,    5,  145
idFrqMlt		FLvalue	"",	 50,      16,    5,  195
idgain			FLvalue	"",	 50,      16,    5,  295

;SLIDERS				            		MIN   |  MAX | EXP | TYPE |   DISP   | WIDTH | HEIGHT | X  | Y
gkBWMlt, ihBWMlt	FLslider 	"Bandwidths Multiply",	0.01,     4,   -1,   23,    idBWMlt,    490,     25,    5,  120
gkFrqMlt, ihFrqMlt	FLslider 	"Frequencies Multiply",	0.25,     4,   -1,   23,    idFrqMlt,   490,     25,    5,  170
gkmix, ihmix		FLslider 	"Dry/Wet Mix",		0,        1,    0,   23,        -1,     490,     25,    5,  220
gkgain, ihgain		FLslider 	"Global Gain",		0,        4,    0,   23,    idgain,     490,     25,    5,  270
gkInGain, ihInGain	FLslider 	"Gain",			0,        1,    0,   23,        -1,      75,     10,   70,   40
gkBuzFrq, ihBuzFrq	FLslider 	"Freq.",		20,     500,   -1,   23,        -1,      75,     10,   70,   65
FLsetTextSize 11, ihInGain
FLsetTextSize 11, ihBuzFrq

gkf1, ihf1		FLslider 	"f1",			0,        1,    0,   24,        -1,      15,     90,  375,    5
gkf2, ihf2		FLslider 	"f2",			0,        1,    0,   24,        -1,      15,     90,  400,    5
gkf3, ihf3		FLslider 	"f3",			0,        1,    0,   24,        -1,      15,     90,  425,    5
gkf4, ihf4		FLslider 	"f4",			0,        1,    0,   24,        -1,      15,     90,  450,    5
gkf5, ihf5		FLslider 	"f5",			0,        1,    0,   24,        -1,      15,     90,  475,    5

;XY PANELS					MINX | MAXX | MINY | MAXY | EXPX | EXPY | DISPX | DISPY | WIDTH | HEIGHT | X | Y
gkx, gky, ihx, ihy	FLjoy	"Vowel",	0,       1,    0,     1,      0,     0,    -1,     -1,     480,    230,   10, 330

;						 MIN | MAX | STEP | TYPE | WIDTH | HEIGHT | X  |  Y
gkfreq1, gihfreq1	FLtext		"",	20,   20000,   0,     1,     65,     20,    75,  600
gkdb1, gihdb1		FLtext		"",  	-100,     0,   0,     1,     65,     20,    75,  620
gkbw1, gihbw1		FLtext		"",    	0,    20000,   0,     1,     65,     20,    75,  640
gkfreq2, gihfreq2	FLtext		"",	20,   20000,   0,     1,     65,     20,   150,  600
gkdb2, gihdb2		FLtext		"",  	-100,     0,   0,     1,     65,     20,   150,  620
gkbw2, gihbw2		FLtext		"",    	0,    20000,   0,     1,     65,     20,   150,  640
gkfreq3, gihfreq3	FLtext		"",	20,   20000,   0,     1,     65,     20,   225,  600
gkdb3, gihdb3		FLtext		"",  	-100,     0,   0,     1,     65,     20,   225,  620
gkbw3, gihbw3		FLtext		"",    	0,    20000,   0,     1,     65,     20,   225,  640
gkfreq4, gihfreq4	FLtext		"",	20,   20000,   0,     1,     65,     20,   300,  600
gkdb4, gihdb4		FLtext		"",  	-100,     0,   0,     1,     65,     20,   300,  620
gkbw4, gihbw4		FLtext		"",    	0,    20000,   0,     1,     65,     20,   300,  640
gkfreq5, gihfreq5	FLtext		"",	20,   20000,   0,     1,     65,     20,   375,  600
gkdb5, gihdb5		FLtext		"",  	-100,     0,   0,     1,     65,     20,   375,  620
gkbw5, gihbw5		FLtext		"",    	0,    20000,   0,     1,     65,     20,   375,  640

;GENERAL_TEXT_SETTINGS			SIZE | FONT |  ALIGN | RED | GREEN | BLUE
			FLlabel		13,      4,      1,    255,   255,   255	;VALUATOR LABELS MADE INVISIBLE

;			FLBUTBANK 	TYPE | NUMX | NUMY | WIDTH | HEIGHT | X | Y | OPCODE
gkvoice,   ihvoice	FLbutBank	4,      1,     5,     25,    100,    150, 8,   -1
FLcolor2	50, 255, 255
gkinput,   ihinput	FLbutBank	12,     1,     3,     25,     75,      5,40,   -1

;GENERAL_TEXT_SETTINGS			SIZE | FONT |  ALIGN | RED | GREEN | BLUE
			FLlabel		13,      4,      1,     0,     0,     0		;VALUATOR LABELS MADE VISIBLE AGAIN

;TEXT BOXES						TYPE | FONT | SIZE | WIDTH | HEIGHT | X |  Y
ih		 	FLbox  	"Bass         ", 	1,       5,    12,     95,     25,  170,   5
ih		 	FLbox  	"Tenor        ", 	1,       5,    12,     95,     25,  170,  25
ih		 	FLbox  	"Counter Tenor", 	1,       5,    12,     95,     25,  170,  45
ih		 	FLbox  	"Alto         ", 	1,       5,    12,     95,     25,  170,  65
ih		 	FLbox  	"Soprano      ", 	1,       5,    12,     95,     25,  170,  85
ih		 	FLbox  	"Formant Gain:", 	1,       5,    11,     95,     15,  280,  96
ih		 	FLbox  	"A", 			1,       6,    16,     10,     15,    8, 315
ih		 	FLbox  	"E", 			1,       6,    16,     10,     15,  250, 315
ih		 	FLbox  	"I", 			1,       6,    16,     10,     15,  484, 315
ih		 	FLbox  	"0", 			1,       6,    16,     10,     15,  484, 560
ih		 	FLbox  	"U", 			1,       6,    16,     10,     15,    8, 560
ih		 	FLbox  	"    Freq.:", 		1,       5,    12,     75,     20,    0, 600
ih		 	FLbox  	"      dB.:",	 	1,       5,    12,     75,     20,    0, 620
ih		 	FLbox  	"Bandwidth:",		1,       5,    12,     75,     20,    0, 640
ih		 	FLbox  	"Formant 1",		1,       5,    12,     65,     20,   75, 580
ih		 	FLbox  	"Formant 2",		1,       5,    12,     65,     20,  150, 580
ih		 	FLbox  	"Formant 3",		1,       5,    12,     65,     20,  225, 580
ih		 	FLbox  	"Formant 4",		1,       5,    12,     65,     20,  300, 580
ih		 	FLbox  	"Formant 5",		1,       5,    12,     65,     20,  375, 580
ih		 	FLbox  	"Live",			1,       5,    11,     40,     25,   30,  40
ih		 	FLbox  	"Buzz",			1,       5,    11,     40,     25,   30,  65
ih		 	FLbox  	"File",			1,       5,    11,     40,     25,   30,  90

;SET INITIAL VALUES FOR VALUATORS 	VALUE | HANDLE
			FLsetVal_i	1, 	ihBWMlt
			FLsetVal_i	1, 	ihgain
			FLsetVal_i	1, 	ihmix
			FLsetVal_i	1, 	ihFrqMlt
			FLsetVal_i	0, 	ihx
			FLsetVal_i	1, 	ihy
			FLsetVal_i	2, 	ihinput
			FLsetVal_i	50, 	ihBuzFrq

		FLpanel_end	; END OF PANEL CONTENTS

;INSTRUCTIONS AND INFO PANEL
				FLpanel	" ", 500, 660, 512, 0
;TEXT BOXES												TYPE | FONT | SIZE | WIDTH | HEIGHT | X | Y
ih		 	FLbox  	"                       Formant Filter                        ", 	1,      5,     14,    490,    15,     5,  0
ih		 	FLbox  	"-------------------------------------------------------------", 	1,      5,     14,    490,    15,     5,  20
ih		 	FLbox  	"This example uses five 'reson' bandpass filters to imitate   ", 	1,      5,     14,    490,    15,     5,  40
ih		 	FLbox  	"the filtering effect of the human mouth when expressing      ", 	1,      5,     14,    490,    15,     5,  60
ih		 	FLbox  	"various vowel sounds.                                        ", 	1,      5,     14,    490,    15,     5,  80
ih		 	FLbox  	"These five resonant peaks are referred to as 'formants'.     ", 	1,      5,     14,    490,    15,     5, 100
ih		 	FLbox  	"Each formant consists of data for frequency, intensity (in   ", 	1,      5,     14,    490,    15,     5, 120
ih	  	 	FLbox  	"decibels) and bandwith for each of the five filters.         ", 	1,      5,     14,    490,    15,     5, 140
ih		 	FLbox  	"The user can morph between different vowel sounds by dragging", 	1,      5,     14,    490,    15,     5, 160
ih		 	FLbox  	"the cross-hairs of an X-Y panel. The locations of specific   ", 	1,      5,     14,    490,    15,     5, 180
ih		 	FLbox  	"vowel sounds are indicated around the edge of the panel.     ", 	1,      5,     14,    490,    15,     5, 200
ih		 	FLbox  	"Data-sets for five different voice types are selectable using", 	1,      5,     14,    490,    15,     5, 220
ih		 	FLbox  	"a button-bank selecter.                                      ", 	1,      5,     14,    490,    15,     5, 240
ih		 	FLbox  	"Individual gain controls are provided for each formant.      ", 	1,      5,     14,    490,    15,     5, 260
ih		 	FLbox  	"Normally these are left at their maximum setting (gain=1,    ", 	1,      5,     14,    490,    15,     5, 280
ih		 	FLbox  	"therefore no attenuation). Attenuating all formants except   ", 	1,      5,     14,    490,    15,     5, 300
ih		 	FLbox  	"the first two will reveal that the character of the formant  ", 	1,      5,     14,    490,    15,     5, 320
ih		 	FLbox  	"is chiefly defined by just these two formants. An economic   ", 	1,      5,     14,    490,    15,     5, 340
ih		 	FLbox  	"formant filter could be created with just two reson filters. ", 	1,      5,     14,    490,    15,     5, 360
ih		 	FLbox  	"Frequencies can be warped using a global multiplier control. ", 	1,      5,     14,    490,    15,     5, 380
ih		 	FLbox  	"Normally this is set to '1' - no warping.                    ", 	1,      5,     14,    490,    15,     5, 400
ih		 	FLbox  	"Bandwidths can be warped in a similar fashion with the       ", 	1,      5,     14,    490,    15,     5, 420
ih		 	FLbox  	"'Bandwidths Multiply' control.                               ", 	1,      5,     14,    490,    15,     5, 440
ih		 	FLbox  	"The user can choose between three different input sources:   ", 	1,      5,     14,    490,    15,     5, 460
ih		 	FLbox  	"the computer's live input, a 'buzz' tone and a soundfile.    ", 	1,      5,     14,    490,    15,     5, 480
ih		 	FLbox  	"The 'buzz' tone provides a good imitation of the tone        ", 	1,      5,     14,    490,    15,     5, 500
ih		 	FLbox  	"provided by the human vocal chords. When unpitched noise-like", 	1,      5,     14,    490,    15,     5, 520
ih		 	FLbox  	"sounds (like the soundfile option) are used the resulting    ", 	1,      5,     14,    490,    15,     5, 540
ih		 	FLbox  	"output resembles a whisper.                                  ", 	1,      5,     14,    490,    15,     5, 560
ih		 	FLbox  	"The live audio input is stereo, reading from both channels.  ", 	1,      5,     14,    490,    15,     5, 580
ih		 	FLbox  	"A matrix of 15 values boxes at the bottom of the GUI provides", 	1,      5,     14,    490,    15,     5, 580
ih		 	FLbox  	"the user with information about current frequency, intensity ", 	1,      5,     14,    490,    15,     5, 600
ih		 	FLbox  	"and bandwidth values for the five formants. These boxes are  ", 	1,      5,     14,    490,    15,     5, 620
ih		 	FLbox  	"displaying values only.                                      ", 	1,      5,     14,    490,    15,     5, 640

				FLpanel_end

		FLrun		; RUN THE WIDGET THREAD!

givoice_os	ftgen	0, 0, 8, -2, 0, 15, 30, 45, 60	;TABLE OF OFFSET VALUES USED WHEN READING FORMANT DATA - WHICH OFFSET VALUE IS CHOSEN DEPENDS ON WHAT VOICE TYPE IS SELECTED	
;gisine		ftgen	0, 0, 131072, 10, 1

instr	1	;(ALWAYS ON - SEE SCORE) PLAYS FILE AND SENSES FADER MOVEMENT AND RESTARTS INSTR 2 FOR I-RATE CONTROLLERS
	if gkOnOff=0	then					;IF FLTK 'On/Off' SWITCH IS OFF... 
		turnoff         				;TURN THIS INSTRMENT OFF IMEDIATELY
	endif                   				;END OF CONDITIONAL BRANCHING      
	ibit		=	16				;BIT DEPTH OF THE SOUNDFILE USED
	ginorm		=	(2^ibit)*0.5			;MULTIPLIER USED TO NORMALISE THE AUDIO SIGNAL BETWEEN ZERO AND 1
	iporttime	=	.1
	kporttime	linseg	0,.001,iporttime,1,iporttime	;PORTAMENTO TIME                                                      
	kBuzFrq	portk	gkBuzFrq, kporttime                     ;K-RATE PORTAMENTO TIME - RISES QUICKLY TO DESIRED VALUE THEN HOLDS IT
	if	gkinput=0	then				;IF 'Live' IS SELECTED FOR INPUT
		asigL	inch	1				;READ AUDIO FROM CHANNEL 1 (LEFT)
		asigL	=	asigL * gkInGain		;ATTENUATE AUDIO FROM CHANNEL 1 USING 'gkInGain' CONTROL
		asigR	inch	2                               ;READ AUDIO FROM CHANNEL 2 (RIGHT)                       
		asigR	=	asigR * gkInGain                ;ATTENUATE AUDIO FROM CHANNEL 2 USING 'gkInGain' CONTROL
	elseif	gkinput=1	then				;IF 'Buzz' IS SELECTED FOR INPUT
		;OUT		OPCODE	AMPLITUDE | INTERVAL (BETWEEN PULSES)
		asigL		mpulse	32768,      1/kBuzFrq
		asigR		=	asigL							;SET asigR TO BE IDENTICAL TO asigL (THE 'BUZZING' TONE) 
	else							;IF NEITHER OF THE FIRST 2 OPTIONS FOR INPUT ARE USED... (ONLY ONE OPTION REMAINS)
		;OUTPUTS	OPCODE	FILE           | SPEED | INSKIP | LOOPING (0=OFF 1=ON)
		asigL, asigR	diskin2	"Seashore.wav",    1,      0,         1	;GENERATE 2 AUDIO SIGNALS FROM A STEREO SOUND FILE
	endif
		
	gasigL		=	asigL/ginorm			;NORMALISE BOTH CHANNELS OF AUDIO - CREATE GLOBAL AUDIO VARIABLES THAT WILL BE ACCESSIBLE BY INSTR 2
	gasigR		=	asigR/ginorm			;NORMALISE BOTH CHANNELS OF AUDIO - CREATE GLOBAL AUDIO VARIABLES THAT WILL BE ACCESSIBLE BY INSTR 2
	                                                                                                                                                           
	kSwitch		changed	gkvoice	;GENERATE A MOMENTARY '1' PULSE IN OUTPUT 'kSwitch' IF ANY OF THE SCANNED INPUT VARIABLES CHANGE. (OUTPUT 'kSwitch' IS NORMALLY ZERO)
	if	kSwitch=1	then		;IF I-RATE VARIABLE CHANGE TRIGGER IS '1'...
		reinit	START			;BEGIN A REINITIALISATION PASS FROM LABEL 'START'
	endif
	START:
	ivoice_os	table	i(gkvoice), givoice_os		;READ TABLE OFFSET VALUE FROM FUNCTION TABLE 'givoice_os' - THESE ARE USED TO SELECT THE DIFFERENT DATA SET CORRESPONDING TO THE 5 DIFFERENT VOICE TYPES
		
	;A TEXT MACRO IS DEFINED THAT WILL BE THE CODE FOR DERIVING DATA FOR EACH FORMANT. A MACRO IS USED TO AVOID HAVING TO USING CODE REPETITION AND TO EASIER FACICLITATE CODE MODIFICATION
#define	FORMANT_DATA	#
	kfreq$NUMU	table		gkx*(3/5),$NUM+ivoice_os, 1			;READ DATA FOR FREQUENCY (UPPER EDGE OF PANEL)
	kfreq$NUML	table		((1-gkx)*(1/5))+(4/5),$NUM+ivoice_os, 1		;READ DATA FOR FREQUENCY (LOWER EDGE OF PANEL)
	kfreq$NUM	ntrpol		kfreq$NUML, kfreq$NUMU, gky			;INTERPOLATE BETWEEN UPPER VALUE AND LOWER VALUE (DETERMINED BY Y-LOCATION ON PANEL)                          
	kfreq$NUM	=		kfreq$NUM * gkFrqMlt				;MULTIPLY FREQUENCY VALUE BY VALUE FROM 'Frequency Multiply' SLIDER
	kdbamp$NUMU	table		gkx*(3/5),$NUM+ivoice_os+5, 1			;READ DATA FOR INTENSITY (UPPER EDGE OF PANEL)                                      
	kdbamp$NUML	table		((1-gkx)*(1/5))+(4/5),$NUM+ivoice_os+5, 1       ;READ DATA FOR INTENSITY (LOWER EDGE OF PANEL)                                      
	kdbamp$NUM	ntrpol		kdbamp$NUML, kdbamp$NUMU, gky                   ;INTERPOLATE BETWEEN UPPER VALUE AND LOWER VALUE (DETERMINED BY Y-LOCATION ON PANEL)
	kbw$NUMU	table		gkx*(3/5),$NUM+ivoice_os+10, 1			;READ DATA FOR BANDWIDTH (UPPER EDGE OF PANEL)                                      
	kbw$NUML	table		((1-gkx)*(1/5))+(4/5),$NUM+ivoice_os+10, 1      ;READ DATA FOR BANDWIDTH (LOWER EDGE OF PANEL)                                      
	kbw$NUM		ntrpol		kbw$NUML, kbw$NUMU, gky                         ;INTERPOLATE BETWEEN UPPER VALUE AND LOWER VALUE (DETERMINED BY Y-LOCATION ON PANEL)
	kbw$NUM		=		kbw$NUM*gkBWMlt					;MULTIPLY BANDWIDTH VALUE BY VALUE FROM 'Bandwidth Multiply' SLIDER
	FLsetVal	kDisplayTrigger, kfreq$NUM, gihfreq$NUM				;UPDATE DISPLAY OF FREQUENCY VALUE IN THE ON-SCREEN VALUATOR BOX                                                          
	FLsetVal	kDisplayTrigger, kdbamp$NUM, gihdb$NUM				;UPDATE DISPLAY OF INTENSITY VALUE IN THE ON-SCREEN VALUATOR BOX                                                          
	FLsetVal	kDisplayTrigger, kbw$NUM, gihbw$NUM				;UPDATE DISPLAY OF BANDWIDTH VALUE IN THE ON-SCREEN VALUATOR BOX                                                          
	#										;END OF MACRO!

	kDisplayTrigger	metro	20							;CREATE A TRIGGER METRONOME (USED TO UPDATE VALUATOR BOX DISPLAYS

;READING DATA FOR FORMANTS (MACROS IMPLEMENTED)
#define	NUM	#1#
	$FORMANT_DATA
#define	NUM	#2#
	$FORMANT_DATA
#define	NUM	#3#
	$FORMANT_DATA
#define	NUM	#4#
	$FORMANT_DATA
#define	NUM	#5#
	$FORMANT_DATA

	rireturn	;RETURN FROM REINITIALISATION PASS TO PERFORMANCE TIME PASSES
	
	kfreq1		portk	kfreq1,		kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kfreq2		portk	kfreq2,		kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kfreq3		portk	kfreq3,		kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kfreq4		portk	kfreq4,		kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kfreq5		portk	kfreq5,		kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kdbamp1		portk	kdbamp1,	kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kdbamp2		portk	kdbamp2,	kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kdbamp3		portk	kdbamp3,	kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kdbamp4		portk	kdbamp4,	kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kdbamp5		portk	kdbamp5,	kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kbw1		portk	kbw1,		kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kbw2		portk	kbw2,		kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kbw3		portk	kbw3,		kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kbw4		portk	kbw4,		kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	kbw5		portk	kbw5,		kporttime	;PORTAMENTO APPLIED TO VALUE TO SMOOTH TRANSITIONS
	
	aBPF1L	reson	gasigL, kfreq1, kbw1, 1			;FORMANT 1
	aBPF1R	reson	gasigR, kfreq1, kbw1, 1			;FORMANT 1
	;                                                        
	aBPF2L	reson	gasigL, kfreq2, kbw2, 1			;FORMANT 2
	aBPF2R	reson	gasigR, kfreq2, kbw2, 1			;FORMANT 2
	;                                                       
	aBPF3L	reson	gasigL, kfreq3, kbw3, 1			;FORMANT 3
	aBPF3R	reson	gasigR, kfreq3, kbw3, 1			;FORMANT 3
	;                                                        
	aBPF4L	reson	gasigL, kfreq4, kbw4, 1			;FORMANT 4
	aBPF4R	reson	gasigR, kfreq4, kbw4, 1			;FORMANT 4
	;                                                       
	aBPF5L	reson	gasigL, kfreq5, kbw5, 1			;FORMANT 5
	aBPF5R	reson	gasigR, kfreq5, kbw5, 1			;FORMANT 5
	
	;FORMANTS ARE MIXED AND MULTIPLIED BOTH BY INTENSITY VALUES DERIVED FROM TABLES AND BY THE ON-SCREEN GAIN CONTROLS FOR EACH FORMANT 
	aMixL	sum	aBPF1L*(ampdbfs(kdbamp1))*(1-gkf1), aBPF2L*(ampdbfs(kdbamp2))*(1-gkf2), aBPF3L*(ampdbfs(kdbamp3))*(1-gkf3), aBPF4L*(ampdbfs(kdbamp4))*(1-gkf4), aBPF5L*(ampdbfs(kdbamp5))*(1-gkf5)
	aMixR	sum	aBPF1R*(ampdbfs(kdbamp1))*(1-gkf1), aBPF2R*(ampdbfs(kdbamp2))*(1-gkf2), aBPF3R*(ampdbfs(kdbamp3))*(1-gkf3), aBPF4R*(ampdbfs(kdbamp4))*(1-gkf4), aBPF5R*(ampdbfs(kdbamp5))*(1-gkf5)

	aOutMixL	ntrpol	gasigL*ginorm, aMixL*gkgain, gkmix	;MIX BETWEEN DRY AND WET SIGNALS
	aOutMixR	ntrpol	gasigR*ginorm, aMixR*gkgain, gkmix	;MIX BETWEEN DRY AND WET SIGNALS

		outs	aOutMixL, aOutMixR				;SEND AUDIO TO OUTPUTS
endin

</CsInstruments>

<CsScore>
f 0 3600	;DUMMY SCORE EVENT - PERMITS REALTIME PERFORMANCE FOR UP TO 1 HOUR  

;FUNCTION TABLES STORING FORMANT DATA FOR EACH OF THE FIVE VOICE TYPES REPRESENTED
;BASS
f 1  0 32768 -7 600	10922	400	10922	250	10924	350	;FREQ
f 2  0 32768 -7 1040	10922	1620	10922	1750	10924	600	;FREQ
f 3  0 32768 -7	2250	10922	2400	10922	2600	10924	2400	;FREQ
f 4  0 32768 -7	2450	10922	2800	10922	3050	10924	2675	;FREQ
f 5  0 32768 -7	2750	10922	3100	10922	3340	10924	2950	;FREQ
f 6  0 32768 -7	0	10922	0	10922	0	10924	0	;dB
f 7  0 32768 -7	-7	10922	-12	10922	-30	10924	-20	;dB
f 8  0 32768 -7	-9	10922	-9	10922	-16	10924	-32	;dB
f 9  0 32768 -7	-9	10922	-12	10922	-22	10924	-28	;dB
f 10 0 32768 -7	-20	10922	-18	10922	-28	10924	-36	;dB
f 11 0 32768 -7	60	10922	40	10922	60	10924	40	;BAND WIDTH
f 12 0 32768 -7	70	10922	80	10922	90	10924	80	;BAND WIDTH
f 13 0 32768 -7	110	10922	100	10922	100	10924	100	;BAND WIDTH
f 14 0 32768 -7	120	10922	120	10922	120	10924	120	;BAND WIDTH
f 15 0 32768 -7	130	10922	120	10922	120	10924	120	;BAND WIDTH
;TENOR
f 16 0 32768 -7 650 	8192	400 	8192	290	8192	400	8192	350	;FREQ
f 17 0 32768 -7 1080 	8192	1700    8192	1870	8192	800	8192	600	;FREQ
f 18 0 32768 -7	2650	8192	2600    8192	2800	8192	2600	8192	2700	;FREQ
f 19 0 32768 -7	2900	8192	3200    8192	3250	8192	2800	8192	2900	;FREQ
f 20 0 32768 -7	3250	8192	3580    8192	3540	8192	3000	8192	3300	;FREQ
f 21 0 32768 -7	0	8192	0	8192	0	8192	0	8192	0	;dB
f 22 0 32768 -7	-6	8192	-14	8192	-15	8192	-10	8192	-20	;dB
f 23 0 32768 -7	-7	8192	-12	8192	-18	8192	-12	8192	-17	;dB
f 24 0 32768 -7	-8	8192	-14	8192	-20	8192	-12	8192	-14	;dB
f 25 0 32768 -7	-22	8192	-20	8192	-30	8192	-26	8192	-26	;dB
f 26 0 32768 -7	80	8192	70	8192	40	8192	40	8192	40	;BAND WIDTH
f 27 0 32768 -7	90	8192	80	8192	90	8192	80	8192	60	;BAND WIDTH
f 28 0 32768 -7	120	8192	100	8192	100	8192	100	8192	100	;BAND WIDTH
f 29 0 32768 -7	130	8192	120	8192	120	8192	120	8192	120	;BAND WIDTH
f 30 0 32768 -7	140	8192	120	8192	120	8192	120	8192	120	;BAND WIDTH
;COUNTER TENOR
f 31 0 32768 -7 660	8192	440	8192	270	8192	430	8192	370	;FREQ
f 32 0 32768 -7 1120	8192	1800	8192	1850	8192	820	8192	630	;FREQ
f 33 0 32768 -7	2750	8192	2700	8192	2900	8192	2700	8192	2750	;FREQ
f 34 0 32768 -7	3000	8192	3000	8192	3350	8192	3000	8192	3000	;FREQ
f 35 0 32768 -7	3350	8192	3300	8192	3590	8192	3300	8192	3400	;FREQ
f 36 0 32768 -7	0	8192	0	8192	0	8192	0	8192	0	;dB
f 37 0 32768 -7	-6	8192	-14	8192	-24	8192	-10	8192	-20	;dB
f 38 0 32768 -7	-23	8192	-18	8192	-24	8192	-26	8192	-23	;dB
f 39 0 32768 -7	-24	8192	-20	8192	-36	8192	-22	8192	-30	;dB
f 40 0 32768 -7	-38	8192	-20	8192	-36	8192	-34	8192	-30	;dB
f 41 0 32768 -7	80	8192	70	8192	40	8192	40	8192	40	;BAND WIDTH
f 42 0 32768 -7	90	8192	80	8192	90	8192	80	8192	60	;BAND WIDTH
f 43 0 32768 -7	120	8192	100	8192	100	8192	100	8192	100	;BAND WIDTH
f 44 0 32768 -7	130	8192	120	8192	120	8192	120	8192	120	;BAND WIDTH
f 45 0 32768 -7	140	8192	120	8192	120	8192	120	8192	120	;BAND WIDTH
;ALTO
f 46 0 32768 -7	800	8192	400	8192	350	8192	450	8192	325	;FREQ
f 47 0 32768 -7	1150	8192	1600	8192	1700	8192	800	8192	700	;FREQ
f 48 0 32768 -7	2800	8192	2700	8192	2700	8192	2830	8192	2530	;FREQ
f 49 0 32768 -7	3500	8192	3300	8192	3700	8192	3500	8192	2500	;FREQ
f 50 0 32768 -7	4950	8192	4950	8192	4950	8192	4950	8192	4950	;FREQ
f 51 0 32768 -7	0	8192	0	8192	0	8192	0	8192	0	;dB
f 52 0 32768 -7	-4	8192	-24	8192	-20	8192	-9	8192	-12	;dB
f 53 0 32768 -7	-20	8192	-30	8192	-30	8192	-16	8192	-30	;dB
f 54 0 32768 -7	-36	8192	-35	8192	-36	8192	-28	8192	-40	;dB
f 55 0 32768 -7	-60	8192	-60	8192	-60	8192	-55	8192	-64	;dB
f 56 0 32768 -7	50	8192	60	8192	50	8192	70	8192	50	;BAND WIDTH
f 57 0 32768 -7	60	8192	80	8192	100	8192	80	8192	60	;BAND WIDTH
f 58 0 32768 -7	170	8192	120	8192	120	8192	100	8192	170	;BAND WIDTH
f 59 0 32768 -7	180	8192	150	8192	150	8192	130	8192	180	;BAND WIDTH
f 60 0 32768 -7	200	8192	200	8192	200	8192	135	8192	200	;BAND WIDTH
;SOPRANO
f 61 0 32768 -7	800	8192	350	8192	270	8192	450	8192	325	;FREQ
f 62 0 32768 -7	1150	8192	2000	8192	2140	8192	800	8192	700	;FREQ
f 63 0 32768 -7	2900	8192	2800	8192	2950	8192	2830	8192	2700	;FREQ
f 64 0 32768 -7	3900	8192	3600	8192	3900	8192	3800	8192	3800	;FREQ
f 65 0 32768 -7	4950	8192	4950	8192	4950	8192	4950	8192	4950	;FREQ
f 66 0 32768 -7	0	8192	0	8192	0	8192	0	8192	0	;dB
f 67 0 32768 -7	-6	8192	-20	8192	-12	8192	-11	8192	-16	;dB
f 68 0 32768 -7	-32	8192	-15	8192	-26	8192	-22	8192	-35	;dB
f 69 0 32768 -7	-20	8192	-40	8192	-26	8192	-22	8192	-40	;dB
f 70 0 32768 -7	-50	8192	-56	8192	-44	8192	-50	8192	-60	;dB
f 71 0 32768 -7	80	8192	60	8192	60	8192	70	8192	50	;BAND WIDTH
f 72 0 32768 -7	90	8192	90	8192	90	8192	80	8192	60	;BAND WIDTH
f 73 0 32768 -7	120	8192	100	8192	100	8192	100	8192	170	;BAND WIDTH
f 74 0 32768 -7	130	8192	150	8192	120	8192	130	8192	180	;BAND WIDTH
f 75 0 32768 -7	140	8192	200	8192	120	8192	135	8192	200	;BAND WIDTH
</CsScore>

</CsoundSynthesizer>