/
clm-ins.scm
2731 lines (2429 loc) · 119 KB
/
clm-ins.scm
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
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; CLM instruments translated to Snd/Scheme
(provide 'snd-clm-ins.scm)
(if (provided? 'snd)
(require snd-ws.scm)
(require sndlib-ws.scm))
(require snd-env.scm snd-dsp.scm snd-fullmix.scm snd-expandn.scm)
;;; -------- pluck
;;;
;;; The Karplus-Strong algorithm as extended by David Jaffe and Julius Smith -- see
;;; Jaffe and Smith, "Extensions of the Karplus-Strong Plucked-String Algorithm"
;;; CMJ vol 7 no 2 Summer 1983, reprinted in "The Music Machine".
;;; translated from CLM's pluck.ins
(definstrument (pluck start dur freq amp (weighting .5) (lossfact .9))
"(pluck start dur freq amp weighting lossfact) implements the Jaffe-Smith plucked string physical model.
'weighting' is the ratio of the once-delayed to the twice-delayed samples. It defaults to .5=shortest decay.
Anything other than .5 = longer decay. Must be between 0 and less than 1.0.
'lossfact' can be used to shorten decays. Most useful values are between .8 and 1.0. (with-sound () (pluck 0 1 330 .3 .7 .995))"
(define tuneIt
(let ((getOptimumC (lambda (S o p)
(let* ((pa (* (/ 1.0 o)
(atan (* S (sin o))
(- (+ 1.0 (* S (cos o))) S))))
(tmpInt (floor (- p pa)))
(pc (- p pa tmpInt)))
(if (< pc .1)
(do ()
((>= pc .1))
(set! tmpInt (- tmpInt 1))
(set! pc (+ pc 1.0))))
(list tmpInt (/ (- (sin o) (sin (* o pc)))
(sin (+ o (* o pc)))))))))
(lambda (f s1)
(let ((p (/ *clm-srate* f)) ;period as float
(s (if (= s1 0.0) 0.5 s1))
(o (hz->radians f)))
(let ((vals (getOptimumC s o p))
(vals1 (getOptimumC (- 1.0 s) o p)))
(if (and (not (= s 1/2))
(< (abs (cadr vals)) (abs (cadr vals1))))
(list (- 1.0 s) (cadr vals) (car vals))
(list s (cadr vals1) (car vals1))))))))
(let* ((vals (tuneIt freq weighting))
(wt0 (car vals))
(c (cadr vals))
(dlen (caddr vals))
(beg (seconds->samples start))
(end (seconds->samples (+ start dur)))
(lf (if (= lossfact 0.0) 1.0 (min 1.0 lossfact)))
(wt (if (= wt0 0.0) 0.5 (min 1.0 wt0)))
(tab (make-float-vector dlen))
;; get initial waveform in "tab" -- here we can introduce 0's to simulate different pick
;; positions, and so on -- see the CMJ article for numerous extensions. The normal case
;; is to load it with white noise (between -1 and 1).
(allp (make-one-zero (* lf (- 1.0 wt)) (* lf wt)))
(feedb (make-one-zero c 1.0)) ;or (feedb (make-one-zero 1.0 c))
(c1 (- 1.0 c)))
(do ((i 0 (+ i 1)))
((= i dlen))
(float-vector-set! tab i (mus-random 1.0)))
(do ((i beg (+ i 1))
(ctr 0 (modulo (+ ctr 1) dlen)))
((= i end))
(outa i (* amp (float-vector-set! tab ctr (* c1 (one-zero feedb (one-zero allp (float-vector-ref tab ctr))))))))))
#|
(let ((val (float-vector-ref tab ctr))) ;current output value
(float-vector-set! tab ctr (* c1 (one-zero feedb (one-zero allp val))))
(outa i (* amp val)))))))))
|#
;;; -------- mlbvoi
;;;
;;; translation from MUS10 of Marc LeBrun's waveshaping voice instrument (using FM here)
;;; this version translated (and simplified slightly) from CLM's mlbvoi.ins
(definstrument (vox beg dur freq amp ampfun freqfun freqscl phonemes formant-amps formant-indices (vibscl .1) (deg 0) (pcrev 0))
(define vox-fun
(let ((formants ; formant center frequencies for a male speaker
'((I 390 1990 2550) (E 530 1840 2480) (AE 660 1720 2410)
(UH 520 1190 2390) (A 730 1090 2440) (OW 570 840 2410)
(U 440 1020 2240) (OO 300 870 2240) (ER 490 1350 1690)
(W 300 610 2200) (LL 380 880 2575) (R 420 1300 1600)
(Y 300 2200 3065) (EE 260 3500 3800) (LH 280 1450 1600)
(L 300 1300 3000) (I2 350 2300 3340) (B 200 800 1750)
(D 300 1700 2600) (G 250 1350 2000) (M 280 900 2200)
(N 280 1700 2600) (NG 280 2300 2750) (P 300 800 1750)
(T 200 1700 2600) (K 350 1350 2000) (F 175 900 4400)
(TH 200 1400 2200) (S 200 1300 2500) (SH 200 1800 2000)
(V 175 1100 2400) (THE 200 1600 2200)(Z 200 1300 2500)
(ZH 175 1800 2000) (ZZ 900 2400 3800) (VV 565 1045 2400)))
(find-phoneme (lambda (phoneme forms)
(do ((forms forms (cdr forms)))
((eq? phoneme (caar forms))
(cdar forms))))))
(lambda (phons which)
(let ((f1 ())
(len (length phons)))
(do ((i 0 (+ i 2)))
((>= i len))
(set! f1 (cons ((find-phoneme (phons (+ i 1)) formants) which) (cons (phons i) f1))))
(reverse f1)))))
(let ((start (seconds->samples beg))
(end (seconds->samples (+ beg dur)))
(car-os (make-oscil 0))
(fs (length formant-amps))
(per-vib (make-triangle-wave :frequency 6 :amplitude (hz->radians (* freq vibscl))))
(ran-vib (make-rand-interp :frequency 20 :amplitude (hz->radians (* freq .5 vibscl))))
(freqf (make-env freqfun :duration dur :scaler (hz->radians (* freqscl freq)) :offset (hz->radians freq))))
(if (and (= fs 3)
(= (channels *output*) 1))
;; optimize the common case
(let ((a0 (make-env ampfun :scaler (* amp (formant-amps 0)) :duration dur))
(a1 (make-env ampfun :scaler (* amp (formant-amps 1)) :duration dur))
(a2 (make-env ampfun :scaler (* amp (formant-amps 2)) :duration dur))
(o0 (make-oscil 0.0))
(o1 (make-oscil 0.0))
(o2 (make-oscil 0.0))
(e0 (make-oscil 0.0))
(e1 (make-oscil 0.0))
(e2 (make-oscil 0.0))
(ind0 (formant-indices 0))
(ind1 (formant-indices 1))
(ind2 (formant-indices 2))
(f0 (make-env (vox-fun phonemes 0) :scaler (hz->radians 1.0) :duration dur))
(f1 (make-env (vox-fun phonemes 1) :scaler (hz->radians 1.0) :duration dur))
(f2 (make-env (vox-fun phonemes 2) :scaler (hz->radians 1.0) :duration dur)))
(do ((i start (+ i 1)))
((= i end))
(let* ((frq (+ (env freqf) (triangle-wave per-vib) (rand-interp ran-vib)))
(carg (oscil car-os frq))
(frm0 (/ (env f0) frq))
(frm1 (/ (env f1) frq))
(frm2 (/ (env f2) frq)))
(outa i (+
(* (env a0)
(+ (* (even-weight frm0) (oscil e0 (+ (* ind0 carg) (even-multiple frm0 frq))))
(* (odd-weight frm0) (oscil o0 (+ (* ind0 carg) (odd-multiple frm0 frq))))))
(* (env a1)
(+ (* (even-weight frm1) (oscil e1 (+ (* ind1 carg) (even-multiple frm1 frq))))
(* (odd-weight frm1) (oscil o1 (+ (* ind1 carg) (odd-multiple frm1 frq))))))
(* (env a2)
(+ (* (even-weight frm2) (oscil e2 (+ (* ind2 carg) (even-multiple frm2 frq))))
(* (odd-weight frm2) (oscil o2 (+ (* ind2 carg) (odd-multiple frm2 frq)))))))))))
(let ((evens (make-vector fs))
(odds (make-vector fs))
(ampfs (make-vector fs))
(indices (make-float-vector fs))
(frmfs (make-vector fs))
(carrier 0.0)
(frm-int 0)
(rfrq 0.0)
(frm0 0.0)
(frac 0.0)
(fracf 0.0)
(loc (make-locsig deg 1.0 pcrev)))
(do ((i 0 (+ i 1)))
((= i fs))
(set! (evens i) (make-oscil 0))
(set! (odds i) (make-oscil 0))
(set! (ampfs i) (make-env ampfun :scaler (* amp (formant-amps i)) :duration dur))
(set! (indices i) (formant-indices i))
(set! (frmfs i) (make-env (vox-fun phonemes i) :scaler (hz->radians 1.0) :duration dur)))
(if (= fs 3)
(let ((frmfs0 (frmfs 0)) (frmfs1 (frmfs 1)) (frmfs2 (frmfs 2))
(index0 (indices 0)) (index1 (indices 1)) (index2 (indices 2))
(ampfs0 (ampfs 0)) (ampfs1 (ampfs 1)) (ampfs2 (ampfs 2))
(evens0 (evens 0)) (evens1 (evens 1)) (evens2 (evens 2))
(odds0 (odds 0)) (odds1 (odds 1)) (odds2 (odds 2)))
(do ((i start (+ i 1)))
((= i end))
(set! rfrq (+ (env freqf) (triangle-wave per-vib) (rand-interp ran-vib)))
(set! carrier (oscil car-os rfrq))
(set! frm0 (/ (env frmfs0) rfrq))
(set! frm-int (floor frm0))
(set! frac (- frm0 frm-int))
(set! fracf (+ (* index0 carrier) (* frm-int rfrq)))
(locsig loc i
(* (env ampfs0)
(if (even? frm-int)
(+ (* (- 1.0 frac) (oscil evens0 fracf)) (* frac (oscil odds0 (+ fracf rfrq))))
(+ (* frac (oscil evens0 (+ fracf rfrq))) (* (- 1.0 frac) (oscil odds0 fracf))))))
(set! frm0 (/ (env frmfs1) rfrq))
(set! frm-int (floor frm0))
(set! frac (- frm0 frm-int))
(set! fracf (+ (* index1 carrier) (* frm-int rfrq)))
(locsig loc i
(* (env ampfs1)
(if (even? frm-int)
(+ (* (- 1.0 frac) (oscil evens1 fracf)) (* frac (oscil odds1 (+ fracf rfrq))))
(+ (* frac (oscil evens1 (+ fracf rfrq))) (* (- 1.0 frac) (oscil odds1 fracf))))))
(set! frm0 (/ (env frmfs2) rfrq))
(set! frm-int (floor frm0))
(set! frac (- frm0 frm-int))
(set! fracf (+ (* index2 carrier) (* frm-int rfrq)))
(locsig loc i
(* (env ampfs2)
(if (even? frm-int)
(+ (* (- 1.0 frac) (oscil evens2 fracf)) (* frac (oscil odds2 (+ fracf rfrq))))
(+ (* frac (oscil evens2 (+ fracf rfrq))) (* (- 1.0 frac) (oscil odds2 fracf))))))))
(do ((i start (+ i 1)))
((= i end))
(set! rfrq (+ (env freqf) (triangle-wave per-vib) (rand-interp ran-vib)))
(set! carrier (oscil car-os rfrq)) ; better name: modulator or perhaps perceived-carrier?
(do ((k 0 (+ k 1)))
((= k fs))
(set! frm0 (/ (env (vector-ref frmfs k)) rfrq))
(set! frm-int (floor frm0))
(set! frac (- frm0 frm-int))
(set! fracf (+ (* (float-vector-ref indices k) carrier) (* frm-int rfrq)))
(locsig loc i
(* (env (vector-ref ampfs k))
(if (even? frm-int)
(+ (* (- 1.0 frac) (oscil (vector-ref evens k) fracf))
(* frac (oscil (vector-ref odds k) (+ fracf rfrq))))
(+ (* frac (oscil (vector-ref evens k) (+ fracf rfrq)))
(* (- 1.0 frac) (oscil (vector-ref odds k) fracf)))))))))))))
;;; (with-sound (:statistics #t) (vox 0 2 170 .4 '(0 0 25 1 75 1 100 0) '(0 0 5 .5 10 0 100 1) .1 '(0 E 25 AE 35 ER 65 ER 75 I 100 UH) '(.8 .15 .05) '(.005 .0125 .025) .05 .1))
;;; (with-sound () (vox 0 2 300 .4 '(0 0 25 1 75 1 100 0) '(0 0 5 .5 10 0 100 1) .1 '(0 I 5 OW 10 I 50 AE 100 OO) '(.8 .15 .05) '(.05 .0125 .025) .02 .1))
;;; (with-sound () (vox 0 5 600 .4 '(0 0 25 1 75 1 100 0) '(0 0 5 .5 10 0 100 1) .1 '(0 I 5 OW 10 I 50 AE 100 OO) '(.8 .16 .04) '(.01 .01 .1) .01 .1))
;;; -------- PQWVOX
;;; translation of CLM pqwvox.ins (itself translated from MUS10 of MLB's waveshaping voice instrument (using phase quadrature waveshaping))
(definstrument (pqw-vox beg dur freq spacing-freq amp ampfun freqfun freqscl phonemes formant-amps formant-shapes)
"(pqw-vox beg dur freq spacing-freq amp ampfun freqfun freqscl phonemes formant-amps formant-shapes) produces
vocal sounds using phase quadrature waveshaping"
(letrec ((vox-fun
(let ((formants '((I 390 1990 2550) (E 530 1840 2480) (AE 660 1720 2410)
(UH 520 1190 2390) (A 730 1090 2440) (OW 570 840 2410)
(U 440 1020 2240) (OO 300 870 2240) (ER 490 1350 1690)
(W 300 610 2200) (LL 380 880 2575) (R 420 1300 1600)
(Y 300 2200 3065) (EE 260 3500 3800) (LH 280 1450 1600)
(L 300 1300 3000) (I2 350 2300 3340) (B 200 800 1750)
(D 300 1700 2600) (G 250 1350 2000) (M 280 900 2200)
(N 280 1700 2600) (NG 280 2300 2750) (P 300 800 1750)
(T 200 1700 2600) (K 350 1350 2000) (F 175 900 4400)
(TH 200 1400 2200) (S 200 1300 2500) (SH 200 1800 2000)
(V 175 1100 2400) (THE 200 1600 2200)(Z 200 1300 2500)
(ZH 175 1800 2000) (ZZ 900 2400 3800) (VV 565 1045 2400))))
;; formant center frequencies for a male speaker
(lambda (phons which newenv)
;; make an envelope from which-th entry of phoneme data referred to by phons
(if (null? phons)
newenv
(vox-fun (cddr phons) which
(append newenv
(list (car phons)
((do ((phoneme (cadr phons))
(form formants (cdr form)))
((eq? (caar form) phoneme)
(cdar form)))
which)))))))))
(let ((start (seconds->samples beg))
(end (seconds->samples (+ beg dur)))
(car-sin (make-oscil 0))
(car-cos (make-oscil 0 :initial-phase (/ pi 2.0)))
(frq-ratio (/ spacing-freq freq))
(fs (length formant-amps))
(freqf (make-env freqfun :duration dur :scaler (* freqscl freq) :offset freq))
(per-vib (make-triangle-wave :frequency 6.0 :amplitude (* freq .1)))
(ran-vib (make-rand-interp :frequency 20.0 :amplitude (* freq .05))))
(let ((sin-evens (make-vector fs))
(cos-evens (make-vector fs))
(sin-odds (make-vector fs))
(cos-odds (make-vector fs))
(ampfs (make-vector fs))
(frmfs (make-vector fs))
(sin-coeffs (make-vector fs))
(cos-coeffs (make-vector fs))
(frq 0.0) (rfrq 0.0) (carcos 0.0) (carsin 0.0)
(frac 0.0) (fracf 0.0) (frm0 0.0) (frm-int 0) (fax 0.0) (yfax 0.0))
(do ((i 0 (+ i 1)))
((= i fs))
(let ((shape (normalize-partials (formant-shapes i))))
(set! (sin-evens i) (make-oscil 0))
(set! (sin-odds i) (make-oscil 0))
(set! (cos-evens i) (make-oscil 0 :initial-phase (/ pi 2.0)))
(set! (cos-odds i) (make-oscil 0 :initial-phase (/ pi 2.0)))
(set! (ampfs i) (make-env ampfun :scaler (* amp (formant-amps i)) :duration dur))
(set! (cos-coeffs i) (partials->polynomial shape mus-chebyshev-first-kind))
(set! (sin-coeffs i) (partials->polynomial shape mus-chebyshev-second-kind))
(set! (frmfs i) (make-env (vox-fun phonemes i ()) :duration dur))))
(if (= fs 3) ; unroll the inner loop in the most common case
(let ((frmfs0 (frmfs 0)) (frmfs1 (frmfs 1)) (frmfs2 (frmfs 2))
(ampfs0 (ampfs 0)) (ampfs1 (ampfs 1)) (ampfs2 (ampfs 2))
(sin-evens0 (sin-evens 0)) (sin-evens1 (sin-evens 1)) (sin-evens2 (sin-evens 2))
(sin-odds0 (sin-odds 0)) (sin-odds1 (sin-odds 1)) (sin-odds2 (sin-odds 2))
(cos-evens0 (cos-evens 0)) (cos-evens1 (cos-evens 1)) (cos-evens2 (cos-evens 2))
(cos-odds0 (cos-odds 0)) (cos-odds1 (cos-odds 1)) (cos-odds2 (cos-odds 2))
(cos-coeffs0 (cos-coeffs 0)) (cos-coeffs1 (cos-coeffs 1)) (cos-coeffs2 (cos-coeffs 2))
(sin-coeffs0 (sin-coeffs 0)) (sin-coeffs1 (sin-coeffs 1)) (sin-coeffs2 (sin-coeffs 2)))
(do ((i start (+ i 1)))
((= i end))
(set! frq (+ (env freqf) (triangle-wave per-vib) (rand-interp ran-vib)))
(set! rfrq (hz->radians frq))
(set! carsin (oscil car-sin (* rfrq frq-ratio)))
(set! carcos (oscil car-cos (* rfrq frq-ratio)))
(set! frm0 (/ (env frmfs0) frq))
(set! frm-int (floor frm0))
(set! frac (- frm0 frm-int))
(set! fracf (* frm-int rfrq))
(set! fax (polynomial cos-coeffs0 carcos))
(set! yfax (* carsin (polynomial sin-coeffs0 carcos)))
(outa i
(* (env ampfs0)
(if (even? frm-int)
(+ (* (- 1.0 frac) (- (* yfax (oscil sin-evens0 fracf)) (* fax (oscil cos-evens0 fracf))))
(* frac (- (* yfax (oscil sin-odds0 (+ fracf rfrq))) (* fax (oscil cos-odds0 (+ fracf rfrq))))))
(+ (* frac (- (* yfax (oscil sin-evens0 (+ fracf rfrq))) (* fax (oscil cos-evens0 (+ fracf rfrq)))))
(* (- 1.0 frac) (- (* yfax (oscil sin-odds0 fracf)) (* fax (oscil cos-odds0 fracf))))))))
(set! frm0 (/ (env frmfs1) frq))
(set! frm-int (floor frm0))
(set! frac (- frm0 frm-int))
(set! fracf (* frm-int rfrq))
(set! fax (polynomial cos-coeffs1 carcos))
(set! yfax (* carsin (polynomial sin-coeffs1 carcos)))
(outa i
(* (env ampfs1)
(if (even? frm-int)
(+ (* (- 1.0 frac) (- (* yfax (oscil sin-evens1 fracf)) (* fax (oscil cos-evens1 fracf))))
(* frac (- (* yfax (oscil sin-odds1 (+ fracf rfrq))) (* fax (oscil cos-odds1 (+ fracf rfrq))))))
(+ (* frac (- (* yfax (oscil sin-evens1 (+ fracf rfrq))) (* fax (oscil cos-evens1 (+ fracf rfrq)))))
(* (- 1.0 frac) (- (* yfax (oscil sin-odds1 fracf)) (* fax (oscil cos-odds1 fracf))))))))
(set! frm0 (/ (env frmfs2) frq))
(set! frm-int (floor frm0))
(set! frac (- frm0 frm-int))
(set! fracf (* frm-int rfrq))
(set! fax (polynomial cos-coeffs2 carcos))
(set! yfax (* carsin (polynomial sin-coeffs2 carcos)))
(outa i
(* (env ampfs2)
(if (even? frm-int)
(+ (* (- 1.0 frac) (- (* yfax (oscil sin-evens2 fracf)) (* fax (oscil cos-evens2 fracf))))
(* frac (- (* yfax (oscil sin-odds2 (+ fracf rfrq))) (* fax (oscil cos-odds2 (+ fracf rfrq))))))
(+ (* frac (- (* yfax (oscil sin-evens2 (+ fracf rfrq))) (* fax (oscil cos-evens2 (+ fracf rfrq)))))
(* (- 1.0 frac) (- (* yfax (oscil sin-odds2 fracf)) (* fax (oscil cos-odds2 fracf))))))))))
(do ((i start (+ i 1)))
((= i end))
(set! frq (+ (env freqf) (triangle-wave per-vib) (rand-interp ran-vib)))
(set! rfrq (hz->radians frq))
(set! carsin (oscil car-sin (* rfrq frq-ratio)))
(set! carcos (oscil car-cos (* rfrq frq-ratio)))
(do ((k 0 (+ k 1)))
((= k fs))
(set! frm0 (/ (env (vector-ref frmfs k)) frq))
(set! frm-int (floor frm0))
(set! frac (- frm0 frm-int))
(set! fracf (* frm-int rfrq))
(set! fax (polynomial (vector-ref cos-coeffs k) carcos))
(set! yfax (* carsin (polynomial (vector-ref sin-coeffs k) carcos)))
(outa i (* (env (vector-ref ampfs k))
(if (even? frm-int)
(+ (* (- 1.0 frac) (- (* yfax (oscil (vector-ref sin-evens k) fracf))
(* fax (oscil (vector-ref cos-evens k) fracf))))
(* frac (- (* yfax (oscil (vector-ref sin-odds k) (+ fracf rfrq)))
(* fax (oscil (vector-ref cos-odds k) (+ fracf rfrq))))))
(+ (* frac (- (* yfax (oscil (vector-ref sin-evens k) (+ fracf rfrq)))
(* fax (oscil (vector-ref cos-evens k) (+ fracf rfrq)))))
(* (- 1.0 frac) (- (* yfax (oscil (vector-ref sin-odds k) fracf))
(* fax (oscil (vector-ref cos-odds k) fracf)))))))))))))))
;;; (with-sound (:statistics #t) (pqw-vox 0 1 300 300 .1 '(0 0 50 1 100 0) '(0 0 100 0) 0 '(0 L 100 L) '(.33 .33 .33) '((1 1 2 .5) (1 .5 2 .5 3 1) (1 1 4 .5))))
;;; (a test to see if the cancellation is working -- sounds like a mosquito)
;;; (with-sound () (pqw-vox 0 2 200 200 .1 '(0 0 50 1 100 0) '(0 0 100 1) .1 '(0 UH 100 ER) '(.8 .15 .05) '((1 1 2 .5) (1 1 2 .5 3 .2 4 .1) (1 1 3 .1 4 .5))))
;;; (with-sound () (pqw-vox 0 2 100 314 .1 '(0 0 50 1 100 0) '(0 0 100 1) .1 '(0 UH 100 ER) '(.8 .15 .05) '((1 1 2 .5) (1 1 2 .5 3 .2 4 .1) (1 1 3 .1 4 .5))))
;;; (with-sound () (pqw-vox 0 2 200 314 .1 '(0 0 50 1 100 0) '(0 0 100 1) .01 '(0 UH 100 ER) '(.8 .15 .05) '((1 1 2 .5) (1 1 4 .1) (1 1 2 .1 4 .05))))
;;; (with-sound () (pqw-vox 0 2 100 414 .2 '(0 0 50 1 100 0) '(0 0 100 1) .01 '(0 OW 50 E 100 ER) '(.8 .15 .05) '((1 1 2 .5 3 .1 4 .01) (1 1 4 .1) (1 1 2 .1 4 .05))))
;;; -------- FOF
(definstrument (fofins beg dur frq amp vib f0 a0 f1 a1 f2 a2 (ae '(0 0 25 1 75 1 100 0)) ve)
"(fofins beg dur frq amp vib f0 a0 f1 a1 f2 a2 (ampenv '(0 0 25 1 75 1 100 0)) vibenv) produces FOF
synthesis: (fofins 0 1 270 .2 .001 730 .6 1090 .3 2440 .1)"
(let ((foflen (if (= *clm-srate* 22050) 100 200)))
(let ((start (seconds->samples beg))
(end (seconds->samples (+ beg dur)))
(ampf (make-env ae :scaler amp :duration dur))
(vibf (make-env (or ve '(0 1 100 1)) :scaler vib :duration dur))
(frq0 (hz->radians f0))
(frq1 (hz->radians f1))
(frq2 (hz->radians f2))
(vibr (make-oscil 6))
(win-freq (/ (* 2.0 pi) foflen))
(wt0 (make-wave-train :size foflen :frequency frq)))
(let ((foftab (mus-data wt0)))
(do ((i 0 (+ i 1)))
((= i foflen))
(float-vector-set! foftab i (* (+ (* a0 (sin (* i frq0)))
(* a1 (sin (* i frq1)))
(* a2 (sin (* i frq2))))
.5 (- 1.0 (cos (* i win-freq)))))))
(do ((i start (+ i 1)))
((= i end))
(outa i (* (env ampf)
(wave-train wt0 (* (env vibf)
(oscil vibr)))))))))
;;; FM TRUMPET ---------------------------------------------------
;;; Dexter Morrill's FM-trumpet:
;;; from CMJ feb 77 p51
(definstrument (fm-trumpet startime dur
(frq1 250.0)
(frq2 1500.0)
(amp1 0.5)
(amp2 0.1)
(ampatt1 0.03)
(ampdec1 0.35)
(ampatt2 0.03)
(ampdec2 0.3)
(modfrq1 250.0)
(modind11 0.0)
(modind12 2.66)
(modfrq2 250.0)
(modind21 0.0)
(modind22 1.8)
(rvibamp 0.007)
(rvibfrq 125.0)
(vibamp 0.007)
(vibfrq 7.0)
(vibatt 0.6)
(vibdec 0.2)
(frqskw 0.03)
(frqatt 0.06)
(ampenv1 '(0 0 25 1 75 .9 100 0))
(ampenv2 '(0 0 25 1 75 .9 100 0))
(indenv1 '(0 0 25 1 75 .9 100 0))
(indenv2 '(0 0 25 1 75 .9 100 0))
(degree 0.0)
(distance 1.0)
(reverb-amount 0.005))
(let ((dec-01 (max 75 (* 100 (- 1.0 (/ .01 dur))))))
(let ((beg (seconds->samples startime))
(end (seconds->samples (+ startime dur)))
(loc (make-locsig degree distance reverb-amount))
(per-vib-f (let ((vibe (stretch-envelope '(0 1 25 .1 75 0 100 0)
25 (min (* 100 (/ vibatt dur)) 45)
75 (max (* 100 (- 1.0 (/ vibdec dur))) 55))))
(make-env vibe :scaler vibamp :duration dur)))
(ran-vib (make-rand-interp :frequency rvibfrq :amplitude rvibamp))
(per-vib (make-oscil vibfrq))
(frq-f (let ((frqe (stretch-envelope '(0 0 25 1 75 1 100 0)
25 (min 25 (* 100 (/ frqatt dur)))
75 dec-01)))
(make-env frqe :scaler frqskw :offset 1.0 :duration dur)))
(ampattpt1 (min 25 (* 100 (/ ampatt1 dur))))
(ampdecpt1 (max 75 (* 100 (- 1.0 (/ ampdec1 dur)))))
(ampattpt2 (min 25 (* 100 (/ ampatt2 dur))))
(ampdecpt2 (max 75 (* 100 (- 1.0 (/ ampdec2 dur))))))
(let ((mod1-f (make-env (stretch-envelope indenv1 25 ampattpt1 75 dec-01)
:scaler (* modfrq1 (- modind12 modind11)) :duration dur))
(mod1 (make-oscil 0.0))
(car1 (make-oscil 0.0))
;; set frequency to zero here because it is handled multiplicatively below
(car1-f (make-env (stretch-envelope ampenv1 25 ampattpt1 75 ampdecpt1)
:scaler amp1 :duration dur))
(mod2-f (make-env (stretch-envelope indenv2 25 ampattpt2 75 dec-01)
:scaler (* modfrq2 (- modind22 modind21)) :duration dur))
(mod2 (make-oscil 0.0))
(car2 (make-oscil 0.0))
(car2-f (make-env (stretch-envelope ampenv2 25 ampattpt2 75 ampdecpt2)
:scaler amp2 :duration dur)))
(do ((i beg (+ i 1)))
((= i end))
(let ((frq-change (hz->radians (* (+ 1.0 (rand-interp ran-vib))
(+ 1.0 (* (env per-vib-f) (oscil per-vib)))
(env frq-f)))))
(locsig loc i (+ (* (env car1-f)
(oscil car1 (* frq-change
(+ frq1 (* (env mod1-f)
(oscil mod1 (* modfrq1 frq-change)))))))
(* (env car2-f)
(oscil car2 (* frq-change
(+ frq2 (* (env mod2-f)
(oscil mod2 (* modfrq2 frq-change)))))))))))))))
;;; -------- STEREO-FLUTE
(definstrument (stereo-flute start dur freq flow
(flow-envelope '(0 1 100 1))
(decay 0.01) ; additional time for instrument to decay
(noise 0.0356)
(embouchure-size 0.5)
(fbk-scl1 0.5) ; these two are crucial for good results
(fbk-scl2 0.55)
(offset-pos 0.764264) ; from 0.0 to 1.0 along the bore
(out-scl 1.0)
(a0 0.7) (b1 -0.3) ; filter coefficients
(vib-rate 5) (vib-amount 0.03)
(ran-rate 5) (ran-amount 0.03))
"(stereo-flute dur freq flow
(flow-envelope '(0 1 100 1)) (decay 0.01)
(noise 0.0356) (embouchure-size 0.5) (fbk-scl1 0.5)
(fbk-scl2 0.55) (offset-pos 0.764264) (out-scl 1.0)
(a0 0.7) (b1 -0.3) (vib-rate 5) (vib-amount 0.03)
(ran-rate 5) (ran-amount 0.03))
is a physical model of a flute:
(stereo-flute 0 1 440 .55 :flow-envelope '(0 0 1 1 2 1 3 0))"
(let ((period-samples (floor (/ *clm-srate* freq))))
(let ((embouchure-samples (floor (* embouchure-size period-samples))))
(let ((current-excitation 0.0)
(current-difference 0.0)
(current-flow 0.0)
(out-sig 0.0)
(tap-sig 0.0)
(previous-out-sig 0.0)
(previous-tap-sig 0.0)
(dc-blocked-a 0.0)
(dc-blocked-b 0.0)
(previous-dc-blocked-a 0.0)
(previous-dc-blocked-b 0.0)
(delay-sig 0.0)
(emb-sig 0.0)
(beg (seconds->samples start))
(end (seconds->samples (+ start dur)))
(flowf (make-env flow-envelope
:scaler flow
:duration (- dur decay)))
(periodic-vibrato (make-oscil vib-rate))
(random-vibrato (make-rand-interp :frequency ran-rate :amplitude ran-amount))
(breath (make-rand :frequency (/ *clm-srate* 2) :amplitude noise))
(embouchure (make-delay embouchure-samples :initial-element 0.0))
(bore (make-delay period-samples))
(offset (floor (* period-samples offset-pos)))
(reflection-lowpass-filter (make-one-pole a0 b1)))
(do ((i beg (+ i 1)))
((= i end))
(set! delay-sig (delay bore out-sig))
(set! emb-sig (delay embouchure current-difference))
(set! current-flow (+ (* vib-amount (oscil periodic-vibrato))
(rand-interp random-vibrato)
(env flowf)))
(set! current-difference
(+ current-flow
(* current-flow (rand breath))
(* fbk-scl1 delay-sig)))
(set! current-excitation (- emb-sig (* emb-sig emb-sig emb-sig)))
(set! out-sig (one-pole reflection-lowpass-filter
(+ current-excitation (* fbk-scl2 delay-sig))))
(set! tap-sig (tap bore offset))
;; NB the DC blocker is not in the cicuit. It is applied to the out-sig
;; but the result is not fed back into the system.
(set! dc-blocked-a (- (+ out-sig (* 0.995 previous-dc-blocked-a)) previous-out-sig))
(set! dc-blocked-b (- (+ tap-sig (* 0.995 previous-dc-blocked-b)) previous-tap-sig))
(outa i (* out-scl dc-blocked-a))
(outb i (* out-scl dc-blocked-b))
(set! previous-out-sig out-sig)
(set! previous-dc-blocked-a dc-blocked-a)
(set! previous-tap-sig tap-sig)
(set! previous-dc-blocked-b dc-blocked-b))))))
;;; -------- FM-BELL
(definstrument (fm-bell startime dur frequency amplitude amp-env index-env index)
"(fm-bell startime dur frequency amplitude amp-env index-env index) mixes in one fm bell note"
(let ((fmInd2 (hz->radians (* 4.0 (- 8.0 (/ frequency 50.0))))))
(let ((beg (seconds->samples startime))
;(len (seconds->samples dur))
(end (seconds->samples (+ startime dur)))
(fmInd1 (hz->radians (* 32.0 frequency)))
(fmInd3 (* fmInd2 0.705 (- 1.4 (/ frequency 250.0))))
(fmInd4 (hz->radians (* 32.0 (- 20 (/ frequency 20)))))
(mod1 (make-oscil (* frequency 2)))
(mod2 (make-oscil (* frequency 1.41)))
(mod3 (make-oscil (* frequency 2.82)))
(mod4 (make-oscil (* frequency 2.4)))
(car1 (make-oscil frequency))
(car2 (make-oscil frequency))
(car3 (make-oscil (* frequency 2.4)))
(indf (make-env (or index-env
'(0 1 2 1.1 25 .75 75 .5 100 .2))
(or index 1.0) dur))
(ampf (make-env (or amp-env
'(0 0 .1 1 10 .6 25 .3 50 .15 90 .1 100 0))
amplitude dur)))
(do ((i beg (+ i 1)))
((= i end))
(let ((fmenv (env indf)))
(outa i (* (env ampf)
(+ (oscil car1 (* fmenv fmInd1 (oscil mod1)))
(* .15 (oscil car2 (* fmenv
(+ (* fmInd2 (oscil mod2))
(* fmInd3
(oscil mod3))))))
(* .15 (oscil car3 (* fmenv
fmInd4
(oscil mod4))))))))))))
;(define fbell '(0 1 2 1.1000 25 .7500 75 .5000 100 .2000 ))
;(define abell '(0 0 .1000 1 10 .6000 25 .3000 50 .1500 90 .1000 100 0 ))
;(fm-bell 0.0 1.0 220.0 .5 abell fbell 1.0)
;;; -------- FM_INSECT
(definstrument (fm-insect startime dur frequency amplitude amp-env
mod-freq mod-skew mod-freq-env mod-index mod-index-env
fm-index fm-ratio
(degree 0.0)
(distance 1.0)
(reverb-amount 0.005))
(let ((beg (seconds->samples startime))
(end (seconds->samples (+ startime dur)))
(loc (make-locsig degree distance reverb-amount))
(carrier (make-oscil frequency))
(fm1-osc (make-oscil mod-freq))
(fm2-osc (make-oscil (* fm-ratio frequency)))
(ampf (make-env amp-env :scaler amplitude :duration dur))
(indf (make-env mod-index-env :scaler (hz->radians mod-index) :duration dur))
(modfrqf (make-env mod-freq-env :scaler (hz->radians mod-skew) :duration dur))
(fm2-amp (hz->radians (* fm-index fm-ratio frequency))))
(do ((i beg (+ i 1)))
((= i end))
(let ((garble-in (* (env indf)
(oscil fm1-osc (env modfrqf)))))
(locsig loc i (* (env ampf)
(oscil carrier (+ (* fm2-amp (oscil fm2-osc garble-in))
garble-in))))))))
#|
(with-sound (:srate 22050)
(let ((locust '(0 0 40 1 95 1 100 .5))
(bug_hi '(0 1 25 .7 75 .78 100 1))
(amp '(0 0 25 1 75 .7 100 0)))
(fm-insect 0 1.699 4142.627 .015 amp 60 -16.707 locust 500.866 bug_hi .346 .500)
(fm-insect 0.195 .233 4126.284 .030 amp 60 -12.142 locust 649.490 bug_hi .407 .500)
(fm-insect 0.217 2.057 3930.258 .045 amp 60 -3.011 locust 562.087 bug_hi .591 .500)
(fm-insect 2.100 1.500 900.627 .06 amp 40 -16.707 locust 300.866 bug_hi .346 .500)
(fm-insect 3.000 1.500 900.627 .06 amp 40 -16.707 locust 300.866 bug_hi .046 .500)
(fm-insect 3.450 1.500 900.627 .09 amp 40 -16.707 locust 300.866 bug_hi .006 .500)
(fm-insect 3.950 1.500 900.627 .12 amp 40 -10.707 locust 300.866 bug_hi .346 .500)
(fm-insect 4.300 1.500 900.627 .09 amp 40 -20.707 locust 300.866 bug_hi .246 .500)))
|#
;;; -------- FM-DRUM
;;; Jan Mattox's fm drum:
(definstrument (fm-drum start-time duration frequency amplitude index
high (degree 0.0) (distance 1.0) (reverb-amount 0.01))
(let (;; many of the following variables were originally passed as arguments
(indxfun '(0 0 5 .014 10 .033 15 .061 20 .099
25 .153 30 .228 35 .332 40 .477
45 .681 50 .964 55 .681 60 .478 65 .332
70 .228 75 .153 80 .099 85 .061
90 .033 95 .0141 100 0))
(indxpt (- 100 (* 100 (/ (- duration .1) duration))))
(atdrpt (* 100 (/ (if high .01 .015) duration))))
(let ((divindxf (stretch-envelope indxfun 50 atdrpt 65 indxpt))
(ampfun '(0 0 3 .05 5 .2 7 .8 8 .95 10 1.0 12 .95 20 .3 30 .1 100 0))
(casrat (if high 8.525 3.515))
(fmrat (if high 3.414 1.414))
(glsfun '(0 0 25 0 75 1 100 1)))
(let ((beg (seconds->samples start-time))
(end (seconds->samples (+ start-time duration)))
(glsf (make-env glsfun :scaler (if high (hz->radians 66) 0.0) :duration duration))
(ampf (let ((ampe (stretch-envelope ampfun
10 atdrpt
15 (max (+ atdrpt 1)
(- 100 (* 100 (/ (- duration .2) duration)))))))
(make-env ampe :scaler amplitude :duration duration)))
(indxf (make-env divindxf :scaler (min (hz->radians (* index fmrat frequency)) pi) :duration duration))
(mindxf (make-env divindxf :scaler (min (hz->radians (* index casrat frequency)) pi) :duration duration))
(devf (let ((deve (stretch-envelope ampfun
10 atdrpt
90 (max (+ atdrpt 1)
(- 100 (* 100 (/ (- duration .05) duration)))))))
(make-env deve :scaler (min pi (hz->radians 7000)) :duration duration)))
(loc (make-locsig degree distance reverb-amount))
(rn (make-rand :frequency 7000 :amplitude 1.0))
(carrier (make-oscil frequency))
(fmosc (make-oscil (* frequency fmrat)))
(cascade (make-oscil (* frequency casrat))))
(do ((i beg (+ i 1)))
((= i end))
(let ((gls (env glsf)))
(locsig loc i (* (env ampf)
(oscil carrier
(+ gls
(* (env indxf)
(oscil fmosc
(+ (* gls fmrat)
(* (env mindxf)
(oscil cascade
(+ (* gls casrat)
(* (env devf) (rand rn))))))))))))))))))
#|
(with-sound ()
(fm-drum 0 1.5 55 .3 5 #f)
(fm-drum 2 1.5 66 .3 4 #t))
|#
;;; -------- FM-GONG
;;; Paul Weineke's gong.
(definstrument (gong start-time duration frequency amplitude
(degree 0.0) (distance 1.0) (reverb-amount 0.005))
(let* ((mfq1 (* frequency 1.16))
(mfq2 (* frequency 3.14))
(mfq3 (* frequency 1.005))
(indx01 (hz->radians (* .01 mfq1)))
(indx11 (hz->radians (* .30 mfq1)))
(indx02 (hz->radians (* .01 mfq2)))
(indx12 (hz->radians (* .38 mfq2)))
(indx03 (hz->radians (* .01 mfq3)))
(indx13 (hz->radians (* .50 mfq3)))
(atpt 5)
(atdur (* 100 (/ .002 duration)))
(expf '(0 0 3 1 15 .5 27 .25 50 .1 100 0))
(rise '(0 0 15 .3 30 1.0 75 .5 100 0))
(fmup '(0 0 75 1.0 98 1.0 100 0))
(fmdwn '(0 0 2 1.0 100 0))
(ampfun (make-env (stretch-envelope expf atpt atdur)
:scaler amplitude :duration duration))
(indxfun1 (make-env fmup :duration duration
:scaler (- indx11 indx01) :offset indx01))
(indxfun2 (make-env fmdwn :duration duration
:scaler (- indx12 indx02) :offset indx02))
(indxfun3 (make-env rise :duration duration
:scaler (- indx13 indx03) :offset indx03))
(loc (make-locsig degree distance reverb-amount))
(carrier (make-oscil frequency))
(mod1 (make-oscil mfq1))
(mod2 (make-oscil mfq2))
(mod3 (make-oscil mfq3))
(beg (seconds->samples start-time))
(end (seconds->samples (+ start-time duration))))
(do ((i beg (+ i 1)))
((= i end))
(locsig loc i (* (env ampfun)
(oscil carrier (+ (* (env indxfun1) (oscil mod1))
(* (env indxfun2) (oscil mod2))
(* (env indxfun3) (oscil mod3)))))))))
;;; (with-sound () (gong 0 3 261.61 .6))
(definstrument (attract beg dur amp c-1) ;c from 1 to 10 or so
;; by James McCartney, from CMJ vol 21 no 3 p 6
(let ((st (seconds->samples beg))
(nd (seconds->samples (+ beg dur)))
(c c-1) (a .2) (b .2) (dt .04)
(scale (/ (* .5 amp) c-1))
(x -1.0) (y 0.0) (z 0.0))
(do ((i st (+ i 1)))
((= i nd))
(let ((x1 (- x (* dt (+ y z)))))
(set! y (+ y (* dt (+ x (* a y)))))
(set! z (+ z (* dt (- (+ b (* x z)) (* c z)))))
(set! x x1)
(outa i (* scale x))))))
;;; -------- PQW
(definstrument (pqw start dur spacing-freq carrier-freq amplitude ampfun indexfun partials
(degree 0.0)
(distance 1.0)
(reverb-amount 0.005))
;; phase-quadrature waveshaping used to create asymmetric (i.e. single side-band) spectra.
;; The basic idea here is a variant of sin x sin y - cos x cos y = cos (x + y)
(define (clip-env e)
(do ((x e (cddr x)))
((null? x) e)
(if (> (cadr x) 1.0)
(list-set! x 1 1.0))))
(let* ((normalized-partials (normalize-partials partials))
(spacing-cos (make-oscil spacing-freq :initial-phase (/ pi 2.0)))
(spacing-sin (make-oscil spacing-freq))
(carrier-cos (make-oscil carrier-freq :initial-phase (/ pi 2.0)))
(carrier-sin (make-oscil carrier-freq))
(sin-coeffs (partials->polynomial normalized-partials mus-chebyshev-second-kind))
(cos-coeffs (partials->polynomial normalized-partials mus-chebyshev-first-kind))
(amp-env (make-env ampfun :scaler amplitude :duration dur))
(ind-env (make-env (clip-env indexfun) :duration dur))
(loc (make-locsig degree distance reverb-amount))
(r (/ carrier-freq spacing-freq))
(tr (make-triangle-wave :frequency 5 :amplitude (hz->radians (* .005 spacing-freq))))
(rn (make-rand-interp :frequency 12 :amplitude (hz->radians (* .005 spacing-freq))))
(beg (seconds->samples start))
(end (seconds->samples (+ start dur))))
(do ((i beg (+ i 1)))
((= i end))
(let* ((vib (+ (triangle-wave tr) (rand-interp rn)))
(ax (* (env ind-env) (oscil spacing-cos vib))))
(locsig loc i (* (env amp-env)
(- (* (oscil carrier-sin (* vib r))
(oscil spacing-sin vib)
(polynomial sin-coeffs ax))
(* (oscil carrier-cos (* vib r))
(polynomial cos-coeffs ax)))))))))
;; (with-sound () (pqw 0 .5 200 1000 .2 '(0 0 25 1 100 0) '(0 1 100 0) '(2 .1 3 .3 6 .5)))
;; to see the asymmetric spectrum most clearly, set the index function above to '(0 1 100 1)
;;; taken from Perry Cook's stkv1.tar.Z (Synthesis Toolkit), but I was
;;; in a bit of a hurry and may not have made slavishly accurate translations.
;;; Please let me know of any errors.
(definstrument (tubebell beg dur freq amp (base 32.0))
;; from Perry Cook's TubeBell.cpp
(let ((osc0 (make-oscil (* freq 0.995)))
(osc1 (make-oscil (* freq 1.414 0.995)))
(osc2 (make-oscil (* freq 1.005)))
(osc3 (make-oscil (* freq 1.414)))
(ampenv1 (make-env (list 0 0 .005 1 dur 0) :base base :duration dur :scaler (* amp .5 .707)))
(ampenv2 (make-env (list 0 0 .001 1 dur 0) :base (* 2 base) :duration dur :scaler (* .5 amp)))
(ampmod (make-oscil 2.0))
(st (seconds->samples beg))
(nd (seconds->samples (+ beg dur))))
(do ((i st (+ i 1)))
((= i nd))
(outa i (* (+ (* .007 (oscil ampmod)) .993)
(+ (* (env ampenv1) (oscil osc0 (* .203 (oscil osc1))))
(* (env ampenv2) (oscil osc2 (* .144 (oscil osc3))))))))))
(definstrument (wurley beg dur freq amp)
;; from Perry Cook's Wurley.cpp
(let ((osc0 (make-oscil freq))
(osc1 (make-oscil (* freq 4.0)))
(osc2 (make-oscil 510.0))
(osc3 (make-oscil 510.0))
(ampmod (make-oscil 8.0))
(g0 (* .5 amp))
(ampenv (make-env '(0 0 1 1 9 1 10 0) :duration dur))
(indenv (make-env (list 0 0 .001 1 .15 0 (max dur .16) 0) :duration dur :scaler .117))
(resenv (make-env (list 0 0 .001 1 .25 0 (max dur .26) 0) :duration dur :scaler (* .5 .307 amp)))
(st (seconds->samples beg))
(nd (seconds->samples (+ beg dur))))
(do ((i st (+ i 1)))
((= i nd))
(outa i (* (env ampenv)
(+ 1.0 (* .007 (oscil ampmod)))
(+ (* g0 (oscil osc0 (* .307 (oscil osc1))))
(* (env resenv) (oscil osc2 (* (env indenv) (oscil osc3))))))))))
(definstrument (rhodey beg dur freq amp (base .5))
;; from Perry Cook's Rhodey.cpp
(let ((osc0 (make-oscil freq))
(osc1 (make-oscil (* freq 0.5)))
(osc2 (make-oscil freq))
(osc3 (make-oscil (* freq 15.0)))
(ampenv1 (make-env (list 0 0 .005 1 dur 0) :base base :duration dur :scaler (* amp .5)))
(ampenv2 (make-env (list 0 0 .001 1 dur 0) :base (* base 1.5) :duration dur :scaler (* amp .5)))
(ampenv3 (make-env (list 0 0 .001 1 .25 0 (max dur .26) 0) :base (* base 4) :duration dur :scaler .109))
(st (seconds->samples beg))
(nd (seconds->samples (+ beg dur))))
(do ((i st (+ i 1)))
((= i nd))
(outa i (+ (* (env ampenv1) (oscil osc0 (* .535 (oscil osc1))))
(* (env ampenv2) (oscil osc2 (* (env ampenv3) (oscil osc3)))))))))
(definstrument (hammondoid beg dur freq amp)
;; from Perry Cook's BeeThree.cpp
(let ((osc0 (make-oscil (* freq 0.999)))
(osc1 (make-oscil (* freq 1.997)))
(osc2 (make-oscil (* freq 3.006)))
(osc3 (make-oscil (* freq 6.009)))
(ampenv1 (make-env (list 0 0 .005 1 (- dur .008) 1 dur 0) :duration dur))
(ampenv2 (make-env (list 0 0 .005 1 dur 0) :duration dur :scaler (* .5 .75 amp)))
(g0 (* .25 .75 amp))
(g1 (* .25 .75 amp))
(g2 (* .5 amp))
(st (seconds->samples beg))
(nd (seconds->samples (+ beg dur))))
(do ((i st (+ i 1)))
((= i nd))
(outa i (+ (* (env ampenv1)
(+ (* g0 (oscil osc0))
(* g1 (oscil osc1))
(* g2 (oscil osc2))))
(* (env ampenv2) (oscil osc3)))))))
(definstrument (metal beg dur freq amp)
;; from Perry Cook's HeavyMtl.cpp
(let ((osc0 (make-oscil freq))
(osc1 (make-oscil (* freq 4.0 0.999)))
(osc2 (make-oscil (* freq 3.0 1.001)))
(osc3 (make-oscil (* freq 0.50 1.002)))
(ampenv0 (make-env (list 0 0 .001 1 (- dur .002) 1 dur 0) :duration dur :scaler (* amp .615)))
(ampenv1 (make-env (list 0 0 .001 1 (- dur .011) 1 dur 0) :duration dur :scaler .202))
(ampenv2 (make-env (list 0 0 .01 1 (- dur .015) 1 dur 0) :duration dur :scaler .574))
(ampenv3 (make-env (list 0 0 .03 1 (- dur .040) 1 dur 0) :duration dur :scaler .116))
(st (seconds->samples beg))
(nd (seconds->samples (+ beg dur))))
(do ((i st (+ i 1)))
((= i nd))
(outa i (* (env ampenv0)
(oscil osc0
(+ (* (env ampenv1) (oscil osc1 (* (env ampenv2) (oscil osc2))))
(* (env ampenv3) (oscil osc3)))))))))
(definstrument (drone startime dur frequency amp ampfun synth ampat ampdc amtrev deg dis rvibamt rvibfreq)
(let ((beg (seconds->samples startime))
(end (seconds->samples (+ startime dur)))
(waveform (partials->wave synth))
(amplitude (* amp .25))
(freq (hz->radians frequency)))
(let ((s (make-table-lookup :frequency frequency :wave waveform))
(amp-env (let ((ampe (stretch-envelope ampfun 25 (* 100 (/ ampat dur)) 75 (- 100 (* 100 (/ ampdc dur))))))
(make-env ampe :scaler amplitude :duration dur)))
(ran-vib (make-rand :frequency rvibfreq :amplitude (* rvibamt freq)))
(loc (make-locsig deg dis amtrev)))
(do ((i beg (+ i 1)))
((= i end))
(locsig loc i (* (env amp-env) (table-lookup s (rand ran-vib))))))))
(definstrument (canter beg dur pitch amp-1 deg dis pcrev ampfun ranfun skewfun
skewpc ranpc ranfreq indexfun atdr dcdr
ampfun1 indfun1 fmtfun1
ampfun2 indfun2 fmtfun2
ampfun3 indfun3 fmtfun3
ampfun4 indfun4 fmtfun4)
(let* ((amp (* amp-1 .25)) ;pvc's amplitudes in bag.clm are very high (overflows)
(rangetop 910.0)
(rangebot 400.0)
(k (floor (* 100 (log (/ pitch rangebot) (/ rangetop rangebot)))))
(atpt (* 100 (/ atdr dur)))
(dcpt (- 100 (* 100 (/ dcdr dur))))
(lfmt1 (envelope-interp k fmtfun1))
(lfmt2 (envelope-interp k fmtfun2))
(lfmt3 (envelope-interp k fmtfun3))
(lfmt4 (envelope-interp k fmtfun4))
(dev11 (hz->radians (* (envelope-interp k indfun1) pitch)))
(dev12 (hz->radians (* (envelope-interp k indfun2) pitch)))
(dev13 (hz->radians (* (envelope-interp k indfun3) pitch)))
(dev14 (hz->radians (* (envelope-interp k indfun4) pitch)))
(start (seconds->samples beg))
(end (seconds->samples (+ beg dur)))
(dev01 (* dev11 .5))
(dev02 (* dev12 .5))
(dev03 (* dev13 .5))
(dev04 (* dev14 .5))
(harm1 (floor (+ .5 (/ lfmt1 pitch))))
(harm2 (floor (+ .5 (/ lfmt2 pitch))))
(harm3 (floor (+ .5 (/ lfmt3 pitch))))
(harm4 (floor (+ .5 (/ lfmt4 pitch))))
(lamp1 (* (envelope-interp k ampfun1) amp (- 1 (abs (- harm1 (/ lfmt1 pitch))))))
(lamp2 (* (envelope-interp k ampfun2) amp (- 1 (abs (- harm2 (/ lfmt2 pitch))))))
(lamp3 (* (envelope-interp k ampfun3) amp (- 1 (abs (- harm3 (/ lfmt3 pitch))))))
(lamp4 (* (envelope-interp k ampfun4) amp (- 1 (abs (- harm4 (/ lfmt4 pitch))))))
(tidx-stretched (stretch-envelope indexfun 25 atpt 75 dcpt))
(tampfun (make-env (stretch-envelope ampfun 25 atpt 75 dcpt) :duration dur))
(tskwfun (make-env (stretch-envelope skewfun 25 atpt 75 dcpt) :scaler (hz->radians (* pitch skewpc)) :duration dur))
(tranfun (make-env (stretch-envelope ranfun 25 atpt 75 dcpt) :duration dur))
(d1env (make-env tidx-stretched :offset dev01 :scaler dev11 :duration dur))
(d2env (make-env tidx-stretched :offset dev02 :scaler dev12 :duration dur))