aboutsummaryrefslogtreecommitdiff
path: root/BUG8/BUG8.csd
blob: 5f27a8629a4d7870d13d9e746f7527b99ecf0f2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
sr = 44100
kr = 441
nchnls = 2
0dbfs = 1
seed 0

#include "wavetables.udo"

giampfn init -1
gifreqfn init -1
gifftsize = 1024


opcode SCReverb, aa, aakkjpo
	
		setksmps 1
	
	ainL, ainR, kFeedBack, kLPFreq, iSRate, iPitchMod, iSkip	xin
	iSRate	=  (iSRate <= 0 ? 1 : (sr / iSRate))
		if (iSkip != 0) igoto SkipInit
	
	afilt1	init 0
	afilt2	init 0
	afilt3	init 0
	afilt4	init 0
	afilt5	init 0
	afilt6	init 0
	afilt7	init 0
	afilt8	init 0
	
	; Delay times chosen to be prime numbers.
	; Works with sr=44100 ONLY. If you wish to
	; use a different delay time, find some new
	; prime numbers that will give roughly the
	; same delay times for the new sampling rate.
	; Or adjust to taste.
	
	idel1 = 2473.000 / (iSRate * 44100)
	idel2 = 2767.000 / (iSRate * 44100)
	idel3 = 3217.000 / (iSRate * 44100)
	idel4 = 3557.000 / (iSRate * 44100)
	idel5 = 3907.000 / (iSRate * 44100)
	idel6 = 4127.000 / (iSRate * 44100)
	idel7 = 2143.000 / (iSRate * 44100)
	idel8 = 1933.000 / (iSRate * 44100)
	
	; kFeedBack:
	; gain of reverb. Adjust empirically
	; for desired reverb time. .6 gives
	; a good small \\\"live\\\" room sound, .8
	; a small hall, .9 a large hall,
	; .99 an enormous stone cavern.
	
	; iPitchMod:
	; amount of random pitch modulation
	; for the delay lines. 1 is the \\\"normal\\\"
	; amount, but this may be too high for
	; held pitches such as piano tones.
	; Adjust to taste.
	
	; kLPFreq:
	; Cutoff frequency of lowpass filters
	; in feedback loops of delay lines,
	; in Hz. Lower cutoff frequencies results
	; in a sound with more high-frequency
	; damping.
	
	; k1-k8 are used to add random pitch modulation to the
	; delay lines. Helps eliminate metallic overtones
	; in the reverb sound.
	
	iPitchMod	=  iPitchMod / iSRate
	
	k1	randi 0.0010 * iPitchMod, 3.100 * iSRate, 0.06
	k2	randi 0.0011 * iPitchMod, 3.500 * iSRate, 0.90
	k3	randi 0.0017 * iPitchMod, 1.110 * iSRate, 0.70
	k4	randi 0.0006 * iPitchMod, 3.973 * iSRate, 0.30
	k5	randi 0.0010 * iPitchMod, 2.341 * iSRate, 0.63
	k6	randi 0.0011 * iPitchMod, 1.897 * iSRate, 0.70
	k7	randi 0.0017 * iPitchMod, 0.891 * iSRate, 0.90
	k8	randi 0.0006 * iPitchMod, 3.221 * iSRate, 0.44
	
	; apj is used to calculate \\\"resultant junction pressure\\\" for
	; the scattering junction of 8 lossless waveguides
	; of equal characteristic impedance. If you wish to
	; add more delay lines, simply add them to the following
	; equation, and replace the .25 by 2/N, where N is the
	; number of delay lines.
	
	apj	=  .25 * (afilt1+afilt2+afilt3+afilt4+afilt5+afilt6+afilt7+afilt8)
	
	adum1   delayr  1
	adel1   deltap3 idel1 + k1
		delayw  ainL + apj - afilt1
	
	adum2   delayr  1
	adel2   deltap3 idel2 + k2
		delayw  ainR + apj - afilt2
	
	adum3   delayr  1
	adel3   deltap3 idel3 + k3
		delayw  ainL + apj - afilt3
	
	adum4	delayr  1
	adel4   deltap3 idel4 + k4
		delayw  ainR + apj - afilt4
	
	adum5   delayr  1
	adel5   deltap3 idel5 + k5
		delayw  ainL + apj - afilt5
	
	adum6   delayr  1
	adel6   deltap3 idel6 + k6
		delayw  ainR + apj - afilt6
	
	adum7	delayr  1
	adel7	deltap3 idel7 + k7
		delayw  ainL + apj - afilt7
	
	adum8	delayr  1
	adel8	deltap3 idel8 + k8
		delayw  ainR + apj - afilt8
	
	; 1st order lowpass filters in feedback
	; loops of delay lines.
	
	kLPFreq	=  kLPFreq * iSRate
	
	afilt1	tone  adel1 * kFeedBack, kLPFreq
	afilt2	tone  adel2 * kFeedBack, kLPFreq
	afilt3	tone  adel3 * kFeedBack, kLPFreq
	afilt4	tone  adel4 * kFeedBack, kLPFreq
	afilt5	tone  adel5 * kFeedBack, kLPFreq
	afilt6	tone  adel6 * kFeedBack, kLPFreq
	afilt7	tone  adel7 * kFeedBack, kLPFreq
	afilt8	tone  adel8 * kFeedBack, kLPFreq
	
	; The outputs of the delay lines are summed
	; and sent to the stereo outputs. This could
	; easily be modified for a 4 or 8-channel
	; sound system.
	
	aoutL	= 0.35 * (afilt1 + afilt3 + afilt5 + afilt7)
	aoutR	= 0.35 * (afilt2 + afilt4 + afilt6 + afilt8)
	
	SkipInit:
		xout aoutL, aoutR
			endop


