;WRITTEN BY IAIN MCCURDY, 2008

<CsoundSynthesizer>

<CsOptions>
-odevaudio -b800
</CsOptions>

<CsInstruments>

sr 		= 	44100
ksmps 		= 	10
nchnls 		= 	2

;FLTK INTERFACE CODE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		FLcolor		255, 255, 255, 0, 0, 0
	FLpanel	"Convert decibels to amplitude", 500, 120, 0, 0

;				IWIDTH IHEIGHT IX, IY
iddb		FLvalue	" ",      100,    18,   5,  45
idamp		FLvalue	" ",      100,    18,   5,  95

;					     		MIN   MAX IEXP ITYPE,  IDISP    IWIDTH IHEIGHT, IX, IY
gkdb, gihdb		FLslider	"Decibels",	0, 90.473,  0,  23,     iddb,     490,    25,    5, 20
gkamp, gihamp		FLslider	"Amplitude",	0,  32768,  0,  23,     idamp,    490,    25,    5, 70

;SET INITIAL VALUES FOR SLIDERS
		FLsetVal_i	0, 	gihdb
		FLsetVal_i	0, 	gihamp

		FLpanel_end

;INSTRUCTIONS AND INFO PANEL
				FLpanel	" ", 500, 240, 512, 0
;TEXT BOXES												TYPE | FONT | SIZE | WIDTH | HEIGHT | X | Y
ih		 	FLbox  	"          convert decibels to amplitude values               ", 	1,       5,    14,    490,    15,     5,  0
ih		 	FLbox  	"-------------------------------------------------------------", 	1,       5,    14,    490,    15,     5,  20
ih		 	FLbox  	"This example converts decibel values into amplitude values   ", 	1,       5,    14,    490,    15,     5,  40
ih		 	FLbox  	"that Csound uses to play a soundfile from a stored function  ", 	1,       5,    14,    490,    15,     5,  60
ih		 	FLbox  	"table. The opcode used is 'ampdb'. If the user moves the     ", 	1,       5,    14,    490,    15,     5,  80
ih		 	FLbox  	"'decibels' slider the 'amplitude' slider moves to show its   ", 	1,       5,    14,    490,    15,     5, 100
ih		 	FLbox  	"corresponding value. How the two scales for sound intensity  ", 	1,       5,    14,    490,    15,     5, 120
ih	  	 	FLbox  	"differ is evident visually through how the sliders move and  ", 	1,       5,    14,    490,    15,     5, 140
ih		 	FLbox  	"aurally through how they vary the intensity of the played    ", 	1,       5,    14,    490,    15,     5, 160
ih		 	FLbox  	"back soundfile. (The sound intensity can also be varied using", 	1,       5,    14,    490,    15,     5, 180
ih		 	FLbox  	"the 'amplitude' slider.) Decibels are converted back to      ", 	1,       5,    14,    490,    15,     5, 200
ih		 	FLbox  	"amplitude using the 'dbamp' opcode.                          ", 	1,       5,    14,    490,    15,     5, 220

				FLpanel_end
		FLrun

gisample	ftgen	0,0,2097152,1,"Songpan.wav",0,4,1		

instr	1
	kamp		=	ampdb(gkdb)
	ktrigger	changed	kamp
	FLsetVal 	ktrigger, kamp, gihamp
	kdb		=	dbamp(gkamp)
	ktrigger2	metro	kr
	FLsetVal 	ktrigger2, kdb, gihdb
	;OUTPUT		OPCODE  AMP | PITCH | START |       DUR          | FADE_TIME | SOURCE_SAMPLE_FUNCTION_TABLE
	asig		flooper	gkamp,  1,      0,   nsamp(gisample)/sr,       0,             gisample		;PLAY BACK SAMPLE LOOPED
	outs		asig, asig
endin

</CsInstruments>

<CsScore>
i 1 0 3600
</CsScore>

</CsoundSynthesizer>
