/*
This is an example of bitmap images used to control the
amplitude of a bank of oscillators (additive synthesis).

It doesn't display the images.

There are 10 different pictures used in this example, and the user can
switch the reading from a picture to another.

Also there are other parameters controllable by means of MIDI control change
messages:

MIDI Control 1 controls bitmap picture scanning speed (phasor rate)
MIDI Control 2 selects frequency table. 2 tables are provided, the first
               contains linear Hertz distance for each element 
               (harmonic progression), the second exponential (geometric progression)
MIDI Control 3 adjusts frequency range expansion/compression
MIDI Control 4 controls absolute phase of horizontal dimension (or starting point of scanning)
MIDI Control 5 selects the image (10 different images are provided)
MIDI Control 6 controls base frequency offset (transposition to obtain 
               best results for each configuration)
MIDI Control 7 selects audio waveform (sine and other waveforms are provided)
MIDI Control 8 controls amplitude envelope attack time
MIDI Control 9 controls vibrato depth

*/

<CsoundSynthesizer>
<CsOptions>

-+P -+K -+Om0

</CsOptions>
<CsInstruments>
sr=44100
kr=882;1764
ksmps=50
nchnls=2


giTabWidths ftgen	51,0,128,2,0
giTabHeights ftgen	52,0,128,2,0

iwidth,iheight,ibpp bmopen	"C:/My_Docs/Visual_C/paintlib/testpic/rgb8.pct",1, 2
                       tabw_i	iwidth,	1, giTabWidths
		   tabw_i	iheight, 1, giTabHeights
iwidth,iheight,ibpp bmopen	"C:/CSOUND/ga2000/spirali1.bmp",2, 2
                       tabw_i	iwidth,	2, giTabWidths
		   tabw_i	iheight, 2, giTabHeights
iwidth,iheight,ibpp bmopen	"C:/CSOUND/ga2000/spirali2.bmp",3, 2
                       tabw_i	iwidth,	3, giTabWidths
		   tabw_i	iheight, 3, giTabHeights
iwidth,iheight,ibpp bmopen	"C:/CSOUND/ga2000/spirali3.bmp",4, 2
                       tabw_i	iwidth,	4, giTabWidths
		   tabw_i	iheight, 4, giTabHeights
iwidth,iheight,ibpp bmopen	"C:/CSOUND/ga2000/nasca6.bmp",5, 2
                       tabw_i	iwidth,	5, giTabWidths
		   tabw_i	iheight, 5, giTabHeights
iwidth,iheight,ibpp bmopen	"C:/CSOUND/ga2000/nasca7.bmp",6, 2
                       tabw_i	iwidth,	6, giTabWidths
		   tabw_i	iheight, 6, giTabHeights
iwidth,iheight,ibpp bmopen	"C:/CSOUND/ga2000/nasca7b.bmp",7, 2
                       tabw_i	iwidth,	7, giTabWidths
		   tabw_i	iheight, 7, giTabHeights
iwidth,iheight,ibpp bmopen	"C:/CSOUND/ga2000/nasca7c.bmp",8, 2
                       tabw_i	iwidth,	8, giTabWidths
		   tabw_i	iheight, 8, giTabHeights
iwidth,iheight,ibpp bmopen	"C:/CSOUND/ga2000/nasca7d.bmp",9, 2
                       tabw_i	iwidth,	9, giTabWidths
		   tabw_i	iheight, 9, giTabHeights
iwidth,iheight,ibpp bmopen	"C:/CSOUND/ga2000/nasca7e.bmp",10, 2
                       tabw_i	iwidth,	10, giTabWidths
		   tabw_i	iheight, 10, giTabHeights
giElems	init	32

iTabExp	ftgen 	101,0,129,5, .1, 127, 1,128,1		;ascending exponential curve
giTabExp	ftgen 	100,0,129,-24, iTabExp, 0, 1	;** exponential curve for slider mapping

giTabFreq1 ftgen	1,0,512,-7, 1,giElems,8,128,8
giTabFreq2 ftgen	2,0,512,-5, 1,giElems,2,128,2

giTabRed	ftgen	4,0,512,2, 0
giTaGreen	ftgen	5,0,512,2, 0
giTaBlue	ftgen	6,0,512,2, 0