instr liner	
	index = p4
	isinit = p5
	iampscale = (((gifftsize / 2) - index) / (gifftsize / 2)) * 0.1
	isamp = (isinit == 1) ? random(0, iampscale) : tab_i(index, giampfn)
	isfreq = (isinit == 1) ? 440 : tab_i(index, gifreqfn)
	tabw oscil:k(1, random(0.01, 1), -1, random(0, 1)) * linseg(isamp, p3, random(0, iampscale)), index, giampfn
	tabw linseg(isfreq, p3, random(50, 1900)), index, gifreqfn

endin

instr rndoise
	ipanrange1 = p4
	ipanrange2 = p5
	ifreqmax = random(100, 1000)
	if (random(0, 1) > 0.3) then
		a1 oscil line(random(0.5, 1), p3, random(0.5, 1)), random(100, ifreqmax)
	else
		a1 noise line(random(0.5, 1), p3, random(0.5, 1)), random(-1, 1)
	endif

	if (random(0, 1) > 0.6) then
		a1 *= oscil(line(random(0.5, 1), p3, random(0.5, 1)), random(100, ifreqmax))
	endif

	if (random(0, 1) > 0.9) then
		a1 *= noise(line(random(0.5, 1), p3, random(0.5, 1)), random(-1, 1))
	endif
	
	if (random(0, 1) > 0.6) then
		a1 *= oscil(random:k(0.5, 1), random(100, ifreqmax))
	endif

	if (random(0, 1) > 0.9) then
		a1 *= noise(random:k(0.5, 1), random(-1, 1))
	endif
	
	if (random(0, 1) > 0.6) then
		a1 taninv a1 * line(random(1, 10), p3, random(1, 10))
	endif

	if (random(0, 1) > 0.6) then
		a1 butterhp a1, line(random(20, 2000), p3, random(20, 2000))
	endif

	if (random(0, 1) > 0.6) then
		a1 butterlp a1, line(random(500, 16000), p3, random(500, 16000))
	endif

	if (random(0, 1) > 0.5) then
		a1 *= oscil(1, random(1, 50))
	else
		a1 *= line(random(0, 1), p3, random(0, 1))
	endif

	if (random(0, 1) > 0.6) then
		a1 waveset a1, random(1, 20)
	endif

	a1 *= 0.5
	aL, aR pan2 a1, ipanrange1, ipanrange2
	outs aL, aR
endin


instr trigrndoise
	itime = 0
	imax = random(5, 20)
	while (itime < p3) do
		ilen = (p3 / imax) * random(0.6, 1.2)
		event_i "i", "rndoise", itime, ilen, random(0, 1), random(0, 1)
		itime += ilen * random(0.8, 1.1)
	od
endin


instr clicker
	aL noise 0.4, 0.4
	aR noise 0.4, 0.4
	kamp linseg 1, p3, 0
	outs aL*kamp, aR*kamp
endin


instr clickmaker
	idur random 0.001, 0.01
	kmetro metro random(1, 6)
	if (kmetro == 1) then
		event "i", "clicker", 0, idur
	endif
endin

instr 1
	ktime timeinsts
	isize = gifftsize / 2
	giampfn ftgen 0, 0, isize, 7, 0
	gifreqfn ftgen 0, 0, isize, 7, 0
	
	itime = 60
	kmetro metro 1/itime
	kinit init 1
	if (kmetro == 1) then
		kndex = 0
		while (kndex < isize) do
			event "i", "liner", 0, itime, kndex, kinit
			kndex += 1
		od
		if (kinit == 1) then
			kinit = 0
		endif
	endif

	event_i "i", "clickmaker", 0, 1

	kmetro2 metro 3
	if (ktime > 5 && kmetro2 == 1 && random:k(0, 1) > 0.95) then
		event "i", "trigrndoise", 0, random:k(0.6, 2)
	endif
	
	; pvsinit not working here..
	f1 pvsanal oscils(1, 440, 0), gifftsize, gifftsize/4, gifftsize, 1
	pvsftr f1, giampfn, gifreqfn
	f2L pvscale f1, 0.03 + oscil(0.01, 0.01)
	f2R pvscale f1, 0.03 + oscil(0.01, 0.02, -1, 0.26)

	a2L pvsynth f2L
	a2R pvsynth f2R
	a2L pareq a2L, 200, 0.3, 0.6
	a2R pareq a2R, 200, 0.3, 0.6

	k2mul = 3 * (abs(oscil(0.7, 0.1)) + 0.2)
	a2L *= k2mul
	a2R *= k2mul

	ay pvsynth f1
	ay *= abs(oscil(0.7, 0.001, -1, 0))
	;ay exciter ay, 3000, 20000, 10, 10

	a1L = ay
	a1R = ay
	;a1L, a1R SCReverb ay, ay, 0.9, 10000
	aL = a1L + a2L 
	aR = a1R + a2R
	
	outs aL, aR
endin




</CsInstruments>
<CsScore>


i1 0 100

</CsScore>
</CsoundSynthesizer>