aboutsummaryrefslogtreecommitdiff
path: root/include/instruments_idiophone.inc
blob: 19d9d7891dae0a46780896d0fdf458e1e327f196 (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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
#ifndef INC_MUSICBOX_INSTR
#define INC_MUSICBOX_INSTR ##
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

	Partial Emergence
		by Richard Knight 2022

	Installation submission for the International Csound Conference 2022

	Idiophone instruments

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "sonics/soundxdb.udo"
#include "sonics/array_tools.udo"
#include "sonics/sequencing_melodic.udo"
#include "sonics/sequencing_melodic_portamento.udo"
#include "sonics/bussing.udo"
#include "sonics/frequency_tools.udo"
#include "sonics/instrument_portchord.udo"
#include "sonics/instrument_gchord1.udo"
#include "sonics/wavetables.udo"


; sound collections
gicol_musicbox sounddb_getcollectionid "MusicBox"
gicol_kalimba sounddb_getcollectionid "Kalimba"
gicol_idiophone = gicol_musicbox
gicol_idiophone_other = gicol_kalimba

opcode idiophone_change, 0, 0
	if (random(0, 1) >= 0.5) then
		gicol_idiophone = gicol_musicbox
		gicol_idiophone_other = gicol_kalimba
	else
		gicol_idiophone = gicol_kalimba
		gicol_idiophone_other = gicol_musicbox
	endif
endop

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

	Sample playback initiation instruments

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


instr note_idiophone_randtime
	ifileid, ipitchratio sounddb_mel_nearestnote gicol_idiophone, mel_randomnote()
	ifn = gisounddb[ifileid][0]
	idur = gisounddb[ifileid][2]
	;p3 = random(4, 8)

	ipitch = round(random(1, 2)) * ipitchratio
	ktime init random(0, idur)
	aL, aR mincer a(port(ktime, 0.001, random(0, idur))), 1, ipitch, ifn, 0, 256 ;64

	if (random:k(0, 1) > 0.1) then
		ktime = random:k(0, idur)
	endif


	kamp linseg 1, p3*0.8, 1, p3*0.2, 0
	aL *= kamp
	aR *= kamp

	if (random(0, 1) > 0.8) then
		bus_mix("delay1", aL*random(0, 0.3), aR*random(0, 0.3))
	endif

	bus_mix("reverb1", aL*random(0.2, 0.8), aR*random(0.2, 0.8))

	if (random(0, 1) > 0.5) then
		bus_mix("pvsamp1", aL*0.6, aR*0.6)
	endif

	bus_mix("master", aL, aR)
endin


/*
	Idiophone chord
	
	p4		one note (0 = play one note, 1 = play chord)
*/
instr phrase_idiophone1
	ionenote = p4

	if (ionenote == 1) then
		knote init mel_randomnote() + (round(random(-2, 4)) * 12)
	endif

	if (random(0, 1) > 0.5) then
		ifreqstart = random(10, 30)
		ifreqend = random(2, 15)
	else
		ifreqstart = random(2, 10)
		ifreqend = random(10, 30)
	endif
	kfreq linseg ifreqstart, p3, ifreqend
	kamp linseg 0, p3*0.1, 1, p3*0.8, 1, p3*0.1, 0

	ktrig metro kfreq
	if (ktrig == 1) then
		if (ionenote != 1) then
			knote = mel_randomnote:k() + (round:k(random:k(-2, 4)) * 12)
		endif
		schedulek("note_idiophone1", random:k(0, 0.1), 0.1, min:k(knote, 127), kamp*2)
	endif
endin


/*
	Idiophone chord using portamento note frequencies
	
	p4		one note (0 = play one note, 1 = play chord)
*/
instr phrase_idiophone2
	ionenote = p4
	ilen = mel_length() * random(1, 10)
	p3 = ilen

	if (ionenote == 1) then
		itlen = table:i(0, gimel_current_notes)
		index = round(random(1, itlen-1))
		kindex init index
		knote init table(index, gimel_current_notes)
		knoteaugment init (round(random(-2, 4)) * 12)
	endif

	kfreq linseg random(20, 60), ilen, random(2, 10)

	kamp linseg 1, p3, 0
	if (random(0, 1) > 0.5) then
		kamp = 1-kamp
	endif

	ktrig metro kfreq
	if (ktrig == 1) then
		if (ionenote != 1) then
			klen = table:k(0, gimel_current_notes)
			kindex = round:k(random:k(1, klen-1))
			knote = table:k(kindex, gimel_current_notes)
			knoteaugment = (round:k(random:k(-2, 4)) * 12)
		endif

		kportfreq = table:k(kindex-1, gimel_freqs)
		kportamp = table:k(kindex-1, gimel_amps)

		if (kportfreq != cpsmidinn:k(knote)) then
			kscale = cpsmidinn:k(knote) / kportfreq
		else
			kscale = 1
		endif
		schedulek("note_idiophone2", random:k(0, 0.1), 1, min:k(knote+knoteaugment, 127), kamp*kportamp, kscale)
	endif
endin


/*
	Stretch idiophone chord

	p4		mode (0 = flipflop loop, 1 = linear loop)
*/
instr phrase_idiophone_stretch1
	imode = p4
	ilen = p3
	index = 1
	inoteaugment = min((round(random(-1, 4)) * 12), 127)
	while (index < table:i(0, gimel_current_notes)) do
		inote = table(index, gimel_current_notes)
		schedule("note_idiophonestretch1", 0, ilen, inote + inoteaugment, imode)
		index += 1
	od
	turnoff
endin


/*
	Stretch idiophone box chord

	p4		mode (0 = flipflop loop, 1 = linear loop)
*/
instr phrase_idiophone_stretch2
	imode = p4
	ilen = p3
	index = 1
	while (index < table:i(0, gimel_current_notes)) do
		inote = table(index, gimel_current_notes)
		schedule("note_idiophonestretch2", 0, ilen, inote, imode, 0, 1) ; no low pass, out to note_idiophonestretch2 bus, mincer read
		schedule("note_idiophonestretch2", 0, ilen, inote-12, imode, 1, 0) ; low pass, master out, sndwarp read
		index += 1
	od
	turnoff
endin


instr phrase_idiophone_stretch3
	ksendDelay1 init 0
	ksendReverb1 init 0.3
	ksendPV1 init 0
	kampx4 init 0
	kamp linsegr 0, 0.5, 1, p3-0.5, 1, 1, 0

	; cpu saving: first arg 0 = sndwarp, 1 = mincer
	aL1, aR1 portchord_sound gicol_idiophone, 0, 0.5, 512
	aL2, aR2 portchord_sound gicol_idiophone, 0, 1, 1024 
	aL3, aR3 portchord_sound gicol_idiophone, 0, 2, 512

	aL = (aL3 * portk(kampx4, 2) + (aL1 + aL2)) * kamp
	aR = (aR3 * portk(kampx4, 2) + (aR1 + aR2)) * kamp

	kchangemetro = metro(0.2)
	if (kchangemetro == 1) then
		if (random:k(0, 1) > 0.6) then
			ksendDelay1 = random:k(0, 0.8)
		endif
	
		if (random:k(0, 1) > 0.6) then
			ksendReverb1 = random:k(0.3, 0.8)
		endif

		if (random:k(0, 1) > 0.6) then
			ksendPV1 = random:k(0, 0.8)
		endif

		if (random:k(0, 1) > 0.6) then
			kampx4 = random:k(0, 1.5)
		endif
	endif

	ksendDelay1p = port(ksendDelay1, 1)
	ksendReverb1p = port(ksendReverb1, 1)
	ksendPV1p = port(ksendPV1, 1)

	bus_mix("delay1", aL*ksendDelay1p, aR*ksendDelay1p)
	bus_mix("reverb1", aL*ksendReverb1p, aR*ksendReverb1p)
	bus_mix("pvsamp1", aL*ksendPV1p, aR*ksendPV1p)
	bus_mix("master", aL, aR)
endin


instr phrase_idiophone_stretch4
	iamp = 0.5
	klpf1 init 22050
	klpf2 init 22050

	ichangechance = random(0.1, 0.6)
	icompressmode = 2 ; 0 = none ; 1 = harshwall ; 2 = normal
	aL1, aR1 fnmi_gchord1 gicol_idiophone, 1, 3, icompressmode, ichangechance, 2, 0 ; 1 is mincer
	aL2, aR2 fnmi_gchord1 gicol_idiophone, 1, 3, icompressmode, ichangechance, 1, 0 

	klpf1p port klpf1, 3
	klpf2p port klpf2, 3
	aL1 butterlp aL1, klpf1p
	aR1 butterlp aR1, klpf1p
	aL2 butterlp aL2, klpf2p
	aR2 butterlp aR2, klpf2p
	kchangemetro = metro(0.2)
	if (kchangemetro == 1) then
		if (random:k(0, 1) > 0.6) then
			klpf1 = random:k(400, 22050)
		endif
	
		if (random:k(0, 1) > 0.6) then
			klpf2 = random:k(400, 22050)
		endif
	endif

	aL = (aL1 + aL2) * iamp
	aR = (aR1 + aR2) * iamp


	bus_mix("master", aL, aR)
	bus_mix("reverb1", aL*0.4, aR*0.4)
	bus_mix("pvsamp1", aL*0.1, aR*0.1)
endin


/*
	Play a short glissando, possibly ascending or descending
*/
instr phrase_idiophone_gliss1
	iamp = p4
	ilen = table:i(0, gimel_current_notes)
	itime = 0
	imultreal = 1
	imaxmult = 6
	iascending = round(random(0, 1))
	if (iascending == 1) then
		iincrement = 1
		istartindex = 1
		imult = 1
	else
		iincrement = -1
		istartindex = ilen
		imult = imaxmult 
	endif
		
	while (imultreal <= imaxmult) do
		indexreal = 1
		index = istartindex
		while (indexreal < ilen) do
			inote = (table:i(index, gimel_current_notes)-12)+(12*imult)
			if (inote >= 127 || inote <= 0) then
				goto complete
			endif
			schedule("note_idiophone1", itime, 0.1, inote, iamp, gicol_idiophone_other)
			itime += random(0.05, 0.1)
			indexreal += 1
			index += iincrement
		od
		imult += iincrement
		imultreal += 1
	od
complete:
	turnoff
endin


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

	Transition instruments

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


instr transition_idiophone_randtime
	iriseratio = p4
	kamp expseg 0.00001, p3*iriseratio, 1, p3*(1-iriseratio), 0.00001
	ifileid, ipitchratio sounddb_mel_nearestnote gicol_idiophone_other, mel_randomnote()
	ifn = gisounddb[ifileid][0]
	idur = gisounddb[ifileid][2]

	ipitch = round(random(1, 2)) * ipitchratio
	ktime init random(0, idur)
	aL, aR mincer a(port(ktime, 0.001, random(0, idur))), 1, ipitch, ifn, 0, 256 ;64

	if (random:k(0, 1) > 0.1) then
		ktime = random:k(0, idur)
	endif

	aL *= kamp * 3
	aR *= kamp * 3

	if (random(0, 1) > 0.8) then
		bus_mix("delay1", aL*random(0, 0.3), aR*random(0, 0.3))
	endif

	bus_mix("reverb1", aL*random(0.4, 0.8), aR*random(0.4, 0.8))

	if (random(0, 1) > 0.5) then
		bus_mix("pvsamp1", aL*0.6, aR*0.6)
	endif

	bus_mix("master", aL, aR)
endin


instr transition_idiophone_gliss1
	iriseratio = p4
	kamp expseg 0.00001, p3*iriseratio, 1, p3*(1-iriseratio), 0.00001
	kmetro metro 20
	kmult init 0
	kincrement init 1
	kindex init 1

	if (kmetro == 1) then
		knote = min:k((table:k(kindex, gimel_current_notes))+(12*kmult), 127)
		schedulek("note_idiophone1", random:k(0, 0.1), 0.1, knote, kamp*3.5, gicol_idiophone_other)
	
		kmaxnotes = table:k(0, gimel_current_notes)
		if ((kindex < kmaxnotes - 1 && kincrement == 1) || (kindex > 1 && kincrement == -1)) then
			kindex += kincrement
		else
			kindex = (kincrement == 1) ? 1 : kmaxnotes - 1
			kmult += kincrement
			if (kmult >= 4) then
				kmult = 4
				kincrement = -1
			elseif (kmult < 0) then
				kmult = 0
				kincrement = 1
			endif
		endif
	
	endif
endin


instr transition_idiophone_stretch1
	iriseratio = p4
	kamp expseg 0.00001, p3*iriseratio, 1, p3*(1-iriseratio), 0.00001

	inotestart = mel_randomnote()
	inoteend = mel_randomnote()
	
	if (random(0, 1) >= 0.5) then
		inotestart += 12
	endif

	if (random(0, 1) >= 0.5) then
		inoteend += 12
	endif

	
	ifileid, ipitchratio sounddb_mel_nearestnote gicol_idiophone_other, inotestart
	ifn = gisounddb[ifileid][0]
	idur = gisounddb[ifileid][2]

	istart = random(0.01, 0.1)
	iend = random(istart+0.05, 0.3) 
	atime = abs(oscil(iend-istart, random(0.001, 0.1), gifnSine, random(0, 1)))
	atime *= idur
	apitchratio line ipitchratio, p3, (ipitchratio * (cpsmidinn(inoteend) / cpsmidinn(inotestart)))

	isndwarpadjust = (ftsr(ifn) / sr) ; adjustment for sndwarp required
	aL, aR sndwarpst kamp, atime, apitchratio*isndwarpadjust, ifn, istart, 4096, 128, 2, gifnHalfSine, 1
	
	bus_mix("reverb1", aL*random(0, 0.8), aR*random(0, 0.8))
	bus_mix("pvsamp1", aL*random(0, 0.2), aR*random(0, 0.2))
	bus_mix("master", aL*1.7, aR*1.7)
endin


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

	Sample playback note instruments

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


/*
	Play idiophone note with stochastic transforms and sends

	p4		midi note number
	p5		amplitude (0 to 1)
	p6		optional collection, defaults to gicol_idiophone
*/
instr note_idiophone1
	inote = p4
	iamp = p5 * 0.2
	icollection = (p6 == 0) ? gicol_idiophone : p6
	iamp *= random(0.6, 1)
	ifileid, ipitchratio sounddb_mel_nearestnote icollection, inote

	if (active:i(p1) < 50 && (abs(ipitchratio) > 1.8 || random(0, 1) > 0.8)) then
		iloscilratio = 1
		idopvs = 1
	else
		iloscilratio = ipitchratio
		idopvs = 0
	endif

	ifn = gisounddb[ifileid][0]
	idur = gisounddb[ifileid][2]
	p3 = idur / iloscilratio
	kamp linseg iamp, p3*0.6, iamp, p3*0.4, 0
	;ktime line random(0, 0.2), p3, p3
	;aL, aR sndwarpst kamp, ktime, iloscilratio, isound[0], 0, 441*random(1, 100), 44*random(1, 10), 4, gifnHalfSine, 1
	aL, aR loscil kamp, iloscilratio, ifn, 1

	if (idopvs == 1) then
		if (random(0, 1) > 0.75) then
			ipitchratio *= pow(2, int(random(1, 4)))
		endif
		ir = 512
		fL1 pvsanal aL, ir, ir/2, ir, 1
		fR1 pvsanal aR, ir, ir/2, ir, 1
		fL2 pvscale fL1, ipitchratio
		fR2 pvscale fR1, ipitchratio
		aL pvsynth fL2
		aR pvsynth fR2
	endif

	ipan = random(0, 1)
	aL *= ipan
	aR *= (1-ipan)

	if (random(0, 1) > 0.6) then
		aL pareq aL, random(100, 4000), random(0.3, 1.1), 0.7
		aR pareq aR, random(100, 4000), random(0.3, 1.1), 0.7
	endif

	if (random(0, 1) > 0.9) then
		bus_mix("delay1", aL*random(0.1, 0.4), aR*random(0.1, 0.4))
	endif

	if (random(0, 1) > 0.8) then
		;krenv linseg 0, p3*0.1, 1, p3*0.8, 1, p3*0.1, 0
		bus_mix("reverb1", aL*random(0.1, 0.7), aR*random(0.1, 0.7))
	endif

	if (random(0, 1) > 0.5) then
		bus_mix("pvsamp1", aL*random(0.5, 0.8), aR*random(0.5, 0.8))
	endif

	bus_mix("master", aL, aR)
	
endin




/*
	Play idiophone note with stochastic transforms and sends

	p4		midi note number
	p5		amplitude (0 to 1)
	p6		pitchscale: amount to scale pitch by (for portamento augmentation)
*/
instr note_idiophone2
	inote = p4
	iamp = p5 * 0.2
	ipitchscale = p6

	iamp *= random(0.6, 1)
	kamp linseg iamp, p3*0.6, iamp, p3*0.4, 0
	ifileid, ipitchratio sounddb_mel_nearestnote gicol_idiophone, inote

	kpitchratio init ipitchratio * ipitchscale

	kpitchenv = abs:k(oscil:k(random(0.001, 0.01), random(0.1, 4), gifnSine, random(0, 1))) + 1
	kpitchratio += kpitchenv

	if (kpitchratio > 1.8 || random(0, 1) > 0.8) then
		kloscilratio init 1
		idopvs = 1
	else
		kloscilratio = kpitchratio
		idopvs = 0
	endif

	ifn = gisounddb[ifileid][0]
	idur = gisounddb[ifileid][2]

	p3 = idur
	;ktime line random(0, 0.2), p3, p3
	;aL, aR sndwarpst kamp, ktime, iloscilratio, isound[0], 0, 441*random(1, 100), 44*random(1, 10), 4, gifnHalfSine, 1
	aL, aR loscil kamp, kloscilratio, ifn, 1

	if (idopvs == 1) then
		if (random(0, 1) > 0.5) then
			kpitchratio *= pow(2, int(random(1, 4)))
		endif
		ir = 512
		fL1 pvsanal aL, ir, ir/4, ir, 1
		fR1 pvsanal aR, ir, ir/4, ir, 1
		fL2 pvscale fL1, kpitchratio
		fR2 pvscale fR1, kpitchratio
		aL pvsynth fL2
		aR pvsynth fR2
	endif

	ipan random 0, 1
	aL *= ipan
	aR *= (1-ipan)

	if (random(0, 1) > 0.8) then
		kdenv linseg 0, p3*0.1, 1, p3*0.8, 1, p3*0.1, 0
		bus_mix("delay1", aL*kdenv, aR*kdenv)
	endif

	if (random(0, 1) > 0.8) then
		krenv linseg 0, p3*0.1, 1, p3*0.8, 1, p3*0.1, 0
		bus_mix("reverb1", aL*krenv, aR*krenv)
	endif

	if (random(0, 1) > 0.5) then
		bus_mix("pvsamp1", aL, aR)
	endif
	
	bus_mix("master", aL, aR)
	
endin



/*
	Play held/stretched idiophone note with stochastic transforms and sends

	p4		midi note number
	p5		mode (0 = forwards and reverse, 1 = linear forwards)
*/
instr note_idiophonestretch1
	inote = p4
	imode = p5
	iamp = 0.6
	kamp linseg 0, p3*0.2, iamp, p3*0.6, iamp, p3*0.2, 0
	ifileid, ipitchratio sounddb_mel_nearestnote gicol_idiophone, inote
	ifn = gisounddb[ifileid][0]
	idur = gisounddb[ifileid][2]
	ipitchratio *= (ftsr(ifn) / sr) ; adjustment for sndwarp required

	if (imode == 0) then
		istart = random(0, 0.3)
		iend = random(istart+0.1, 0.5)
		atime = abs(oscil(iend-istart, random(0.001, 0.1), gifnSine, random(0, 1))) 
	else
		istart = 0
		iend = random(0.1, 0.99)
		atime = (phasor(random(10, 40)) * (iend-istart))
	endif
	

	if (random(0, 1) > 0.5) then
		alfo = oscil(random(0.0001, 0.0009), random(4, 10)) + 1
		apitchratio = ipitchratio * alfo
	else
		apitchratio init ipitchratio
	endif
	
	atime *= idur

	aL, aR sndwarpst kamp, atime, apitchratio, ifn, istart, 441*random(1, 100), 44*random(1, 10), 8, gifnHalfSine, 1

	aL butterhp aL, 150
	aR butterhp aR, 150

	if (random(0, 1) > 0.5) then
		atemp = aL
		aL = aR
		aR = atemp	
	endif

	if (random(0, 1) > 0.2) then
		krenv linseg 0, p3*0.1, 1, p3*0.8, 1, p3*0.1, 0
		bus_mix("reverb1", aL*krenv, aR*krenv)
	endif

	if (random(0, 1) > 0.5) then
		bus_mix("pvsamp1", aL, aR)
	endif
	
	bus_mix("master", aL, aR)
endin




instr note_idiophonestretch2
	inote = p4
	imode = p5
	ilpmode = p6
	ireadmode = p7 ; 0 = sndwarp, 1 = mincer
	iamp = 0.4
	kamp linseg 0, p3*0.2, iamp, p3*0.6, iamp, p3*0.2, 0
	ifileid, ipitchratio sounddb_mel_nearestnote gicol_idiophone, inote
	ifn = gisounddb[ifileid][0]
	idur = gisounddb[ifileid][2]

	if (imode == 0) then
		istart = random(0.05, 0.2)
		iend = random(istart+0.1, 0.8) 
		atime = abs(oscil(iend-istart, random(0.001, 0.1), gifnSine, random(0, 1)))
	else
		istart = 0
		iend = random(0.1, 0.99)
		atime = (phasor(random(10, 40)) * (iend-istart))
	endif
	
	if (random(0, 1) > 0.4) then
		alfo = oscil(random(0.0001, 0.001), random(4, 10)) + 1
		apitchratio = ipitchratio * alfo
	else
		apitchratio init 1
	endif

	atime *= idur
	
	if (ireadmode == 0) then
		isndwarpadjust = (ftsr(ifn) / sr) ; adjustment for sndwarp required
		aL, aR sndwarpst kamp, atime, apitchratio*isndwarpadjust, ifn, istart, 4096, 128, 2, gifnHalfSine, 1
	else
		aL, aR mincer atime+istart, kamp, k(apitchratio), ifn, 0, 512
	endif
	
	ipan = random(0, 1)
	aL *= (1-ipan)
	aR *= (ipan)

	aLh butterhp aL, 150
	aRh butterhp aR, 150


	if (random(0, 1) > 0.8) then
		krenv linseg 0, p3*0.1, 1, p3*0.8, 1, p3*0.1, 0
		bus_mix("reverb1", aLh*krenv, aRh*krenv)
	endif

	if (random(0, 1) > 0.7) then
		bus_mix("pvsamp1", aLh, aRh)
	endif
	
	if (ilpmode == 0) then
		bus_mix("note_idiophonestretch2", aLh, aRh)
	elseif (ilpmode == 1) then
		aL butterlp aL, 500
		aR butterlp aR, 500
		bus_mix("master", aL*0.8, aR*0.8)
	endif
endin




#end