File: part16.html

package info (click to toggle)
nyquist 3.12%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 58,036 kB
  • sloc: ansic: 74,355; lisp: 20,485; java: 9,390; cpp: 6,695; sh: 207; xml: 58; makefile: 40
file content (898 lines) | stat: -rw-r--r-- 47,004 bytes parent folder | download | duplicates (2)
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
<html><head><title>Nyquist Libraries</title>
<link rel="stylesheet" type="text/css" href="nyquiststyle.css">
</head>
<body bgcolor="ffffff">
<a href = "part15.html">Previous Section</a> | <a href = "part17.html">Next Section</a> | <a href = "title.html#toc">Table of Contents</a> | <a href = "indx.html">Index</a> | <a href = "title.html">Title Page</a>
<hr>
<a name = "181"><h2>Nyquist Libraries</h2></a>
<a name="index1277"></a>
Nyquist is always growing with new functions. Functions that are most fundamental
are added to the core language. These functions are automatically loaded when you 
start Nyquist, and they are documented in the preceding chapters. Other functions seem
less central and are implemented as lisp files that you can load. These are called
library functions, and they are described here. 
<p>
To use a library function, you
must first load the library, e.g. <code>(load "pianosyn")</code> loads the piano synthesis
library. The libraries are all located in the <code>lib</code> directory, and you 
should therefore include this directory on your <code>XLISPPATH</code> variable. (See 
Section <a href = "part2.html#3">"Installation"</a>.) Each library is documented in one of the following
sections. When you load the library described by the section, all functions
documented in that section become available.
<p>
<a name = "182"><h3>Statistics</h3></a>
<a name="index1278"></a><a name="index1279"></a><a name="index1280"></a><a name="index1281"></a><a name="index1282"></a><a name="index1283"></a><a name="index1284"></a><a name="index1285"></a><a name="index1286"></a><a name="index1287"></a><a name="index1288"></a><a name="index1289"></a><a name="index1290"></a><a name="index1291"></a>
The file <code>statistics.lsp</code> defines a class and functions to compute simple statistics, histograms, correlation, and some other tests. See the source code for complete details.
<p>
<a name = "183"><h3>Plots</h3></a>
<a name="index1292"></a><a name="index1293"></a>
The Nyquist IDE has a simple facility to plot signals. For more advanced plotting, you can use <code>gnuplot.sal</code> to generate plots for <code>gnuplot</code>, a separate, but free program. See the source for details.
<p>
<a name = "184"><h3>Labeling Audio Events, Marking Audio Times, Displaying Marked Audio Times</h3></a>
<a name="index1294"></a><a name="index1295"></a><a name="index1296"></a><a name="index1297"></a>
The <code>labels.sal</code> program can convert lists to label files and label files to lists. Label files can be loaded along with audio in Audacity to show metadata. See the source for details.
<p>
<a name = "185"><h3>Linear Regression</h3></a>
<a name="index1298"></a><a name="index1299"></a><a name="index1300"></a>
See <code>regression.sal</code> for simple linear regression functions.
<p>
<a name = "186"><h3>Vector Math, Linear Algebra</h3></a>
<a name="index1301"></a><a name="index1302"></a><a name="index1303"></a><a name="index1304"></a><a name="index1305"></a><a name="index1306"></a><a name="index1307"></a><a name="index1308"></a><a name="index1309"></a><a name="index1310"></a><a name="index1311"></a><a name="index1312"></a><a name="index1313"></a><a name="index1314"></a>
See <code>vectors.lsp</code> for a simple implementation of vector arithmetic and other vector functions.
<p>
<a name = "187"><h3>Piano Synthesizer</h3></a>
The piano synthesizer (library name is <code>pianosyn.lsp</code>) generates
realistic piano tones using a multiple wavetable implementation by Zheng (Geoffrey)
Hua and Jim Beauchamp, University of Illinois. Please see the notice about
acknowledgements that prints when you load the file. Further informations and
example code can be found in 
<code>demos/piano.htm</code><a name="index1315"></a><a name="index1316"></a>. 
There are several useful functions in this library. These functions auto-load the 
<code>pianoysn.lsp</code> library if it is not already loaded:
<dl>
<dt>
<code>piano-note(<a name="index1317"></a><a name="index1318"></a><i>duration</i>, <i>step</i>, 
 <i>dynamic</i>)</code> [SAL]<br>

<code>(piano-note <i>duration</i> <i>step</i> <i>dynamic</i>)</code> [LISP]<dd>Synthesizes a piano tone. <i>Duration</i> is the duration to the point of
key release, after which there is a rapid decay. <i>Step</i> is the pitch in half
steps, and <i>dynamic</i> is approximately equivalent to a MIDI key velocity
parameter. Use a value near 100 for a loud sound and near 10 for a soft sound.<br><br>
<dt><code>piano-note-2(<a name="index1319"></a><i>step</i>, <i>dynamic</i>)</code> [SAL]<br>

<code>(piano-note-2 <i>step</i> <i>dynamic</i>)</code> [LISP]<dd>Similar to <code>piano-note</code> except the duration is nominally 1.0.<br><br>
<dt><code>piano-midi(<a name="index1320"></a><i>midi-file-name</i>)</code> [SAL]<br>

<code>(piano-midi <i>midi-file-name</i>)</code> [LISP]<dd>Use the piano synthesizer 
to play a MIDI file. The file name (a string) is given by <i>midi-file-name</i>.<br><br>
<dt><code>piano-midi2file(<a name="index1321"></a><i>midi-file-name</i>, 
<i>sound-file-name</i>)</code> [SAL]<br>