giTaScale ftgen	32,0,512,5, 1,giElems,.08
giTemp	ftgen	33,0,512,2,0

itabsize	init	2048
gaReverb	init	0

isine	ftgen	10,0,itabsize,10,1
isine	ftgen	11,0,itabsize,10,1,1,1
isine	ftgen	12,0,itabsize,10,1,0,1
isine	ftgen	13,0,itabsize,10,1,.5,.2,.1,0,.05,.02,0,.01,0,.01
isine	ftgen	14,0,itabsize,10,1,0,.5,.2,0,.1
isine	ftgen	15,0,itabsize,10,.5,1,.5,.3,.2,.1
isine	ftgen	16,0,itabsize,10,1,0,0,0,0,0,.5
isine	ftgen	17,0,itabsize,10,1,1,0,1,0,.5,0,.1
isine	ftgen	18,0,itabsize,10,1,.2,.1,.05
isine	ftgen	19,0,itabsize,10,1,.1,0,0,0,.1,.05,.02,.01
isine	ftgen	20,0,itabsize,10,0,0,0,1,1,1


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	instr	100
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
gk_1,gk_2,gk_3,gk_4,gk_5,gk_6,gk_7,gk_8,\
gk_9,gk_10,gk_11,gk_12,gk_13,gk_14,gk_15,gk_16	slider16	1,\
\;	ctl	min	max	init	func
	1,	0,	1,	.05,	giTabExp,	\;1 scanning speed (phasor rate)
	2,	1,	2.5,	1,	0,	\;2 frequency table select
	3,	1,	5,	1,	0,	\;3 freqency range adjustment
	4,	0,    	1,	0,	0,	\;4 absolute phase of horizontal dimension
	5,	1,	10.5,	1,	0,	\;5 change image
	6,	.25,	8,	.5,	giTabExp,	\;6 base frequency offset
	7,	10,	20.5,	10,	0,	\;7 audio waveform
	8,	0.01,	5,	0.01,	giTabExp,	\;8 amplitude envelope attack time
	9,	0,	50,	0,	0,	\;9 vibrato depth
	10,	300,	8000,	3200,	0,	\;10 
	11,	0,	2,	0,	0,	\;11 
	12,	0,	3,	0,	0,	\;12 
	13,	0,	.2,	.05,	0,	\;13 
	14,	0,	.5,	0,	0,	\;14 
	15,	0,	3,	0,	0,	\;15 
	16,	.05,	2,	1,	0	 ;16 
a1	tone	gaReverb,3000
a2	nreverb	a1*.06, 4.5, .1
a1	delay	a2,.0899
a3	delay	a2,.112345	
	outs	a1,a3
	clear	gaReverb

	endin


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	instr	1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ifreq	cpsmidi
iamp	ampmidi 10
ktime	midic7	0, 2,.2
kphs	phasor	gk_1

iTabFreq	=	i(gk_2)

iBMP	=	i(gk_5) ;number of present scanned picture
iwidth	tab_i	i(gk_5),giTabWidths
iheight	tab_i	i(gk_5),giTabHeights

isine	=	i(gk_7)

kphs	=	(kphs+gk_4)*iwidth
kphs	limit	kphs,0,iwidth-1
;		kphs, ihorLines,      ifn,  istartLine, ifnR, ifnG, ifnB;
	bmscani	kphs, iheight/giElems, iBMP,  0,    giTabRed,giTaGreen,giTaBlue
	
	vaddv	giTabRed,giTaGreen, giElems
	vaddv	giTabRed,giTaBlue, giElems
	vmultv	giTabRed,giTaScale, giElems
	vport	giTabRed,.025,giElems
	vcopy	giTemp,iTabFreq,giElems
	vpow	giTemp,gk_3,giElems
kenv	linsegr	0,i(gk_8),iamp,1,iamp,.1,0
kvib	vibr	gk_9,4,10
a1	adsynt	kenv,ifreq*gk_6*cent(kvib),isine,giTemp,giTabRed,giElems,1
a1	tone	a1,1000
ipan	linrand	2.99
ipan	=	int(ipan)/2
	vincr	gaReverb,a1
	outs	a1*ipan,a1*(1-ipan)
	endin




</CsInstruments>
<CsScore>
i100 0 3600
f0 3600
e

</CsScore>
</CsoundSynthesizer>
