;Garrett Frierson		0518189		Jfrierson@berklee.edu

;Democrissy.csd

;This is a 90 second piece influenced by the sounds of politcal discourse.

;This instrument is mainly focused on the use of global variables and controlling signal flow with the zak opcodes. For this instrument I created a global mixer, distortion, and phase vocoder, as well as modifying the global reverb and comb filter. I wanted to start using csound more modularly, so I created an instruments that had multiple outputs and inputs, accepting audio and control data from various sources. I created instr 901 to only be an envelope so I could use to control the amplitude of a different instrument more specifically, it is a model for a way of dividing the p-fields into ways that I can manage easier visually. By splitting the amplitude envelope (or other parameters as needed) away from the rest of the instrument, I find it easier to troubleshoot and direct my action. I have not yet figured out to make the aux sends from my global mixer work, I think it has to do with the rendering order of instruments, but am not yet sure.

<CsoundSynthesizer>

<CsOptions>
-odac
</CsOptions>
<CsInstruments>
sr 		= 		44100
kr 		= 		4410
ksmps 	= 		10
nchnls 	= 		2
0dbfs		=	1

zakinit	24, 12	;initialize 24 a-rate and 12 k-rate zak variables to pass signal between instruments. 1-12 go to the mixer, and 13-24 ar aux sends
gadist	init	0
gacmb	init	0
garvb	init	0
gavc	init	0



;_____________ ______________________________ _______________________________ ___________________________ ____________________;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
;																						;
;	CONTROLS	CONTROLS	CONTROLS	CONTROLS	CONTROLS	CONTROLS	CONTROLS	CONTROLS	CONTROLS	CONTROLS		;
;_________________ __________________ _______________________________ ________________________________ _______________________;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

		instr 1	;ADSR ENVELOPE controlling the volume of gavc in the global mixer
idur		=	p3
iatk		=	p4
iatkpk	=	p5
idec		=	p6
isuslvl		=	p7
isus	=	p8
irel		=	p9
kenv	linseg	.01, iatk, iatkpk, idec, isuslvl, isus, isuslvl, irel, .001
zkw	kenv, 1
		endin
;_____________ ______________________________ _______________________________ ___________________________ ____________________;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
;																						;
;	INSTRUMENTS		INSTRUMENTS		INSTRUMENTS		INSTRUMENTS		INSTRUMENTS		INSTRUMENTS		INSTRUMENTS		;
;_________________ __________________ _______________________________ ________________________________ _______________________;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

		instr 102
idur	=		p3
iamp	=		ampdb(p4)
ifrq	=		cpspch(p5)	
ipan	=		p6
irvbsnd	=		p7
icmbsnd	=	p8
idistsnd	=	p9
ivcsnd	=	p10
ilfoamp	=	p11
ilfofq	=	p12
kenv	linseg	0, 7, 1, idur-14, 1, 7, 0
klfo	oscil		ilfoamp, ilfofq, 1	;pitch lfo
kpenv	linseg	1, idur/6, .6, idur/6, 1.1, idur/12, 2, idur/12, .99, idur/6, 1
asig1    oscil	iamp, (ifrq*kpenv)*klfo, 1
asig	= asig1*kenv
zawm	asig, 1	;sending the signal to the global mixer
zawm	asig, 2
zawm	asig, 17	;sending the signal to the global mixer
zawm	asig, 18
garvb	=		garvb+(asig*irvbsnd)	;send to garvb
gacmb	=		gacmb+(asig*icmbsnd)	;send to gacmb
gadist	=	gadist+(asig*idistsnd)	;send to gadist
gavc	=	gavc+(asig*ivcsnd)		;send to vocoder

		endin
		
		instr 101
idur	=		p3
iamp	=		ampdb(p4)
ifrq	=		cpspch(p5)	
ipan	=		p6
irvbsnd	=	p7
icmbsnd	=	p8
idistsnd	=	p9
ivcsnd	=	p10
asig1    oscil	.25, ifrq/2, 2
asig2    oscil	.25, ifrq/1.5, 2
asig3    oscil	.25, ifrq, 2
asig4    oscil	.25, ifrq*2, 2
asig = (asig1+asig2+asig3+asig4)*iamp
zawm	asig, 1	;send to global mixer
zawm	asig, 2
garvb	=		garvb+(asig*irvbsnd)	;send to garvb
gacmb	=		gacmb+(asig*icmbsnd)	;send to gacmb
gadist	=	gadist+(asig*idistsnd)	;send to gadist
gavc		=	gavc+(asig*ivcsnd)		;send to vocoder
;zawm	asig, 15	;send to vocoder stereo
;zawm	asig, 16
	endin
		
		instr   103
