9;Written by Iain McCurdy, 2006

<CsoundSynthesizer>

<CsOptions>
-odevaudio -b400
</CsOptions>

<CsInstruments>

;USING THE FLsetVal_i OPCODE TO DEFINE THE INITIAL OUTPUT VALUE AND GRAPHIC POSITION OF AN FL-SLIDER 

sr		=	44100
kr		=	441
ksmps		=	100
nchnls		=	2
0dbfs		=	1	;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH

;		OPCODE	 LABEL       | WIDTH | HEIGHT | X | Y
		FLpanel	"FLsetVal_i",   800,    240,   50, 50

;VALUE DISPLAY BOXES			LABEL  | WIDTH | HEIGHT | X | Y
idfreq				FLvalue	" ",       80,    20,    10,  80

gkfreq,ihandle	FLslider	"Frequency", 200, 5000, -1, 3, idfreq, 780, 30, 10, 50

initval	=		500	;INITIAL VALUE FOR SLIDER
		FLsetVal_i	initval, ihandle

;TEXT BOXES																TYPE | FONT | SIZE | WIDTH | HEIGHT | X | Y
ih		 FLbox  	"FLsetVal_i is used to set an initial value for the slider. The following line:                 ", 	1,      5,     14,    800,    20,     0, 150
ih		 FLbox  	"FLsetVal_i 500, ihandle                                                                        ", 	1,      5,     14,    800,    20,     0, 170
ih		 FLbox  	"instructs it to adopt the value 500. As the slider uses exponential scaling a small inaccuracy ", 	1,      5,     14,    800,    20,     0, 190
ih		 FLbox  	"occurs.                                                                                        ", 	1,      5,     14,    800,    20,     0, 210

		FLpanel_end	;END OF PANEL CONTENTS
		FLrun		;RUN THE WIDGET THREAD

gisine	ftgen 0, 0, 65536, 10, 1		;FUNCTION TABLE THAT DEFINES A SINGLE CYCLE OF A SINE WAVE

instr 1
	kporttime	linseg	0,0.001,0.005,1,0.005	;CREATE A VARIABLE FUNCTION THAT RAPIDLY RAMPS UP TO A SET VALUE
	kfreq		portk	gkfreq, kporttime	;SMOOTH SLIDER VARIABLE
	afreq		interp	kfreq		;INTERPOLATE AND CREATE AN AUDIO RATE VERSION OF K-RATE VARIABLE
	asig		oscil	0.1, afreq, gisine	;SINE WAVE OSCILLATOR
		outs	asig, asig
endin

</CsInstruments>

<CsScore>
f 1 0 1024 10 1		;FUNCTION TABLE THAT DEFINES A SINGLE CYCLE OF A SINE WAVE
i 1 0 3600		;INSTRUMENT 1 WILL PLAY A NOTE FOR 1 HOUR
</CsScore>

</CsoundSynthesizer>