<code>(piano-midi2file <i>midi-file-name</i> <i>sound-file-name</i>)</code> [LISP]<dd>Use the piano synthesizer to play a MIDI file. The MIDI file
is given by <i>midi-file-name</i> and the (monophonic) result is written to the file
named <i>sound-file-name</i>.
</dl>
<p>
<a name = "188"><h3>Dynamics Compression</h3></a>
These functions
implement a compressor originally intended for noisy speech audio, but
usable in a variety of situations.
There are actually two compressors that can be used in 
series. The first, <code>compress</code>, is
a fairly standard one: it detects signal level with an RMS
detector and uses table-lookup to determine how much gain
to place on the original signal at that point. One bit of
cleverness here is that the RMS envelope is "followed" or
enveloped using <code>snd-follow</code>, which does look-ahead to anticipate
peaks before they happen.
<p>
The other interesting feature is <code>compress-map</code>, which builds 
a map in terms of compression and expansion. For speech, the recommended
procedure is to figure out the noise floor on the signal you are compressing
(for example, look at the signal where the speaker is not talking).
Use a compression map that leaves the noise alone and boosts
signals that are well above the noise floor. Alas, the <code>compress-map</code>
function is not written in these terms, so some head-scratching is
involved, but the results are quite good.
<p>
The second compressor is called <code>agc</code>, and it implements automatic gain
control that keeps peaks at or below 1.0. By combining <code>compress</code> and 
<code>agc</code>, you can process poorly recorded speech for playback on low-quality
speakers in noisy environments. The <code>compress</code> function modulates the 
short-term gain to to minimize the total dynamic range, keeping the speech at
a generally loud level, and the <code>agc</code> function rides the long-term gain
to set the overall level without clipping.
<p>
<dl>
<dt>
<code>compress-map(<a name="index1322"></a><i>compress-ratio</i>, 
<i>compress-threshold</i>, 
<i>expand-ratio</i>, <i>expand-threshold</i>, limit: <i>limit</i>, transition: 
<i>transition</i>, verbose: <i>verbose</i>)</code> [SAL]<br>

<code>(compress-map <i>compress-ratio</i> <i>compress-threshold</i>
 <i>expand-ratio</i> <i>expand-threshold</i> :limit <i>limit</i> :transition
 <i>transition</i> :verbose <i>verbose</i>)</code> [LISP]<dd>Construct
a map for the compress function. The map consists of two parts: a compression
part and an expansion part.
The intended use is to compress everything above compress-threshold by
compress-ratio, and to downward expand everything below expand-ratio
by expand-ratio.  Thresholds are in dB and ratios are dB-per-dB.
0dB corresponds to a peak amplitude of 1.0 or rms amplitude of 0.7
If the input goes above 0dB, the output can optionally be limited
by setting <code>limit:</code> (a keyword parameter) to <code>T</code>. 
This effectively changes 
the compression ratio to infinity at 0dB.  If <code>limit:</code> is <code>nil</code>
(the default), then the compression-ratio continues to apply above 0dB.<br><br>
<dt>Another keyword parameter, <code>transition:</code>, sets the amount below the
thresholds (in dB) that a smooth transition starts. The default is 0,
meaning that there is no smooth transition. The smooth transition is a
2nd-order polynomial that matches the slopes of the straight-line compression
curve and interpolates between them.<br><br>
<dt>If verbose is true (this is the default), the map is printed, showing,
for each dB value below zero of this input, what is the gain (in dB) 
indicated by the output. Only regions where the map is changing are 
printed because at lower values, the dB gain is constant.<br><br>
<dt>It is assumed that expand-threshold &lt;= compress-threshold &lt;= 0
The gain is unity at 0dB so if compression-ratio &gt; 1, then gain
will be greater than unity below 0dB.<br><br>
<dt>The result returned by this function is a sound for use in the <code>shape</code>
function. The sound maps input
dB to gain. Time 1.0 corresponds to 0dB, time 0.0 corresponds to
-100 dB, and time 2.0 corresponds to +100dB, so this is a 
100hz "sample rate" sound. The sound gives gain in dB.<br><br>
<dt><code>db-average(<a name="index1323"></a><i>input</i>)</code> [SAL]<br>

<code>(db-average <i>input</i>)</code> [LISP]<dd>Compute the average amplitude 
of <i>input</i> in dB.<br><br>
<dt><code>compress(<a name="index1324"></a><i>input</i>, <i>map</i>, <i>rise-time</i>, <i>fall-time</i> [, <i>lookahead</i>])</code> [SAL]<br>

<code>(compress <i>input</i> <i>map</i> <i>rise-time</i> <i>fall-time</i>
 [<i>lookahead</i>])</code> [LISP]<dd>Compress 
<i>input</i> using <i>map</i>, a compression curve
probably generated by <code>compress-map</code> (see above). Adjustments in gain have
the given <i>rise-time</i> and <i>fall-time</i>. Lookahead tells how far ahead to look
at the signal, and is <i>rise-time</i> by default.<br><br>
<dt><code>agc(<a name="index1325"></a><a name="index1326"></a><a name="index1327"></a><i>input</i>,
<i>range</i>, <i>rise-time</i>, <i>fall-time</i> [, <i>lookahead</i>])</code> [SAL]<br>

<code>(agc <i>input</i> <i>range</i> <i>rise-time</i> <i>fall-time</i>
 [<i>lookahead</i>])</code> [LISP]<dd>An automatic
gain control applied to <i>input</i>. The maximum gain in dB is <i>range</i>. Peaks
are attenuated to 1.0, and gain is controlled with the given <i>rise-time</i> and
<i>fall-time</i>. The look-ahead time default is <i>rise-time</i>.
</dl>
<p>
<a name = "189"><h3>Clipping Softener</h3></a>
This library, in <code>soften.lsp</code>, was written to improve the quality of
poorly recorded speech. In recordings of speech, extreme clipping generates
harsh high frequency noise. This can sound particulary bad on small speakers
that will emphasize high frequencies. This problem can be ameliorated by 
low-pass filtering regions where clipping occurs. The effect is to dull the
harsh clipping. Intelligibility is not affected by much, and the result can
be much more pleasant on the ears. Clipping is detected simply by looking for
large signal values. Assuming 8-bit recording, this level is set to 126/127.
<p>
The function works by cross-fading between the normal signal and a filtered 
signal as opposed to changing filter coefficients.
<p>
<dl>
<dt>
<code>soften-clipping(<a name="index1328"></a><a name="index1329"></a><i>snd</i>, 
<i>cutoff</i>)</code> [SAL]<br>

<code>(soften-clipping <i>snd</i> <i>cutoff</i>)</code> [LISP]<dd>Filter the loud regions of a signal where clipping is likely
to have generated additional high frequencies. The input signal is <i>snd</i>
and <i>cutoff</i> is the filter cutoff frequency
(4 kHz is recommended for speech).
</dl>
<p>
<a name = "190"><h3>Graphical Equalizer</h3></a>
There's nothing really "graphical" about this library (<code>grapheq.lsp</code>), but 
this is a common term for multi-band equalizers. This implementation uses
Nyquist's <code>eq-band</code> function to split the incoming signal into different
frequency bands. Bands are spaced geometrically, e.g. each band could be one
octave, meaning that each successive band has twice the bandwidth. An interesting
possibility is using computed control functions to make the equalization change
over time.
<p>
<dl>
<dt>
<code>nband-range(<a name="index1330"></a><a name="index1331"></a><a name="index1332"></a><i>input</i>, <i>gains</i>, <i>lowf</i>, <i>highf</i>)</code> [SAL]<br>

