aboutsummaryrefslogtreecommitdiff
path: root/BUG6/instruments.udo
blob: 55a7b93f1e9c242dcf5a6318c046fa1f1d79d864 (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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
#ifndef UDO_INSTRUMENTS
#define UDO_INSTRUMENTS ##
/*
	Debugger - Unfixed Bugs : BUG #4

	Sound generators
	Names should correspond to those used in BID file, prepended with play_
*/


#include "wavetables.udo"
#include "bussing.udo"
#include "bid.udo"

instr play_303
	iamp = bid_getparameter(p4, p5, 2)

	inote1 = table(p4+1, gibid_chordfn, 0, 0, 1) - 24

	ifilter = random(30, 50)

	ifrq1 = 440 * exp(log(2) * (ifilter - 69) / 12)	; filter start freq.
	kamp linseg 1, p3*0.8, 1, p3*0.2, 0
	kcps init cpsmidinn(inote1)
	kffrq port 0, 60/150, ifrq1		; filter frequency
	a1 phasor kcps		; oscillator
	a1 = 1 - 2 * a1

	a1x butterbp a1, kffrq, kcps * 1.0			; filters
	a1x =  a1x * (2 + kffrq / kcps)	; correct amplitude
	a1 = a1x + a1 * 0.25 ; 0.5
	a1 butterlp a1, kffrq

	a1 = taninv(a1 * 2.5 * iamp)	; distortion ; 2.5

	keqf limit kffrq * 4, 10, sr * 0.48	; EQ frequency
	a1 pareq a1 * 0.6, keqf, 4.0, 1.0, 2
	a1 pareq a1, 50, 1.3, 0.6
	a1 pareq a1, 130, 0.6, 0.6
	a1 = a1 * kamp * 0.8
	a1 *= 1-gkpump
	aL, aR pan2 a1, random(0.3, 0.7)
	;bus_mix("delay2", aL, aR)
	bus_mix("master", aL, aR)
endin


instr play_303b
	iamp = bid_getparameter(p4, p5, 2)
	ifilter = 50 ;random(50, 90)
	index = 30-p4
	inote = table(max(1, index), gibid_chordfn, 0, 0, 1) -12

	ifrq1 = 440 * exp(log(2) * (ifilter - 69) / 12)	; filter start freq.
	kamp linseg 1, p3*0.8, 1, p3*0.2, 0
	kcps init cpsmidinn(inote)
	kffrq port 0, 60/150, ifrq1		; filter frequency
	a1 phasor kcps		; oscillator
	a1 = 1 - 2 * a1

	a1x butterbp a1, kffrq, kcps * 1.0			; filters
	a1x =  a1x * (2 + kffrq / kcps)	; correct amplitude
	a1 = a1x + a1 * 0.25 ; 0.5
	a1 butterlp a1, kffrq

	a1 = taninv(a1 * 2 * iamp)	; distortion ; 2.5

	keqf limit kffrq * 4, 10, sr * 0.48	; EQ frequency
	a1 pareq a1 * 0.4, keqf, 4.0, 1.0, 2
	a1 butterhp a1, 250
	a1 = a1 * kamp * 0.8
	a1 *= 1-gkpump
	aL, aR pan2 a1, random(0.3, 0.7)
	bus_mix("master", aL, aR)
endin



instr play_blip
	iamp = bid_getparameter(p4, p5, 2)
	inote1 = table(p4+3, gibid_chordfn, 0, 0, 1) +12
	inote2 = table(p4+5, gibid_chordfn, 0, 0, 1) +12
	a1 oscil 1, cpsmidinn(inote1)
	a2 oscil 1, cpsmidinn(inote2)
	kamp linseg 1, p3*0.2, 0, p3*0.8, 0
	aL = a1 * kamp
	aR = a2 * kamp
	aL butterhp aL, 150
	aR butterhp aR, 150
	bus_mix("master", aL, aR)
endin

instr play_blip
	a1 oscil 0.6, 4400
	kamp line 1, p3, 0
	a1 *= kamp

	bus_mix("delay2", a1, a1)
endin


instr play_clap
	iamp = bid_getparameter(p4, p5, 2)
	aL noise 1, 0.3
	aR noise 1, 0.4
	aL butterbp aL, 1200, 700
	aR butterbp aR, 1200, 700
	aL taninv aL*7
	aR taninv aR*7
	
	kamp linseg 2, p3, 0
	aL *= kamp * iamp
	aR *= kamp * iamp
	bus_mix("master", aL, aR)
	
endin

instr play_hat1
	iamp = bid_getparameter(p4, p5, 2)
	idel = random(0.001, 0.02)
	xtratim idel
	p3 = random(0.02, 0.1)
	kfreq line 300, p3, 100
	aenv expsega .1, .0005, 1, p3 - .0005, .01
	asqr1 oscil 1, kfreq, gifnSquare, -1
	asqr2 oscil 1, kfreq*1.4471, gifnSaw, -1
	asqr3 oscil 1, kfreq*1.6170, gifnSaw, -1
	asqr4 oscil 1, kfreq*1.9265, gifnSaw, -1
	asqr5 oscil 1, kfreq*2.5028, gifnSaw, -1
	asqr6 oscil 1, kfreq*2.6637, gifnSaw, -1
	a808 sum asqr1, asqr2, asqr3, asqr4, asqr5, asqr6
	a808 butterhp a808, 4270
	a808 butterhp a808, 4270
	aout = a808 * aenv * iamp * 0.5
	aout delay aout, idel
	bus_mix("master", aout, aout)
endin

instr play_hat2
	iamp = bid_getparameter(p4, p5, 2)
	ixtend = bid_getparameter(p4, p5, 4)
	idel1 = random(0.005, 0.02)
	idel2 = random(0.005, 0.02)
	xtratim(max(idel1, idel2))
	if (ixtend == 0) then
		p3 = 0.1
	endif

	kfreq line 800, p3, 300
	aenv expsega .1, .0005, 1, p3 - .0005, .01
	asqr1 oscil 1, kfreq, gifnSquare, -1
	asqr2 oscil 1, kfreq*1.4471, gifnSquare, -1
	asqr3 oscil 1, kfreq*1.6170, gifnSquare, -1
	asqr4 oscil 1, kfreq*1.9265, gifnSquare, -1
	asqr5 oscil 1, kfreq*2.5028, gifnSaw, -1
	asqr6 oscil 1, kfreq*2.6637, gifnSaw, -1
	a808 sum asqr1, asqr2, asqr3, asqr4, asqr5, asqr6
	a808 butterhp a808, 3270
	a808 butterhp a808, 3270
	aout = a808 * aenv * iamp * 1.1
	aL delay aout, idel1
	aR delay aout, idel2
	if (i(gksection) == 1 && random(0, 1) > 0.7) then
		bus_mix("delay2", aL*0.4, aR*0.4)
	endif
	bus_mix("master", aL, aR)
endin


/*
	Blocky square-ish sounding FM bass
*/
instr play_mel1
	iamp = bid_getparameter(p4, p5, 2)
	inote1 = tab_i(ftlen(gibid_chordfn) - 3, gibid_chordfn)
	inote2 = tab_i(ftlen(gibid_chordfn) - 4, gibid_chordfn)
	a1 foscil 0.46, cpsmidinn(inote1), 1, 2, 1, gifnSine
	a2 foscil 0.46, cpsmidinn(inote2), 1, 2, 1, gifnSine
	a1 += a2
	a1 butterhp a1, 130
	kenv linseg 1, p3*0.1, 0.6, p3*0.5, 0.4, p3*0.4, 0
	aout = a1*kenv*iamp*2
	aL, aR pan2 aout, random(0, 1)
	bus_mix("master", aL, aR)
	if (random(0, 1) > 0.77) then
		bus_mix("delay1", aL*0.9, aR*0.9)
	endif
endin


instr play_kick	; 808 style kick
	iamp = bid_getparameter(p4, p5, 2)

	idist = 0.5 ;= (i(gksection) == 1) ? 0.55 : 0.35
	xtratim 0.1
	krelease release
	ktune init 0
	kmul transeg 0.2, p3*0.5, -15, 0.01, p3*0.5, 0, 0
	kbend transeg 0.5, 1.2, -4, 0, 1, 0, 0
	asig gbuzz 0.5, 50*octave(ktune)*semitone(kbend), 20, 1, kmul, gifnCosine
	aenv transeg 1, p3-0.004, -6, 0
	gkpump = k(aenv)
	aatt linseg 0, 0.004, 1
	asig = asig*aenv*aatt
	aenv linseg 1, 0.07, 0
	acps expsega 400, 0.07, 0.001, 1, 0.001
	aimp oscili aenv, acps*octave(ktune*0.25)
	amix = ((asig*0.7)+(aimp*0.35))*2*iamp
	gkpump = min(rms(amix) * 7, 1)
	aout1 pareq amix, 100, 0.01, 0.7
	aout1 distort aout1, idist, gifnSquare
	aout1 pareq aout1, 50, 2, 0.4
	aout1 pareq aout1, 190, 0.7, 0.6
	aout1 pareq aout1, 4900, 2, 0.7
	aout1 pareq aout1, 8900, 2, 0.7
	aout1 *= 2
	bus_mix("master", aout1, aout1)
endin

instr play_kick2
	iamp = bid_getparameter(p4, p5, 2)
	xtratim 0.1
	krelease release
	ktune init 1 
	ifn = gibid_chordgroups[1][1] ; gibid_chordfn
	ifreq = cpsmidinn(tab_i(1, ifn) - 18) * 0.1
	kmul transeg 0.2, p3*0.5, -15, 0.01, p3*0.5, 0, 0
	kbend transeg 0.5, 1.2, -4, 0, 1, 0, 0
	asig gbuzz 0.5, ifreq, 20, 1, kmul, gifnCosine
	aenv transeg 1, p3-0.004, -6, 0
	aatt linseg 0, 0.004, 1
	asig = asig*aenv*aatt
	aenv linseg 1, 0.07, 0
	acps expsega 400, 0.07, 0.001, 1, 0.001
	aimp oscili aenv, acps*octave(ktune*0.25)
	amix = ((asig*0.7)+(aimp*0.35))*2*iamp
	aout1 pareq amix, 100, 0.01, 0.6
	aout1 distort aout1, 0.6, gifnSaw
	aout1 pareq aout1, 100, 0.8, 0.3
	aout1 butterhp aout1, 30
	aout1 *= 3.6
	;aout1 *= 1-gkpump
	bus_mix("master", aout1, aout1)
endin


instr play_shaker
	iamp = bid_getparameter(p4, p5, 2)
	idel1 = random(0.005, 0.02)
	idel2 = random(0.005, 0.02)
	xtratim(max(idel1, idel2))
	p3 = 0.05
	kfreq line 700, p3, 300
	aenv expsega .1, .0005, 1, p3 - .0005, .01
	asqr1 oscil 1, kfreq, gifnSaw, -1
	asqr2 oscil 1, kfreq*1.4471, gifnSaw, -1
	asqr3 oscil 1, kfreq*1.6170, gifnSaw, -1
	asqr4 oscil 1, kfreq*1.9265, gifnSaw, -1
	asqr5 oscil 1, kfreq*2.5028, gifnSine, -1
	asqr6 oscil 1, kfreq*2.6637, gifnSine, -1
	a808 sum asqr1, asqr2, asqr3, asqr4, asqr5, asqr6
	a808 butterhp a808, 2270
	a808 butterhp a808, 2270
	aout = a808 * aenv * iamp * 0.9 * (1-gkpump)
	aL delay aout, idel1
	aR delay aout, idel2
	bus_mix("master", aL, aR)
	bus_mix("delay3", aL*0.25, aR*0.25)
endin


instr play_snare
	icps0 = 211
	iamp = bid_getparameter(p4, p5, 2)
	p3 = random(0.03, 0.1)
	icps1 = 2.0 * icps0
	kcps port icps0, 0.007, icps1
	kcpsx = kcps * 1.5
  
	kfmd port 0.0, 0.01, 0.7
	aenv1 expon 1.0, 0.03, 0.5
	kenv2 port 1.0, 0.008, 0.0
	aenv2 interp kenv2
	aenv3 expon  1.0, 0.025, 0.5
  
	a_ oscili 1.0, kcps
	a1 oscili 1.0, kcps * (1.0 + a_*kfmd)
	a_ oscili 1.0, kcpsx
	a2 oscili 1.0, kcpsx * (1.0 + a_*kfmd)
 
	a3 unirand 2.0
	a3 = a3 - 1.0
	a3 butterbp a3, 3200, 1500
	a3 = a3 * aenv2
  
	a0 = a1 + a2*aenv3 + a3*1.0
	a0 = a0 * aenv1
	a0 butterhp a0, 210
	aout = a0 * iamp * 1.4
	bus_mix("master", aout, aout)

endin


/*
	Convenience opcode for playing current chord on given instrument, passing p4 as note and p5 as amp
	
	chordinstrument Sinstrument

	Sinstrument	the instrument name
	ipos		position in pattern
	idataindex	section specific data index; pointer to ftable
*/
opcode chordinstrument, 0, Sii
	Sinstrument, ipos, idataindex xin
	iamp = bid_getparameter(ipos, idataindex, 2)
	index = 1  ; index 0 is chordgroup length
	while (index < ftlen(gibid_chordfn)) do
		event_i "i", Sinstrument, 0, p3, tab_i(index, gibid_chordfn), iamp
		index += 1
	od
	
endop


/*
	Housey organ, internal use
*/
instr chord1
	inote = p4
	iamp = p5
	aL fmpercfl 0.65, cpsmidinn(inote), 1, 2, 0.1, 10, gifnSine, gifnSquare, gifnSine, gifnSquare, gifnSine
	aR fmpercfl 0.65, cpsmidinn(inote), 1, 1.4, 0.2, 10, gifnSine, gifnSaw, gifnSine, gifnSquare, gifnSine
	aL butterhp aL, 340
	aR butterhp aR, 340
	aL butterlp aL, 4000
	aR butterlp aR, 4000
	kenv linseg 1, p3*0.5, 1, p3*0.4, 1, p3*0.1, 0
	aL *= kenv
	aR *= kenv
	bus_mix("master", aL, aR)
endin


/*
	Play chord1 above, called from BID
*/
instr play_chord1
	chordinstrument "chord1", p4, p5
	turnoff
endin


instr chord2NOTUSED
	inote = p4
	iamp = p5
	ilower = p6
	if (ilower == 1) then
		inote -= 12
	else
		inote -= 12
	endif

	aphs1 phasor cpsmidinn(inote)
	a1 tablei aphs1, gifnSine, 1, 0, 1 
	a1 *= linseg(1, p3*0.9, 0)

	av1L linseg 3, p3, 0
	aL tablei (aphs1+a1)+av1L, gifnSine, 1, 0, 1

	av1R linseg 4, p3, 0
	aR tablei (aphs1+a1)+av1R, gifnSine, 1, 0, 1
	kenv line 1, p3, 0
	aL *= 0.2 * kenv
	aR *= 0.2 * kenv
	aL butterhp aL, 290
	aR butterhp aR, 290

	bus_mix("master", aL, aR)
endin

instr play_crash
	iamp = 1 ;bid_getparameter(p4, p5, 2)
	kfreq line 5000, p3, 2000
	aenv expsega .1, .0005, 1, p3 - .0005, .01
	asqr1 oscil 1, kfreq, gifnSquare, -1
	asqr2 oscil 1, kfreq*1.4471, gifnSine, -1
	asqr3 oscil 1, kfreq*1.6170, gifnSine, -1
	asqr4 oscil 1, kfreq*1.9265, gifnSine, -1
	asqr5 oscil 1, kfreq*2.5028, gifnSine, -1
	asqr6 oscil 1, kfreq*2.6637, gifnSine, -1
	aL butterhp asqr1+asqr3+asqr5, 3270
	aR butterhp asqr2+asqr4+asqr6, 3270
	aL *= aenv * iamp * 0.4
	aR *= aenv * iamp * 0.4
	bus_mix("master", aL, aR)
	bus_mix("delay1", aL, aR)
endin


instr chord2
	inote = p4
	iamp = p5
	ilower = p6
	iamp = 0.55
	if (ilower == 1) then
		iamp = 1
	else
		inote += 12
	endif
	kfmod oscil 10, 6
	kfl linseg 1, p3*0.8, 1, p3*0.2, 0.1
	aL fmpercfl iamp, (cpsmidinn(inote)+kfmod)*kfl*0.5, 1, 2, 0.6, 10, gifnSine, gifnSquare, gifnSine, gifnSquare, gifnSine
	aR fmpercfl iamp, (cpsmidinn(inote)+kfmod)*kfl*0.5, 1, 1.4, 0.9, 10, gifnSine, gifnSaw, gifnSine, gifnSquare, gifnSine
	aL butterhp aL, 540
	aR butterhp aR, 540
	kenv line 0, p3, 1
	aL *= kenv
	aR *= kenv
	bus_mix("master", aL, aR)
endin


/*
	Play chord2 above, called from BID
*/
instr play_chord2
	iamp = bid_getparameter(p4, p5, 2)
	ilower = bid_getparameter(p4, p5, 4)
	index = 1  ; index 0 is chordgroup length
	while (index < ftlen(gibid_chordfn)) do
		event_i "i", "chord2", 0, p3, tab_i(index, gibid_chordfn), iamp, ilower
		index += 1
	od
	turnoff
endin


instr chord3
	inote = p4 - 12
	iamp = p5
	ifreq = cpsmidinn(inote)
	kfreq linseg 10, p3*0.4, ifreq, p3*0.6, ifreq
	aL fmb3 0.65, kfreq, 1, random(1.2, 2.2), random(0.1, 0.3), random(5, 15), gifnSine, gifnSquare, gifnSine, gifnSquare, gifnSine
	aR fmb3 0.65, kfreq, 1, random(1.2, 2.2), random(0.1, 0.3), random(5, 15), gifnSine, gifnSaw, gifnSine, gifnSquare, gifnSine
	aL butterhp aL, 340
	aR butterhp aR, 340

	kenv linseg 1, p3*0.95, 1, p3*0.05, 0
	aL *= kenv
	aR *= kenv
	bus_mix("master", aL, aR)
endin

/*
	Play chord3 above, called from BID
*/
instr play_chord3
	chordinstrument "chord3", p4, p5
	turnoff
endin


;glitch sampler vars
giglitchsamples = 44100
giglitchbufferL ftgen 0, 0, giglitchsamples, 7, 0
giglitchbufferR ftgen 0, 0, giglitchsamples, 7, 0
instr play_glitchread
	iamp = bid_getparameter(p4, p5, 2)
	ifreq = cpsmidinn(tab_i(random(1, ftlen(gibid_chordfn) - 1), gibid_chordfn))
	ilen = ((1/(ifreq))*sr)*pow(2, round(random(0, 4)))
	istart random 0, giglitchsamples-ilen
	awindex phasor giglitchsamples / ilen
	aL table awindex*giglitchsamples, giglitchbufferL
	aR table awindex*giglitchsamples, giglitchbufferR
	aL butterhp aL, 350
	aR butterhp aL, 350
	aL *= 0.4 * iamp
	aR *= 0.4 * iamp
	if (random(0, 1) > 0.7) then
		if (random(0, 1) > 0.5) then
			bus_mix("delay1", aL, aR)
		else
			bus_mix("delay2", aL, aR)
		endif
	endif
	bus_mix("master", aL, aR)
endin


#end