idur	=		p3
iamp	=		p4
ifrq	=		cpspch(p5)
ifun	=		p6
iatk	=		p7
irel	=		p8
iatkfun	=		p9
index1	=		p10
index2	=		p11
index3	=		p12
kamp		=	p13
irvbsnd	=	p14
icmbsnd	=	p15
idistsnd	=	p16
ivcsnd	=	p17
kpan	oscil	.5, .5, 1
kcps	=	ifrq
kenv	envlpx	1, iatk, idur, irel, iatkfun, .7, .01
kmodswp	linseg	index1, idur/2, index2, idur/3, index3
kbuzswp oscil kamp, kcps, 1    
asig4	  buzz	kenv, ifrq*.749, kbuzswp, ifun				;another buzz with lots of harmonics to provide crackling
asig3   foscil 	kenv, ifrq, 1, 1, kmodswp, ifun
asig2   buzz   	kenv, ifrq*.501, kbuzswp+1, ifun
asig1 	pluck 	iamp, ifrq*.5, ifrq, 0, 1
asig	=		asig1+asig2+asig3+asig4
asigL	=	asig*(sqrt(1-(kpan+.5)))
asigR	=	asig*(sqrt(kpan+.5))
asigdL =	asigL*iamp
asigdR =	asigR*iamp
		zawm	asigdL, 1			;to mixer
		zawm	asigdR, 2
garvb	=		garvb+(asig*irvbsnd)	;send to garvb
gacmb	=		gacmb+(asig*icmbsnd)	;send to gacmb
gadist	=	gadist+(asig*idistsnd)	;send to gadist
;gavc	=	gavc+(asig*ivcsnd)		;send to vocoder mono
	zawm asigL, 15
	zawm asigR, 16				;send to vocoder stereo
		endin

		
		
			instr 104	;RESONANT FILTER MODULE
idur	=		p3
iamp	=		p4
ifrq	=		p5
iatk	=		p6
irel	=		p7
icut1	=		p8
icut2	=		p9
ipan	=		p10
irvbsnd	=	p11
icmbsnd	=	p12
idistsnd	=	p13
ivcsnd	=	p14
kenv	linen	iamp, iatk, idur, irel ; controlling the amount of seperation between resonant bandpass filters
kcut	expon	icut1, idur, icut2
ainL	zar	17
ainR	zar	18	
ares	resony	ainL, kcut, .5, 5, kenv 		;resony is a bank of resonant bandpass filters
ares2	resony	ainR, kcut*.5, 1, 5, kenv 		
aLout	=	ares*(sqrt(1-ipan))
aRout	=	ares*(sqrt(ipan))
	zawm	aLout, 10
	zawm	aRout, 11
;asig	=	(ares/2)+(ares2/2)
asig	=	ares
garvb	=		garvb+(asig*irvbsnd)	;send to garvb
gacmb	=		gacmb+(asig*icmbsnd)	;send to gacmb
gadist	=	gadist+(asig*idistsnd)	;send to gadist
gavc		=	gavc+(asig*ivcsnd)		;send to vocoder
;zawm	asig, 15	;send to vocoder stereo
;zawm	asig, 16
		endin
;_____________ ______________________________ _______________________________ ___________________________ ____________________;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
;																						;
;	GLOBAL MIXER 	GLOBAL MIXER	GLOBAL MIXER	GLOBAL MIXER	GLOBAL MIXER	GLOBAL MIXER	GLOBAL MIXER	;
;_________________ __________________ _______________________________ ________________________________ _______________________;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

		instr 2000	; global mixer  using clip