<code>(nband-range <i>input</i> <i>gains</i> <i>lowf</i> <i>highf</i>)</code> [LISP]<dd>A graphical equalizer applied to 
<i>input</i> (a <code>SOUND</code>). The gain controls and number of bands is given by <i>gains</i>, an
ARRAY of <code>SOUND</code>s (in other words, a Nyquist multichannel <code>SOUND</code>). Any sound in the
array may be replaced by a <code>FLONUM</code>. The bands are
geometrically equally spaced from the lowest frequency <i>lowf</i> to the
highest frequency <i>highf</i> (both are <code>FLONUM</code>s).<br><br>
<dt><code>nband(<a name="index1333"></a><i>input</i>, <i>gains</i>)</code> [SAL]<br>

<code>(nband <i>input</i> <i>gains</i>)</code> [LISP]<dd>A graphical equalizer, identical 
to <code>nband-range</code> with a range of 20 to 20,000 Hz.
</dl>
<p>
<a name = "191"><h3>Sound Reversal</h3></a>
The <code>reverse.lsp</code> library implements functions to play sounds in reverse.
<dl>
<dt>
<code>s-reverse(<a name="index1334"></a><a name="index1335"></a><a name="index1336"></a><a name="index1337"></a><i>snd</i>)</code> [SAL]<br>

<code>(s-reverse <i>snd</i>)</code> [LISP]<dd>Reverses <i>snd</i> (a <code>SOUND</code>). Sound must be shorter
than <code>*max-reverse-samples*</code>, which is currently initialized to 
25 million samples. Reversal allocates about 4 bytes per sample. This function
uses XLISP in the inner sample loop, so do not be surprised if it calls the 
garbage collector a lot and runs slowly. The result starts at the starting
time given by the current environment (not necessarily the starting time 
of <i>snd</i>). If <i>snd</i> has multiple channels, a multiple channel, 
reversed sound is returned.<br><br>
<dt><code>s-read-reverse(<a name="index1338"></a><a name="index1339"></a><i>filename</i>, time-offset: <i>offset</i>, srate: <i>sr</i>, dur: <i>dur</i>, nchans: <i>chans</i>, format: <i>format</i>, mode: <i>mode</i>, bits: <i>n</i>, swap: <i>flag</i>)</code> [SAL]<br>

<code>(s-read-reverse <i>filename</i> :time-offset <i>offset</i>
 :srate <i>sr</i> :dur <i>dur</i> :nchans <i>chans</i> :format <i>format</i> :mode <i>mode</i> 
:bits <i>n</i> :swap <i>flag</i>)</code> [LISP]<dd>This function is 
identical to <code>s-read</code> (see Section <a href = "part8.html#99">"Sound File Input and Output"</a>), except it reads 
the indicated samples in reverse. Like
<code>s-reverse</code> (see above), it uses XLISP in the inner loop, so it is slow.
Unlike <code>s-reverse</code>, <code>s-read-reverse</code> uses a fixed amount of 
memory that is independent of how many samples are computed. Multiple channels
are handled. 
</dl>
<p>
<a name = "192"><h3>Time Delay Functions</h3></a>
The <code>time-delay-fns.lsp</code> library implements chorus, phaser, and flange effects.
<p>
<dl>
<dt>
<code>phaser(<a name="index1340"></a><a name="index1341"></a><i>snd</i>)</code> [SAL]<br>

<code>(phaser <i>snd</i>)</code> [LISP]<dd>A phaser effect
applied to <i>snd</i> (a <code>SOUND</code>). There are no parameters, 
but feel free to modify the source code of this one-liner.<br><br>
<dt><code>flange(<a name="index1342"></a><a name="index1343"></a><a name="index1344"></a><i>snd</i>)</code> [SAL]<br>

<code>(flange <i>snd</i>)</code> [LISP]<dd>A flange effect
applied to <i>snd</i>. To vary the rate and other parameters, see the source code.<br><br>
<dt><code>stereo-chorus(<a name="index1345"></a><a name="index1346"></a><i>snd</i>, delay: <i>delay</i>, depth: <i>depth</i>, rate1: <i>rate1</i>, rate2: <i>rate2</i> saturation: <i>saturation</i>)</code> [SAL]<br>

<code>(stereo-chorus <i>snd</i> :delay <i>delay</i> :depth <i>depth</i>
:rate1 <i>rate1</i> :rate2 <i>rate2</i> :saturation <i>saturation</i>)</code> [LISP]<dd>A chorus effect 
applied to <i>snd</i>,
a <code>SOUND</code> (monophonic). The output is a stereo sound with out-of-phase chorus effects applied separately for the left and right channels. See the <code>chorus</code> function below for a description of the optional parameters. The <i>rate1</i> and <i>rate2</i> parameters are <i>rate</i> parameters for the left and right channels.<br><br>
<dt><code>chorus(<a name="index1347"></a><a name="index1348"></a><i>snd</i>, delay: <i>delay</i>, depth: <i>depth</i>, rate: <i>rate</i>, saturation: <i>saturation</i>, phase: <i>phase</i>)</code> [SAL]<br>

