;===================================================
;Schedule instrument that reads control tables from
;the score and implements some random processing. RP
;===================================================
	sr	=	44100
	kr	=	44100	
	ksmps	=	1	;Sounds cleaner this way.
	nchnls	=	2

	instr	1	;master control instrument
imaxamp	=	p4
ipchvar	=	p5
imaxden	=	p6
imaxdur	=	p7
insno	=	p8	
irndoff	=	p9/100	;random offset percentage for density
iroctmx	=	p10	;maximum random pitch deviation in oct
itptfn	=	p11
ibegpt	=	p12
iendpt	=	p13
iampfn	=	p14
idensfn	=	p15
idurfn	=	p16
ipchfn	=	p17
iroctfn	=	p18
ipanfn	=	p19

kptvar	oscil1i	0,iendpt-ibegpt,p3,itptfn ;master pointer into score tables
kpoint	=	ibegpt+kptvar
krndens	rand	irndoff	;randomized offset from current density
krndoct	rand	iroctmx	;randomization for pitch
krndens	=	1+krndens		;the density control factor
start:
ipoint	=	i(kpoint)
idur	tablei	ipoint,idurfn,1		;get the current duration
iamp	tablei	ipoint,iampfn,1		;get the current amplitude
icpch	tablei	ipoint,ipchfn,1		;get current center pitch
ipan	tablei	ipoint,ipanfn,1		;current pan center position
idens	tablei	ipoint,idensfn,1	;current density
iroct	tablei	ipoint,iroctfn,1	;current amount of random deviation in pitch
ipkamp	=	iamp*imaxamp
ipitch	=	7.00+icpch*ipchvar + iroct*i(krndoct) 
idens	=	idens*imaxden*i(krndens)
intvl	=	(1/idens)		;time interval between events
	timout	0,intvl,continue
	reinit	start
continue:
	schedule	insno,.001,idur*imaxdur,ipkamp,ipitch,ipan,ipoint
	endin

	instr	2	;oscil slave
ipoint	=	p7	;avoid the warning message
agate	linen	p4,p3*.1,p3,p3*.25
asig	oscili	agate,cpsoct(p5),1
ileft	=	sqrt(p6)
iright	=	sqrt(1-p6)
	outs	asig*ileft,asig*iright
	endin

	instr	3	;diskin slave
;	print	p3,p4,p5,p6,p7
iscale	=	p4/32767
;isfdur	=	1.508	;1.508 second duration
isfdur	=	1
istart	=	p7	;starting point for soundin file
ipitch	=	cpsoct(p5)/cpspch(9.00)
asound	diskin	"thewind.aif",ipitch,istart*isfdur,0
asound	=	asound*iscale
asig	linen	asound,p3*.1,p3,p3*.25
ileft	=	sqrt(p6)
iright	=	sqrt(1-p6)
	outs	asig*ileft,asig*iright
	endin
                               
        

;Test score for Schdgran.orc. 
f1 0 8192 10 1
;dur func 
f2	0	513	7	.021	256	.2	257	.021	
;amp func
f3	0	513	5	1	256	.125	128	.5	127	.1
;pch func (exponential rise of 3 octaves)
f4	0	513	5	.25	513	1
;pan func (offset cosine wave)
f5	0	513	19	1	1	90	1
;density func (hamming window - bell shaped)
f6	0	513	20	1
;random pitch deviation
f7	0	513	7	0	256	1	257	0
;no change function
f8	0	2	2	1	1
;linear rise
f9	0	513	7	0	513	1
;linear decay
f10	0	513	7	1	513	0
;.25 sine
f11	0	513	9	.25	1	0
;	st	dur	pkamp	pchvar	maxden	maxdur	insno	rndoff	rpitmax	tptfn	begpt	endpt
i01	0	10	20000	3	100	.2	2	25	.5	9	0	1	
;	ampfn	denfn	durfn	pchfn	rpchfn	panfn
;	3	6	2	4	7	5
;	st	dur	pkamp	pchvar	maxden	maxdur	insno	rndoff	rpitmax	tptfn	begpt	endpt
i01	10	10	30000	3	100	.2	3	0	.5	9	0	1
;	st	dur	pkamp	pchvar	maxden	maxdur	insno	rndoff	rpitmax	tptfn	begpt	endpt
i01	20	10	15000	2	200	.08	3	25	0	11	0	1
;	ampfn	denfn	durfn	pchfn	rpchfn	panfn
	8	8	8	8	8	5
             

Download schdgran.orc

Download thewind.zip

Download schdgran.sco