idry	=	p4	;dry signal level
irvw	=	p5	;reverb signal level
icmw	=	p6	;panned comb signal level
idsw	=	p7	;distortion signal level
ivc	=	p8
irsn	=	p9
kenv1	zkr	1
a1	zarg 1, idry	;mix in dry L
a2 	zarg 2, idry	;mix in dry R
arvL	zarg 3, irvw	;mix in reverb L
arvR 	zarg 4, irvw	;mix in reverb R
acmL	zarg 5, icmw	;mix in comb L
acmR	zarg 6, icmw	;mix in comb R
adst	zarg 7, idsw	;mix in distortion (mono)
avcL	zarg 8, ivc*kenv1		;mix vocoder L
avcR	zarg 9, ivc*kenv1		;mix vocoder L
arsnL	zarg 10, irsn
arsnR	zarg 11, irsn
auxad1L	=	acmL+adst+avcL+arsnL		;aux send Left to reverb	
auxad1R	=	acmR+adst+avcR+arsnR		;aux send Right to reverb
;auxad2L	=	acmL			;aux send Left to vocoder
;auxad2R	=	acmR			;aux send Right to vocoder
;auxad3L	=	a1			;aux send Left to 
;auxad3R	=	a2			;aux send Right to
/*auxad4	=				;mono aux send to
auxad5	=				;mono aux send to
auxad6	=				;mono aux send to			*/
	zaw	auxad1L, 13				;L send to reverb
	zaw	auxad1R, 14				;R send to reverb
;	zaw	auxad2L, 15				;L send to vocoder
;	zaw	auxad2R, 16				;R send to vocoder
;	zaw	auxad3L, 17				;L send to resonant bp filters
;	zaw	auxad3R, 18				;R send to	resonant bp filters
/*	zaw	auxad4, 19				;send to
	zaw	auxad5, 20				;send to
	zaw	auxad6, 21				;send to			*/

aLm	=	a1+arvL+acmL+adst+avcL+arsnL
aRm	=	a2+arvR+acmR+adst+avcR+arsnR
aL	clip aLm, 2, 1
aR	clip aRm, 2, 1
	outs	aL, aR
	zacl	0, 24
	endin
;_____________ ______________________________ _______________________________ ___________________________ ____________________;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
;																						;
;	GLOBAL RACK 	GLOBAL RACK 	GLOBAL RACK 	GLOBAL RACK 	GLOBAL RACK 	GLOBAL RACK 	GLOBAL RACK 	;
;_________________ __________________ _______________________________ ________________________________ _______________________;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;


	instr 1090			;GLOBAL DISTORTION using distor1
	
abal	=	gadist
iamt1	=	p4
iamt2	=	p5
;adst clip gadist, 2, .5
kshpamt	line iamt1, p3, iamt2
adst	powershape gadist, kshpamt	
adist	balance adst, abal
zawm	adist, 7
clear	gadist
	endin
	
		instr	1091		;GLOBAL COMB FILTER using comb
;denorm gacmb
idur	=		p3
itime 	= 		p4
iloop 	= 		p5
ipfq		=	p6
;irnd 	betarand	10,	1,	1	;random numbers between 0 and 10 to create random panning
;ipan =	irnd/10
klfo	oscil 1, ipfq, 1				;kfo controlled panning
kenv	linen	1, .01, idur, .01
acomb 	comb	gacmb, itime, iloop, 0
zawm		(acomb*(sqrt(1-klfo)))*kenv,	5
zawm		(acomb*klfo)*kenv, 6
clear gacmb
	endin
	
	instr 109				;GLOBAL PHASE VOCODER using cross2
agin	=	gavc
ainL	zar 15
ainR	zar 16

idur	=		p3
iamp	=		p4
ifrq	=	cpspch(p5)

isize	=	4096			;window size of fft for cross
ioverlap	=	2 		;window overlap factor of cross
iwin	=	3 			;cross fn
kbias init 1

;kenv	expseg	1, idur/4, 1, idur/2, .5, idur/4, .1
aspk loscil 1, ifrq, 5
;aspk	diskin	"hellorcb.aif", ifrq			;for single shot sampling
;asigL	cross2	agin, aspk, isize, ioverlap, iwin, kbias	;for looped sampling  || for mono
;asigR	cross2	agin, aspk, isize, ioverlap, iwin, kbias
asigL	cross2	ainL, aspk, isize, ioverlap, iwin, kbias	;for stereo
asigR	cross2	ainR, aspk, isize, ioverlap, iwin, kbias
;aoutL	balance asigL, agin
;aoutR	balance asigR, agin
;	zawm	aoutL, 8
;	zawm	aoutR, 9
	zawm	asigL, 8
	zawm	asigR, 9

clear	gavc
		endin

	

			instr 	1099	;GLOBAL REVERB using reverbsc
denorm garvb
idur	=		p3
irvbtim	=		p4
ihiatn	=		p5
iaux1	=	p6
auxL	zarg	13, iaux1
auxR	zarg	14, iaux1			;mixing in other globals signal to get reverb
agrvL		=	garvb+auxL
agrvR		=	garvb+auxR
arvbL,arvbR	reverbsc	agrvL, agrvR, irvbtim, ihiatn
zawm		arvbL, 3
zawm		arvbR, 4
clear garvb
		endin
		





	