<code>(chorus <i>snd</i> :delay <i>delay</i> :depth <i>depth</i> :rate <i>rate</i> :saturation <i>saturation</i> :phase <i>phase</i>)</code> [LISP]<dd>A chorus effect applied to <i>snd</i>. All parameters may be arrays
as usual. The chorus is implemented as a variable delay 
modulated by a sinusoid shifted by <i>phase</i> degrees (a <code>FLONUM</code>) oscillating
at <i>rate</i> Hz (a <code>FLONUM</code>). The sinusoid is 
scaled by <i>depth</i> (a <code>FLONUM</code>. The delayed signal is mixed
with the original, and <i>saturation</i> (a <code>FLONUM</code>) gives the fraction of 
the delayed signal
(from 0 to 1) in the mix. 
Default values are <i>delay</i> 0.03, <i>depth</i> 0.003, <i>rate</i> 0.3, 
 <i>saturation</i> 1.0, and <i>phase</i> 0.0 (degrees).
</dl>
<p>
<a name = "193"><h3>Multiple Band Effects</h3></a>
<a name="index1349"></a><a name="index1350"></a>
The <code>bandfx.lsp</code> library implements several effects based on multiple
frequency bands. The idea is to separate a signal into different frequency
bands, apply a slightly different effect to each band, and sum the effected
bands back together to form the result. This file includes its own set of
examples. After loading the file, try <code>f2()</code>, <code>f3()</code>, <code>f4()</code>,
and <code>f5()</code> to hear them.
Further discussion and examples can be found in 
<code>demos/bandfx.htm</code><a name="index1351"></a>. 
<p>
There is much room for expansion and experimentation with this library. Other
effects might include distortion in certain bands (for example, there are
commercial effects that add distortion to low frequencies to enhance the sound
of the bass), separating bands into different channels for stereo or multi-channel
effects, adding frequency-dependent reverb, and performing dynamic compression, 
limiting, or noise gate functions on each band. There are also opportunities for
cross-synthesis: using the content of bands extracted from one signal to modify
the bands of another. The simplest of these would be to apply amplitude envelopes
of one sound to another. Please contact us (dannenberg@cs.cmu.edu) if you 
are interested in working on this library.
<p>
<dl>
<dt>
<code>apply-banded-delay(<a name="index1352"></a><a name="index1353"></a><i>s</i>, <i>lowp</i>, <i>highp</i>, <i>num-bands</i>, <i>lowd</i>, <i>highd</i>, <i>fb</i>, <i>wet</i>)</code> [SAL]<br>

<code>(apply-banded-delay <i>s</i> <i>lowp</i> <i>highp</i> <i>num-bands</i> <i>lowd</i> <i>highd</i> <i>fb</i> <i>wet</i>)</code> [LISP]<dd>Separates
input <code>SOUND</code> <i>s</i> into <code>FIXNUM</code> <i>num-bands</i> bands from a low frequency
of <i>lowp</i> to a high frequency of <i>highp</i> (these are <code>FLONUMS</code> that specify
steps, not Hz), and applies a delay to each band. The delay for the lowest band is
given by the <code>FLONUM</code> <i>lowd</i> (in seconds) and the delay for the highest band
is given by the <code>FLONUM</code> <i>highd</i>. The delays for other bands are linearly
interpolated between these values. Each delay has feedback gain controlled by
<code>FLONUM</code> <i>fb</i>. The delayed bands are scaled by <code>FLONUM</code> <i>wet</i>, and 
the original sound is scaled by 1 - <i>wet</i>. All are summed to form the result, 
a <code>SOUND</code>.<br><br>
<dt><code>apply-banded-bass-boost(<a name="index1354"></a><a name="index1355"></a><i>s</i>, <i>lowp</i>, <i>highp</i>, <i>num-bands</i>, <i>num-boost</i>, <i>gain</i>)</code> [SAL]<br>

<code>(apply-banded-bass-boost <i>s</i> <i>lowp</i> <i>highp</i> <i>num-bands</i> <i>num-boost</i> <i>gain</i>)</code> [LISP]<dd>Applies a boost to 
low frequencies. Separates
input <code>SOUND</code> <i>s</i> into <code>FIXNUM</code> <i>num-bands</i> bands from a low frequency
of <i>lowp</i> to a high frequency of <i>highp</i> (these are <code>FLONUMS</code> that specify
steps, not Hz), and scales the lowest <i>num-boost</i> (a <code>FIXNUM</code>) bands by <i>gain</i>,
a <code>FLONUM</code>. The bands are summed to form the result, a <code>SOUND</code>.<br><br>
<dt><code>apply-banded-treble-boost(<a name="index1356"></a><a name="index1357"></a><i>s</i>, <i>lowp</i>, <i>highp</i>, <i>num-bands</i>, <i>num-boost</i>, <i>gain</i>)</code> [SAL]<br>

<code>(apply-banded-treble-boost <i>s</i> <i>lowp</i> <i>highp</i> <i>num-bands</i> <i>num-boost</i> <i>gain</i>)</code> [LISP]<dd>Applies a boost to 
high frequencies. Separates
input <code>SOUND</code> <i>s</i> into <code>FIXNUM</code> <i>num-bands</i> bands from a low frequency
of <i>lowp</i> to a high frequency of <i>highp</i> (these are <code>FLONUMS</code> that specify
steps, not Hz), and scales the highest <i>num-boost</i> (a <code>FIXNUM</code>) bands by <i>gain</i>,
a <code>FLONUM</code>. The bands are summed to form the result, a <code>SOUND</code>.
</dl>
<p>
<a name = "194"><h3>Granular Synthesis</h3></a>
Some granular synthesis functions are implemented in the <code>gran.lsp</code> library
file. There are many variations and control schemes one could adopt for granular
synthesis, so it is impossible to create a single universal granular synthesis
function. One of the advantages of Nyquist is the integration of control and
synthesis functions, and users are encouraged to build their own granular synthesis
functions incorporating their own control schemes. The <code>gran.lsp</code> file
includes many comments and is intended to be a useful starting point. Another 
possibility is to construct a score with an event for each grain. Estimate a
few hundred bytes per score event (obviously, size depends on the number of
parameters) and avoid using all of your computer's memory.
<p>
<dl>
<dt>
<code>sf-granulate(<a name="index1358"></a><a name="index1359"></a><i>filename</i>, <i>grain-dur</i>, <i>grain-dev</i>, <i>ioi</i>, <i>ioi-dev</i>, <i>pitch-dev</i>, [<i>file-start</i>, <i>file-end</i>])</code> [SAL]<br>

<code>(sf-granulate <i>filename</i> <i>grain-dur</i> <i>grain-dev</i> <i>ioi</i>
 <i>ioi-dev</i> <i>pitch-dev</i> [<i>file-start</i> <i>file-end</i>])</code> [LISP]<dd>Granular synthesis 
using a sound file
named <i>filename</i> as the source for grains. Grains are extracted from
a sound file named by <i>filename</i> by stepping through the file in equal
increments. Each grain duration is the 
sum of <i>grain-dur</i> and a random number from 0 to <i>grain-dev</i>. Grains are 
then multiplied by a raised cosine smoothing window and resampled at a ratio
between 1.0 and <i>pitch-dev</i>. If <i>pitch-dev</i> is greater than one, grains are
stretched and the pitch (if any) goes down. If <i>pitch-dev</i> is less than one,
grains are shortened and the pitch goes up. Grains are then output
with an 
inter-onset interval between successive grains (which may overlap) 
determined by the sum of
<i>ioi</i> and a random number from 0 to <i>ioi-dev</i>. 
The duration of the resulting sound is determined by
the stretch factor (not by the sound file). The number of grains is
the total sound duration (determined by the stretch factor)
divided by the mean inter-onset interval, 
which is <i>ioi</i> + <i>ioi-dev</i> * 0.5. 
The grains are taken from equally-spaced starting points in <i>filename</i>,
and depending on grain size and number, the grains may or may not overlap.
The output duration will simply be the sum of the inter-onset intervals
and the duration of the last grain. If <i>ioi-dev</i> is non-zero, the
output duration will vary, but the expected value of the duration is
the stretch factor.
To achieve a rich granular synthesis effect, it is often a good idea to
sum four or more copies of <code>sf-granulate</code> together. (See the <code>gran-test</code>
function in <code>gran.lsp</code>.)
</dl>
<p>
<a name = "195"><h3>Chowning FM Voices</h3></a>
John Chowning developed voice synthesis methods using FM to simulate 
resonances for his 1981 composition "Phone." He later recreated the
synthesis algorithms in Max, and Jorge Sastre ported these to SAL. 
See <code>demos/FM-voices-Chowning.sal</code> for more details.
<p>
<a name = "196"><h3>Atonal Melody Composition</h3></a>
Jorge Sastre contributed <code>demos/atonal-melodies.sal</code>, code 
that generates atonal melodies. You can find links to an example
score and audio file in the code and also at
<code>http://algocompbook.com/examples.html</code>.
<p>
<a name = "197"><h3>MIDI Utilities</h3></a>
The <code>midishow.lsp</code> library has functions that can print the contents fo MIDI
files. This intended as a debugging aid.
<p>
<dl>
<dt>
<code>midi-show-file(<a name="index1360"></a><a name="index1361"></a><a name="index1362"></a><i>file-name</i>)</code> [SAL]<br>

<code>(midi-show-file <i>file-name</i>)</code> [LISP]<dd>Print the contents of a MIDI file to the console.<br><br>
<dt><code>midi-show(<a name="index1363"></a><i>the-seq</i> [, <i>out-file</i>])</code> [SAL]<br>

<code>(midi-show <i>the-seq</i> [<i>out-file</i>])</code> [LISP]<dd>Print the
contents of the sequence <i>the-seq</i> to the file <i>out-file</i> (whose default value
is the console.)
</dl>
<p>
<a name = "198"><h3>Reverberation</h3></a>
The <code>reverb.lsp</code> library implements artificial reverberation.
<p>
<dl>
<dt>
<code>reverb(<a name="index1364"></a><a name="index1365"></a><i>snd</i>, 
<i>time</i>)</code> [SAL]<br>

<code>(reverb <i>snd</i> <i>time</i>)</code> [LISP]<dd>Artificial reverberation applied to <i>snd</i> with a decay time of
<i>time</i>.
</dl>
<p>
<a name = "199"><h3>DTMF Encoding</h3></a>
<a name="index1366"></a><a name="index1367"></a>
The <code>dtmf.lsp</code> library implements DTMF encoding. DTMF is the 
"touch tone" code used by telephones.
<p>
<dl>
<dt>
<code>dtmf-tone(<a name="index1368"></a><i>key</i>, <i>len</i>, <i>space</i>)</code> [SAL]<br>

<code>(dtmf-tone <i>key</i> <i>len</i> <i>space</i>)</code> [LISP]<dd>Generate a
single DTMF tone. The <i>key</i> parameter is either a digit (a <code>FIXNUM</code>
from 0 through 9) or the atom <code>STAR</code> or <code>POUND</code>. The duration of
the done is given by <i>len</i> (a <code>FLONUM</code>) and the tone is followed by
silence of duration <i>space</i> (a <code>FLONUM</code>).<br><br>
<dt><code>speed-dial(<a name="index1369"></a><i>thelist</i>)</code> [SAL]<br>

<code>(speed-dial <i>thelist</i>)</code> [LISP]<dd>Generates a sequence
of DTMF tones using the keys in <i>thelist</i> (a <code>LIST</code> of keys as
described above under <code>dtmf-tone</code>). The duration of each tone is 0.2
seconds, and the space between tones is 0.1 second. Use <code>stretch</code> to
change the "dialing" speed.
</dl>
<p>
<a name = "200"><h3>Dolby Surround(R), Stereo and Spatialization Effects</h3></a>
<a name="index1370"></a><a name="index1371"></a><a name="index1372"></a><a name="index1373"></a>
<p>
The <code>spatial.lsp</code> library implements various functions for stereo
manipulation and spatialization. It also includes some functions for
Dolby Pro-Logic panning, which encodes left, right, center, and surround 
channels into stereo. The stereo signal can then be played through
a Dolby decoder to drive a surround speaker array. This library has
a somewhat simplified encoder, so you should certainly test the
output. Consider using a high-end encoder for critical work. There
are a number of functions in <code>spatial.lsp</code> for testing. See the
source code for comments about these.
<p>
<dl>
<dt>
<code>stereoize(<a name="index1374"></a><a name="index1375"></a><a name="index1376"></a><i>snd</i>)</code> [SAL]<br>

<code>(stereoize <i>snd</i>)</code> [LISP]<dd>Convert a mono sound, <i>snd</i>, to stereo. Four bands of 
equalization and some delay are used to create a stereo effect.<br><br>
<dt><code>widen(<a name="index1377"></a><a name="index1378"></a><i>snd</i>, <i>amt</i>)</code> [SAL]<br>

<code>(widen <i>snd</i> <i>amt</i>)</code> [LISP]<dd>Artificially
widen the stereo field in <i>snd</i>, a two-channel sound. The amount of widening
is <i>amt</i>, which varies from 0 (<i>snd</i> is unchanged) to 1 (maximum widening).
The <i>amt</i> can be a <code>SOUND</code> or a number.<br><br>
<dt><code>span(<a name="index1379"></a><a name="index1380"></a><a name="index1381"></a><a name="index1382"></a><i>snd</i>, <i>amt</i>)</code> [SAL]<br>

<code>(span <i>snd</i> <i>amt</i>)</code> [LISP]<dd>Pan the virtual center channel of a stereo sound, <i>snd</i>,
by <i>amt</i>, where 0 pans all the way to the left, while 1 pans all the way 
to the right. The <i>amt</i> can be a <code>SOUND</code> or a number.<br><br>
<dt><code>swapchannels(<a name="index1383"></a><a name="index1384"></a><a name="index1385"></a><i>snd</i>)</code> [SAL]<br>

<code>(swapchannels <i>snd</i>)</code> [LISP]<dd>Swap left and right channels in <i>snd</i>, a stereo sound.<br><br>
<dt><code>prologic(<a name="index1386"></a><a name="index1387"></a><a name="index1388"></a><i>l</i>, <i>c</i>, 
<i>r</i>, <i>s</i>)</code> [SAL]<br>

<code>(prologic <i>l</i> <i>c</i> <i>r</i> <i>s</i>)</code> [LISP]<dd>Encode four monaural <code>SOUND</code>s representing the front-left,
front-center, front-right, and rear channels, respectively. 
The return value is a stereo sound, which is a Dolby-encoded mix of the
four input sounds. <br><br>
<dt><code>pl-left(<a name="index1389"></a><i>snd</i>)</code> [SAL]<br>

<code>(pl-left <i>snd</i>)</code> [LISP]<dd>Produce a Dolby-encoded (stereo)
signal with <i>snd</i>, a <code>SOUND</code>, encoded as the front left channel.<br><br>
<dt><code>pl-center(<a name="index1390"></a><i>snd</i>)</code> [SAL]<br>

<code>(pl-center <i>snd</i>)</code> [LISP]<dd>Produce a Dolby-encoded (stereo)
signal with <i>snd</i>, a <code>SOUND</code>, encoded as the front center channel.<br><br>
<dt><code>pl-right(<a name="index1391"></a><i>snd</i>)</code> [SAL]<br>

<code>(pl-right <i>snd</i>)</code> [LISP]<dd>Produce a Dolby-encoded (stereo)
signal with <i>snd</i>, a <code>SOUND</code>, encoded as the front right channel.<br><br>
<dt><code>pl-rear(<a name="index1392"></a><i>snd</i>)</code> [SAL]<br>

<code>(pl-rear <i>snd</i>)</code> [LISP]<dd>Produce a Dolby-encoded (stereo)
signal with <i>snd</i>, a <code>SOUND</code>, encoded as the rear, or surround, channel.<br><br>
<dt><code>pl-pan2d(<a name="index1393"></a><i>snd</i>, <i>x</i>, <i>y</i>)</code> [SAL]<br>

<code>(pl-pan2d <i>snd</i> <i>x</i> <i>y</i>)</code> [LISP]<dd>Comparable to Nyquist's
existing pan function, <code>pl-pan2d</code> provides not only left-to-right
panning, but front-to-back panning as well. The function
accepts three parameters: <i>snd</i> is the (monophonic) input <code>SOUND</code>, 
<i>x</i> is a left-to-right position, and <i>y</i> is a front-to-back position.
Both position parameters may be numbers or <code>SOUND</code>s. An <i>x</i> value 
of 0 means left, and 1 means right. Intermediate values map linearly
between these extremes. Similarly, a <i>y</i> value of 0 causes the sound
to play entirely through the front speakers(s), while 1 causes it to play
entirely through the rear. Intermediate values map linearly.
Note that, although there are usually two rear speakers in Pro-Logic systems,
they are both driven by the same signal. Therefore any sound that is
panned totally to the rear will be played over both rear speakers. For
example, it is not possible to play a sound exclusively through the 
rear left speaker.<br><br>
<dt><code>pl-position(<a name="index1394"></a><i>snd</i>, <i>x</i>, <i>y</i>, <i>config</i>)</code> [SAL]<br>

<code>(pl-position <i>snd</i> <i>x</i> <i>y</i> <i>config</i>)</code> [LISP]<dd>The
position function builds upon speaker panning to allow more abstract
placement of sounds. Like <code>pl-pan2d</code>, it accepts a (monaural) input
sound as well as left-to-right (<i>x</i>) and front-to-back (<i>y</i>) coordinates,
which may be <code>FLONUM</code>s or <code>SOUND</code>s. A fourth parameter <i>config</i> 
specifies the distance from listeners to the speakers (in meters). Current
settings assume this to be constant for all speakers, but this assumption 
can be changed easily (see comments in the code for more detail).
There are several important differences between <code>pl-position</code> and 
<code>pl-pan2d</code>. First, <code>pl-position</code> uses a Cartesian coordinate 
system that allows x and y coordinates outside of the
range (0, 1). This model assumes a listener position of (0,0). Each speaker
has a predefined position as well. The input sound's position,
relative to the listener, is given by the vector (<i>x</i>,<i>y</i>).<br><br>
<dt><code>pl-doppler(<a name="index1395"></a><a name="index1396"></a><i>snd</i>, 
<i>r</i>)</code> [SAL]<br>

<code>(pl-doppler <i>snd</i> <i>r</i>)</code> [LISP]<dd>Pitch-shift moving sounds according to the equation: <i>fr</i> =
<i>f0</i>((<i>c</i>+<i>vr</i>)/<i>c</i>), where <i>fr</i> is the output frequency, 
<i>f0</i> is the emitted (source) 
frequency, <i>c</i> is the speed of sound (assumed to be 344.31 m/s), and 
<i>vr</i> is the speed at which the emitter approaches the receiver. (<i>vr</i>
is the first derivative of parameter <i>r</i>, the distance from the listener
in meters.
</dl>
<p>
<a name = "201"><h3>Drum Machine</h3></a>
<a name="index1397"></a>
<p>
The drum machine software in <code>demos/plight</code> deserves further explanation. 
to use the software, load the code by evaluating:
<p><pre>
load "../demos/plight/drum.lsp"
exec load-props-file(strcat(*plight-drum-path*, 
                            "beats.props"))
exec create-drum-patches()
exec create-patterns()
</pre></p>

<p>
Drum sounds and patterns are specified in the <code>beats.props</code> file (or
whatever name you give to <code>load-props-file</code>). This file
contains two types of specifications. First, there are sound file specifications.
Sound files are located by a line of the form:
<p><pre>
set sound-directory = "kit/"
</pre></p>

This gives the name of the sound file directory, relative to the 
 <code>beats.props</code> file. Then, for each sound file, there should be a line of
the form:
<p><pre>
track.2.5 = big-tom-5.wav
</pre></p>

This says that on track 2, a velocity value of 5 means to play the sound file
 <code>big-tom-5.wav</code>. (Tracks and velocity values are described below.) 
The <code>beats.props</code> file contains specifications for all the sound files
in <code>demos/plight/kit</code> using 8 tracks. If you make your own specifications
file, tracks should be numbered consecutively from 1, and velocities should be
in the range of 1 to 9.
<p>
The second set of specifications is of beat patterns. A beat pattern is given
by a line in the following form:
<p><pre>
beats.5 = 2--32--43-4-5---
</pre></p>

The number after <code>beats</code> is just a pattern number. Each pattern
is given a unique number. After the equal sign, the digits and dashes are
velocity values where a dash means "no sound." Beat patterns should be
numbered consecutively from 1.
<p>
Once data is loaded, there are several functions to access drum patterns and 
create drum sounds (described below). The <code>demos/plight/drums.lsp</code> file
contains an example function <code>plight-drum-example</code> to play some drums.
There is also the file <code>demos/plight/beats.props</code> to serve as an
example of how to specify sound files and beat patterns.
<p>
<dl>
<dt>
<code>drum(<a name="index1398"></a><i>tracknum</i>, <i>patternnum</i>, <i>bpm</i>)</code> [SAL]<br>

<code>(drum <i>tracknum</i> <i>patternnum</i> <i>bpm</i>)</code> [LISP]<dd>Create
a sound by playing drums sounds associated with track <i>tracknum</i> (a 
FIXNUM) using pattern <i>patternnum</i>. The tempo is given by <i>bpm</i> in
beats per minute. Normally patterns are a sequence of sixteenth notes, so
the tempo is in <i>sixteenth notes per minute</i>. For example,
if <i>patternnum</i> is 10,
then use the pattern specified for <code>beats.10</code>. If the third character
of this pattern is 3 and <i>tracknum</i> is 5, then on the third beat, play
the soundfile assigned to <code>track.5.3</code>. This function returns a <code>SOUND</code>.<br><br>
<dt><code>drum-loop(<a name="index1399"></a><i>snd</i>, <i>duration</i>, <i>numtimes</i>)</code> [SAL]<br>

<code>(drum-loop <i>snd</i> <i>duration</i> <i>numtimes</i>)</code> [LISP]<dd>Repeat the sound given by <i>snd</i> <i>numtimes</i> times. The repetitions occur at a time offset of <i>duration</i>, regardless of the actual duration of <i>snd</i>. A <code>SOUND</code> is returned.<br><br>
<dt><code>length-of-beat(<a name="index1400"></a><i>bpm</i>)</code> [SAL]<br>

<code>(length-of-beat <i>bpm</i>)</code> [LISP]<dd>Given a tempo of 
<i>bpm</i>, return the duration of the beat in seconds. Note that this software
has no real notion of beat. A "beat" is just the duration of each character
in the beat pattern strings. This function returns a <code>FLONUM</code>.
</dl>
<p>
<a name = "202"><h3>Minimoog-inspired Synthesis</h3></a>
<a name="index1401"></a><a name="index1402"></a><a name="index1403"></a>
<p>
The <code>moog.lsp</code> library gives the Nyquist user easy access to "classic"
synthesizer sounds through an emulation of the Minimoog Synthesizer.
Unlike modular Moogs that were very large, the Minimoog was the first
successful and commonly used portable synthesizer. The trademark filter attack
was unique and easily recognizable. The goal of this Nyquist instrument is not
only to provide the user with default sounds, but also to give control over
many of the "knobs" found on the Minimoog. In this implementation, these
parameters are controlled using keywords. The input to the <code>moog</code> 
instrument is a user-defined sequence of notes, durations, and articulations
that simulate notes played on a keyboard. These are translated into 
control voltages that drive multiple oscillators, similar to the Voltage
Controlled Oscillator or VCO found in the original analog Moog.
<p>
The basic functionality of the Minimoog has been implemented, including the
often-used "glide". The glide feature essentially low-pass filters the control
voltage sequence in order to create sweeps between notes. 
Figure <a href = "#202">21</a> is a simplified schematic of the data flow in the Moog. 
The control lines have been omitted.
<p>
<hr>
<blockquote>
</blockquote>
<img src="moog-fig.gif" width=558><br><br>

<p>
<b>Figure 21: </b>System diagram for Minimoog emulator.

<hr>
<p>
The most recognizable feature of the Minimoog is its resonant filter, a 
Four-Pole Ladder Filter invented by Robert Moog. It is simply implemented 
in a circuit with four transistors and provides an outstanding 24 dB/octave 
rolloff. It is modeled here using the built-in Nyquist resonant filter. 
One of the Moog filter features is a constant Q, or center frequency to 
bandwidth ratio. This is implemented and the user can control the Q. 
<p>
The user can control many parameters using keywords. Their default values,
acceptable ranges, and descriptions are shown below. The defaults were
obtained by experimenting with the official Minimoog software synthesizer
by Arturia.
<p>
<a name = "203"><h4>Oscillator Parameters</h4></a>
<p><pre>
range-osc1(2)
range-osc2(1)
range-osc3(3)
</pre></p>

These parameters control the octave of each oscillator. A value of 1
corresponds to the octave indicated by the input note. A value of 3
is two octaves above the fundamental. The allowable range is 1 to 7.
<p>
<p><pre>
detun2(-.035861)
detun3(.0768)
</pre></p>

Detuning of two oscillators adds depth to the sound. A value of 1 corresponds
to an increase of a single semitone and a -1 corresponds to a decrease
in a semitone. The range is -1 to 1.
<p>
<p><pre>
shape-osc1(*saw-table*)
shape-osc2(*saw-table*)
shape-osc3(*saw-table*)
</pre></p>

Oscilators can use any wave shape. The default sawtooth waveform is
a built-in Nyquist variable. Other waveforms can be defined by the user.
<p>
<p><pre>
volume-osc1(1)
volume-osc2(1)
volume-osc3(1)
</pre></p>

These parameters control the relative volume of each oscillator. The range
is any <code>FLONUM</code> greater than or equal to zero.
<p>
<a name = "204"><h4>Noise Parameters</h4></a>
<p><pre>
noiselevel(.05)
</pre></p>

This parameter controls the relative volume of the noise source. The range
is any <code>FLONUM</code> greater than or equal to zero.
	
<a name = "205"><h4>Filter Parameters</h4></a>
<p><pre>
filter-cutoff(768)
</pre></p>

The cutoff frequency of the filter in given in Hz. The range is zero
to 20,000 Hz.
<p>
<p><pre>
Q(2)
</pre></p>

Q is the ratio of center frequency to bandwidth. It is held constant by
making the bandwidth a function of frequency. The range is any
<code>FLONUM</code> greater than zero.
<p>
<p><pre>
contour(.65)
</pre></p>

Contour controls the range of the transient frequency sweep from a high
to low cutoff frequency when a 	note is played. The high frequency is
proportional to contour. A contour of 0 removes this sweep. The range
is 0 to 1.
<p>
<p><pre>
filter-attack(.0001)
</pre></p>

Filter attack controls the attack time of the filter, i.e. the time to
reach the high cutoff frequency. The range is any <code>FLONUM</code> greater
than zero (seconds).
<p>
<p><pre>
filter-decay(.5)
</pre></p>

Filter decay controls the decay time of the filter, i.e. the time of the
sweep from the high to low cutoff frequency. The range is 
any <code>FLONUM</code> greater than zero (seconds).
<p>
<p><pre>
filter-sustain(.8)
</pre></p>

Filter sustain controls the percentage of the filter cutoff frequency that
the filter settles on following the sweep. The range is 0 to 1.
	
<a name = "206"><h4>Amplitude Parameters</h4></a>
<p><pre>
amp-attack(.01)
</pre></p>

This parameter controls the amplitude envelope attack time, i.e. the time to
reach maximum amplitude. The range is 
any <code>FLONUM</code> greater than zero (seconds).
<p>
<p><pre>
amp-decay(1)
</pre></p>

This parameter controls the amplitude envelope decay time, i.e. the time
between the maximum and sustain volumes. The range is
any <code>FLONUM</code> greater than zero (seconds).
<p>
<p><pre>
amp-sustain(1)
</pre></p>

This parameter controls the amplitude envelope sustain volume, a fraction
of the maximum. The range is 0 to 1.
<p>
<p><pre>
amp-release(0)
</pre></p>

This parameter controls the amplitude envelope release time, i.e. the time
it takes between the sustain volume and 0 once the note ends. 
The duration controls the overall length of the sound. The range of <code>amp-release</code> is any <code>FLONUM</code> greater than zero (seconds).
<p>
<a name = "207"><h4>Other Parameters</h4></a>
<p><pre>
glide(0)
</pre></p>

Glide controls the low-pass filter on the control voltages. This models the
glide knob on a Minimoog. A higher value corresponds to a lower cutoff
frequency and hence a longer "glide" between notes. A value of 0
corresponds to no glide. The range is zero to 10.
<p>
<a name = "208"><h4>Input Format</h4></a>
A single note or a series of notes can be input to the Moog instrument
by defining a list with the following format:
<p><pre>
list(list(<i>frequency</i>, <i>duration</i>, <i>articulation</i>), <span style="font-style:normal">...</span> )
</pre></p>

where <i>frequency</i> is a <code>FLONUM</code> in steps, <i>duration</i> is the duration
of each note in seconds (regardless of the release time of the amplifier), 
and <i>articulation</i> is a percentage of the duration that a sound will be
played, representing the amount of time that a key is pressed. The filter 
and amplitude envelopes are only triggered if a note is played when
the articulation of the previous note is less than 1, or a key is not down at
the same time. This Moog instrument is a monophonic instrument, so only
one note can sound at a time. The release section of the amplifier is
triggered when the articulation is less than 1 at the time 
(<i>duration</i> * <i>articulation</i>).
<p>
<a name = "209"><h4>Sample Code/Sounds</h4></a>
<p>
<b>Sound 1 (default parameters):</b>
<p><pre>
set s = {{24 .5 .99} {26 .5 .99} {28 .5 .99} 
         {29 .5 .99} {31 2 1}}
play moog(s)
</pre></p>

<p>
<b>Sound 2 (articulation, with amplitude release):</b>
<p><pre>
set s = {{24 .5 .5} {26 .5 1} {28 .5 .25} {29 .5 1} {31 1 .8}}
play moog(s, amp-release: .2)
</pre></p>

<p>
<b>Sound 3 (glide):</b>
<p><pre>
set s = {{24 .5 .5} {38 .5 1} {40 .5 .25}
         {53 .5 1} {55 2 1} {31 2 .8} {36 2 .8}}
play moog(s, amp-release: .2, glide: .5)
</pre></p>

<p>
<b>Sound 4 (keyword parameters):</b> Filter attack and decay are purposely
longer than notes being played with articulation equal to 1.
<p><pre>
set s = {{20 .5 1} {27 .5 1} {26 .5 1} {21 .5 1}
         {20 .5 1} {27 .5 1} {26 .5 1} {21 .5 1}}
play moog(s, shape-osc1: *tri-table*, shape-osc2: *tri-table*,
             filter-attack: 2, filter-decay: 2,
             filter-cutoff: 300, contour: .8, glide: .2, Q: 8)
</pre></p>

<p>
<b>Sound 5:</b> This example illustrates the ability to completely define a new 
synthesizer with different parameters creating a drastically different
sound. Sine waves are used for wavetables. There is a high value for glide.
<p><pre>
define function my-moog(freq) 
  return moog(freq,
    range-osc1: 3, range-osc2: 2, range-osc3: 4,
    detun2: -.043155, detun3: .015016,
    noiselevel: 0,
    filter-cutoff: 400, Q: .1, contour: .0000001,
    filter-attack: 0, filter-decay: .01, filter-sustain: 1,
    shape-osc1: *sine-table*, shape-osc2: *sine-table*,
    shape-osc3: *sine-table*, volume-osc1: 1, volume-osc2: 1,
    volume-osc3: .1, amp-attack: .1, amp-decay: 0,
    amp-sustain: 1, amp-release: .3, glide: 2)

set s = {{80 .4 .75} {28 .2 1} {70 .5 1} {38 1 .5}}
play my-moog(s)
</pre></p>

<p>
<b>Sound 6:</b> This example has another variation on the default
 parameters.
<p><pre>
set s = {{24 .5 .99} {26 .5 .99} {28 .5 .99} 
         {29 .5 .99} {31 2 1}}
play moog(s, shape-osc1: *tri-table*, shape-osc2: *tri-table*,
             filter-attack: .5, contour: .5)
</pre></p>

<p>


<p>

<p>

<p>

<p>

<p>


<hr>
<a href = "part15.html">Previous Section</a> | <a href = "part17.html">Next Section</a> | <a href = "title.html#toc">Table of Contents</a> | <a href = "indx.html">Index</a> | <a href = "title.html">Title Page</a>
</body></html>