</CsInstruments>
<CsScore>

f1  0 4096 10   1
f2  0 4096 10   1  .5 .333 .25 .2 .166 .142 .125 .111 .1 .09 .083 .076 .071 .066 .062
f3  0 4097 20   2  1
f5  0 0    1   "whatdemoc.aif" 	0 	4 	0
f10 0 513  5   .01  64   1   64   .5   64  .99  64   .6  64  .98  64  .7  64 .97  32  .8  32 1


;a 0 0 10
;inst		 st	dur   dry		rvbw		 cmbw		distw		vcw	resw
;===================================================================	
i 2000	0	90 	0.3		0.5		.001		0.01		.1	.0005


;ins	strt	dur 	
;===================================================================
i 1090 0 	90 	.01	.01	
	
;ins	strt	dur 	time	loop panfreq
;===================================================================
i 1091 0 	90 	10 	.2	4

;i	 s	dur	amp	frq
i 109 0	80 	1	8.00

;	st	dur	rvbtim	hfroll	aux1in
;===================================================================

i 1099 0	90	.9  	15000		1

;VOLUME ENVELOPE FOR vocoder

; 		s	dur	atk	atkpeak	dec	suslevel	sustime	rel		
;===================================================================
i 1		20	40	20	1		10		.5	10		10
;		 st	dr 	amp	frq		pan	rvbsnd	cmbsnd	distsnd	vcdsend	lfoamp	lfofrq	
;=================================================================================
i 102		0	 80	0	6.02		1	1		1 		1		0		1		1

;ins		st 	dur dry	frq	fun	atk	rel	atkfun indx1    indx2	index3	kamp	rvbsnd	cmbsnd	distsnd	vcdsend
;========================================================
i 103		20	 44	0	4.09	 1 	.01	.2	10	 1		100 300000		 15		0.001		0		0	1	




;	 st	dr 	amp	frq		pan	rvbsnd	cmbsnd	distsnd	vcsnd
;=================================================================================
;i 101 0	 15	.00001	9.00		.5		0.001	0 		0		1	


;		s	dur	amp	frq	atk	rel	cut1	cut2	pan	rvbsnd	cmbsnd	distsnd	vcsnd
;=================================================================================
i 104		3	1	.1	20000	.01	.01	10000	100	1	.0001		0		0		0.1	
i 104		11	.3	.1	20000	.01	.01	1000	10000	0	.0005		0		0		.01
i 104		20	.5	.1	20000	.01	.01	1000	10000	.7	.0008		0		0		.01	
i 104		33	.2	.1	20000	.01	.01	1000	20000	.1	.0003		0		0		0	
i 104		46	1	.05	20000	.01	.01	10000	100	.5	.001		0		0		0.1	
i 104		52	1	.1	20000	.01	.01	10000	100	.5	.001		0		0		0.1	
i 104		62	1	.15	20000	.01	.01	10000	100	.5	.001		0		0		0.1	


e


</CsScore>

</CsoundSynthesizer><bsbPanel>
 <label>Widgets</label>
 <objectName/>
 <x>72</x>
 <y>179</y>
 <width>400</width>
 <height>200</height>
 <visible>true</visible>
 <uuid/>
 <bgcolor mode="nobackground">
  <r>231</r>
  <g>46</g>
  <b>255</b>
 </bgcolor>
 <bsbObject version="2" type="BSBVSlider">
  <objectName>slider1</objectName>
  <x>5</x>
  <y>5</y>
  <width>20</width>
  <height>100</height>
  <uuid>{09b24a91-9aac-4937-98f0-0a21fc8c20f8}</uuid>
  <visible>true</visible>
  <midichan>0</midichan>
  <midicc>-3</midicc>
  <minimum>0.00000000</minimum>
  <maximum>1.00000000</maximum>
  <value>0.00000000</value>
  <mode>lin</mode>
  <mouseControl act="jump">continuous</mouseControl>
  <resolution>-1.00000000</resolution>
  <randomizable group="0">false</randomizable>
 </bsbObject>
</bsbPanel>
<bsbPresets>
</bsbPresets>
<MacGUI>
ioView nobackground {59367, 11822, 65535}
ioSlider {5, 5} {20, 100} 0.000000 1.000000 0.000000 slider1
</MacGUI>
