Debian Codegraph @

doc/part16.html

raw
1 <!DOCTYPE html>
2 <html><head><title>Nyquist Libraries</title>
3 <link rel="stylesheet" type="text/css" href="nyquiststyle.css">
4 <link rel="icon" href="nyquist-icon.png" />
5 <link rel="shortcut icon" href="nyquist-icon.png" />
6 </head>
7 <body bgcolor="ffffff">
8 <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>
9 <hr>
10 <a name = "185"><h2>Nyquist Libraries</h2></a><a name="index1335"></a>
11 <p>Nyquist is always growing with new functions. Functions that are most fundamental
12 are added to the core language. These functions are automatically loaded when you
13 start Nyquist, and they are documented in the preceding chapters. Other functions seem
14 less central and are implemented as lisp files that you can load. Many
15 of these functions and files are not included in the main distribution of
16 Nyquist. Instead, they are extensions (see Section <a href = "part3.html#22">Extension Manager</a>).
17 Extensions
18 are just like any other library except you must first install them with
19 the Extension Manager in the NyquistIDE, and each extension is in a separate
20 folder within the <code>lib</code> folder.</p>
21
22 <p>For example, to get statistics functions, <code>load "statistics"</code>, but to get
23 the phase vocoder test functions, first install the <code>pvoc</code> extension,
24 and then <code>load "pvoc/phasevocoder.sal"</code>. In many cases, functions within
25 an extension will &ldquo;autoload,&rdquo; e.g. after you install the <code>labels</code>
26 extension, the first time you call <code>read-labels</code> or <code>write-labels</code>,
27 <code>labels.sal</code> will be loaded automatically to define these functions, as
28 if the function had been loaded all along. Extensions also update the
29 function call quick reference and completion feature in the NyquistIDE.</p>
30
31 <p>Many libraries are documented in one of the following
32 sections, but see the Extension Manager for possible new additions. Extensions
33 have documentation, which you can find using the Extension Manager.</p>
34 <a name = "186"><h3>Statistics</h3></a><a name="index1336"></a><a name="index1337"></a><a name="index1338"></a><a name="index1339"></a><a name="index1340"></a><a name="index1341"></a><a name="index1342"></a><a name="index1343"></a><a name="index1344"></a><a name="index1345"></a><a name="index1346"></a><a name="index1347"></a><a name="index1348"></a><a name="index1349"></a>
35 <p>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>
36 <a name = "187"><h3>Plots</h3></a><a name="index1350"></a><a name="index1351"></a>
37 <p>The Nyquist IDE has a simple facility to plot signals. For more advanced plotting, you can use <code>gnuplot.sal</code> (<code>load "gnuplot.sal"</code>) to generate plots for <code>gnuplot</code>, a separate, but free program. See the source for details.</p>
38 <a name = "188"><h3>Labeling Audio Events, Marking Audio Times, Displaying Marked Audio Times</h3></a><a name="index1352"></a><a name="index1353"></a><a name="index1354"></a><a name="index1355"></a>
39 <p>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>
40 <a name = "189"><h3>Linear Regression</h3></a><a name="index1356"></a><a name="index1357"></a><a name="index1358"></a>
41 <p>See the <code>regression</code> extension and its <code>regression.sal</code> for
42 simple linear regression functions.</p>
43 <a name = "190"><h3>Vector Math, Linear Algebra</h3></a><a name="index1359"></a><a name="index1360"></a><a name="index1361"></a><a name="index1362"></a><a name="index1363"></a><a name="index1364"></a><a name="index1365"></a><a name="index1366"></a><a name="index1367"></a><a name="index1368"></a><a name="index1369"></a><a name="index1370"></a><a name="index1371"></a><a name="index1372"></a>
44 <p>See <code>vectors.lsp</code> and <code>load "vectors"</code>
45 for a simple implementation of vector arithmetic and other vector functions.
46 These &ldquo;vectors&rdquo; are implemented as lists, but there are functions to convert
47 to and from arrays.</p>
48 <a name = "191"><h3>JSON Input and Output</h3></a>
49 <p>JSON<a name="index1373"></a> is widely used in web technology, scientific
50 computing and many other areas. See <code>json.sal</code> and <code>load "json"</code> for a
51 simple implementation of JSON input and output. On input, JSON dictionaries
52 are represented as association lists and JSON arrays are represented as XLisp
53 arrays. Data can be retrieved from dictionaries using <code>json-field</code>. If
54 you are writing in Lisp, note that you can call <code>(sal-load "json")</code> to
55 load and compile <code>json.sal</code> so that you can call its functions from Lisp.</p>
56
57 <p>For output, you can either write a structure consisting of nested arrays
58 and dictionaries (association lists), or you can call a sequence of functions
59 to, for example, begin writing an array, write each element of the array and
60 finish writing the array. This way, you can write JSON as the data is computed
61 rather than building a monolithic structure in Lisp and then writing it.</p>
62
63 <p>Note that Lisp is already able to read and write
64 structured data, and if everyone used Lisp and SAL, there might not be any
65 need for JSON. Nyquist scores are an example of data you can save to files in
66 a text format and read back in. So JSON is not recommended except for
67 interoperation with other non-Lisp systems.</p>
68 <a name = "192"><h3>Piano Synthesizer</h3></a>
69 <p>The piano synthesizer (library name is <code>pianosyn.lsp</code>) generates
70 realistic piano tones using a multiple wavetable implementation by Zheng (Geoffrey)
71 Hua and Jim Beauchamp, University of Illinois. Detailed
72 acknowledgements print when you load the file. Further information and
73 example code can be found in
74 <code>nyquist/lib/piano/piano.htm</code><a name="index1374"></a><a name="index1375"></a>.
75 There are several useful functions in this library. These functions auto-load the
76 <code>pianoysn.lsp</code> file if it is not already loaded:
77 <dl>
78 <dt>
79 <code>piano-note(<a name="index1376"></a><a name="index1377"></a><i>duration</i>, <i>step</i>,
80 <i>dynamic</i>)</code> [SAL]<br>
81
82 <code>(piano-note <i>duration</i> <i>step</i> <i>dynamic</i>)</code> [LISP]</dt>
83 <dd>Synthesizes a piano tone. <i>Duration</i> is the duration to the point of
84 key release, after which there is a rapid decay. <i>Step</i> is the pitch in half
85 steps, and <i>dynamic</i> is approximately equivalent to a MIDI key velocity
86 parameter. Use a value near 100 for a loud sound and near 10 for a soft sound.</p>
87 <dt><code>piano-note-2(<a name="index1378"></a><i>step</i>, <i>dynamic</i>)</code> [SAL]<br>
88
89 <code>(piano-note-2 <i>step</i> <i>dynamic</i>)</code> [LISP]</dt>
90 <dd>Similar to <code>piano-note</code> except the duration is nominally 1.0.<br><br>
91 <dt><code>piano-midi(<a name="index1379"></a><i>midi-file-name</i>)</code> [SAL]<br>
92
93 <code>(piano-midi <i>midi-file-name</i>)</code> [LISP]</dt>
94 <dd>Use the piano synthesizer
95 to play a MIDI file. The file name (a string) is given by <i>midi-file-name</i>.<br><br>
96 <dt><code>piano-midi2file(<a name="index1380"></a><i>midi-file-name</i>,
97 <i>sound-file-name</i>)</code> [SAL]<br>
98
99 <code>(piano-midi2file <i>midi-file-name</i> <i>sound-file-name</i>)</code> [LISP]</dt>
100 <dd>Use the piano synthesizer to play a MIDI file. The MIDI file
101 is given by <i>midi-file-name</i> and the (monophonic) result is written to the file
102 named <i>sound-file-name</i>.
103 </dd></dl><a name = "193"><h3>Dynamics Compression</h3></a>
104 <p>These functions in the <code>compress</code> extension
105 implement a compressor originally intended for noisy speech audio, but
106 usable in a variety of situations.
107 There are actually two compressors that can be used in
108 series. The first, <code>compress</code>, is
109 a fairly standard one: it detects signal level with an RMS
110 detector and uses table-lookup to determine how much gain
111 to place on the original signal at that point. One bit of
112 cleverness here is that the RMS envelope is &ldquo;followed&rdquo; or
113 enveloped using <code>snd-follow</code>, which does look-ahead to anticipate
114 peaks before they happen.</p>
115
116 <p>The other interesting feature is <code>compress-map</code>, which builds
117 a map in terms of compression and expansion. For speech, the recommended
118 procedure is to figure out the noise floor on the signal you are compressing
119 (for example, look at the signal where the speaker is not talking).
120 Use a compression map that leaves the noise alone and boosts
121 signals that are well above the noise floor. Alas, the <code>compress-map</code>
122 function is not written in these terms, so some head-scratching is
123 involved, but the results are quite good.</p>
124
125 <p>The second compressor is called <code>agc</code>, and it implements automatic gain
126 control that keeps peaks at or below 1.0. By combining <code>compress</code> and
127 <code>agc</code>, you can process poorly recorded speech for playback on low-quality
128 speakers in noisy environments. The <code>compress</code> function modulates the
129 short-term gain to to minimize the total dynamic range, keeping the speech at
130 a generally loud level, and the <code>agc</code> function rides the long-term gain
131 to set the overall level without clipping.</p>
132 <dl>
133 <dt>
134 <code>compress-map(<a name="index1381"></a><i>compress-ratio</i>,
135 <i>compress-threshold</i>,
136 <i>expand-ratio</i>, <i>expand-threshold</i>, limit: <i>limit</i>, transition:
137 <i>transition</i>, verbose: <i>verbose</i>)</code> [SAL]<br>
138
139 <code>(compress-map <i>compress-ratio</i> <i>compress-threshold</i>
140 <i>expand-ratio</i> <i>expand-threshold</i> :limit <i>limit</i> :transition
141 <i>transition</i> :verbose <i>verbose</i>)</code> [LISP]</dt>
142 <dd>Construct
143 a map for the compress function. The map consists of two parts: a compression
144 part and an expansion part.
145 The intended use is to compress everything above <i>compress-threshold</i> by
146 <i>compress-ratio</i>, and to downward expand everything below <i>expand-threshold</i>
147 by <i>expand-ratio</i>. Thresholds are in dB and ratios are dB-per-dB.
148 0dB corresponds to a peak amplitude of 1.0 or rms amplitude of 0.7
149 If the input goes above 0dB, the output can optionally be limited
150 by setting <code>limit:</code> (a keyword parameter) to <code>T</code>.
151 This effectively changes
152 the compression ratio to infinity at 0dB. If <code>limit:</code> is <code>nil</code>
153 (the default), then the compression-ratio continues to apply above 0dB.<br><br>
154 <dt>Another keyword parameter, <code>transition:</code>, sets the amount below the
155 thresholds (in dB) that a smooth transition starts. The default is 0,
156 meaning that there is no smooth transition. The smooth transition is a
157 2nd-order polynomial that matches the slopes of the straight-line compression
158 curve and interpolates between them.<br><br>
159 <dt>If verbose is true (this is the default), the map is printed, showing,
160 for each dB value below zero of this input, what is the gain (in dB)
161 indicated by the output. Only regions where the map is changing are
162 printed because at lower values, the dB gain is constant.<br><br>
163 <dt>It is assumed that expand-threshold &lt;= compress-threshold &lt;= 0
164 The gain is unity at 0dB so if compression-ratio &gt; 1, then gain
165 will be greater than unity below 0dB.<br><br>
166 <dt>The result returned by this function is a sound for use in the <code>shape</code>
167 function. The sound maps input
168 dB to gain. Time 1.0 corresponds to 0dB, time 0.0 corresponds to
169 -100 dB, and time 2.0 corresponds to +100dB, so this is a
170 100hz &ldquo;sample rate&rdquo; sound. The sound gives gain in dB.<br><br>
171 <dt><code>db-average(<a name="index1382"></a><i>input</i>, min: <i>mindb</i>)</code> [SAL]<br>
172
173 <code>(db-average <i>input</i> :min <i>mindb</i>)</code> [LISP]</dt>
174 <dd>Compute
175 the average amplitude
176 of <i>input</i> in dB. The result is a sound at a rate of about 40Hz based on RMS
177 of <i>input</i> such that 0 (dB) corresponds to a sinusoid with a peak amplitude of 1.
178 This is the same dB estimate that is used in the <code>compress</code> function. If <i>mindb</i>
179 is specified and non-nil, the result samples below this value will be replaced by
180 <i>mindb</i>. For example, if you plot the <code>db-average</code> curve of an instrument with a
181 range from -3 dB down to -30 dB, but silences exist at -90 dB, then most of
182 the interesting values will be squeezed into the top 1/3 of a plot. Instead, if you
183 specify <code>min</code> to be -30, then the interesting range will span the entire plot
184 (and silences will show up at -30 dB, the value of <code>min</code>).<br><br>
185 <dt><code>compress(<a name="index1383"></a><i>input</i>, <i>map</i>, <i>rise-time</i>, <i>fall-time</i> [, <i>lookahead</i>])</code> [SAL]<br>
186
187 <code>(compress <i>input</i> <i>map</i> <i>rise-time</i> <i>fall-time</i>
188 [<i>lookahead</i>])</code> [LISP]</dt>
189 <dd>Compress
190 <i>input</i> using <i>map</i>, a compression curve
191 probably generated by <code>compress-map</code> (see above). Adjustments in gain have
192 the given <i>rise-time</i> and <i>fall-time</i>. Lookahead tells how far ahead to look
193 at the signal, and is <i>rise-time</i> by default.<br><br>
194 <dt><code>agc(<a name="index1384"></a><a name="index1385"></a><a name="index1386"></a><i>input</i>,
195 <i>range</i>, <i>rise-time</i>, <i>fall-time</i> [, <i>lookahead</i>])</code> [SAL]<br>
196
197 <code>(agc <i>input</i> <i>range</i> <i>rise-time</i> <i>fall-time</i>
198 [<i>lookahead</i>])</code> [LISP]</dt>
199 <dd>An automatic
200 gain control applied to <i>input</i>. The maximum gain in dB is <i>range</i>. Peaks
201 are attenuated to 1.0, and gain is controlled with the given <i>rise-time</i> and
202 <i>fall-time</i>. The look-ahead time default is <i>rise-time</i>.
203 </dd></dl><a name = "194"><h3>Clipping Softener</h3></a>
204 <p>The <code>clipsoften</code> extension was written to improve the quality of
205 poorly recorded speech. In recordings of speech, extreme clipping generates
206 harsh high frequency noise. This can sound particulary bad on small speakers
207 that will emphasize high frequencies. This problem can be ameliorated by
208 low-pass filtering regions where clipping occurs. The effect is to dull the
209 harsh clipping. Intelligibility is not affected by much, and the result can
210 be much more pleasant on the ears. Clipping is detected simply by looking for
211 large signal values. Assuming 8-bit recording, this level is set to 126/127.</p>
212
213 <p>The function works by cross-fading between the normal signal and a filtered
214 signal as opposed to changing filter coefficients.</p>
215 <dl>
216 <dt>
217 <code>soften-clipping(<a name="index1387"></a><a name="index1388"></a><i>snd</i>,
218 <i>cutoff</i>)</code> [SAL]<br>
219
220 <code>(soften-clipping <i>snd</i> <i>cutoff</i>)</code> [LISP]</dt>
221 <dd>Filter the loud regions of a signal where clipping is likely
222 to have generated additional high frequencies. The input signal is <i>snd</i>
223 and <i>cutoff</i> is the filter cutoff frequency
224 (4 kHz is recommended for speech).
225 </dd></dl><a name = "195"><h3>Graphical Equalizer</h3></a>
226 <p>The library
227 (<code>load "grapheq.lsp"</code>) works with the NyquistIDE's Equalizer window
228 (see Section <a href = "part3.html#25">Equalizer Editor</a>, but
229 this library can be used directly in Nyquist programs for multi-band equalizers.
230 This implementation uses
231 Nyquist's <code>eq-band</code> function to split the incoming signal into different
232 frequency bands. Bands are spaced geometrically, e.g. each band could be one
233 octave, meaning that each successive band has twice the bandwidth. An interesting
234 possibility is using computed control functions to make the equalization change
235 over time.</p>
236 <dl>
237 <dt>
238 <code>nband-range(<a name="index1389"></a><a name="index1390"></a><a name="index1391"></a><i>input</i>, <i>gains</i>, <i>lowf</i>, <i>highf</i>)</code> [SAL]<br>
239
240 <code>(nband-range <i>input</i> <i>gains</i> <i>lowf</i> <i>highf</i>)</code> [LISP]</dt>
241 <dd>A graphical equalizer applied to
242 <i>input</i> (a <code>SOUND</code>). The gain controls and number of bands is given by <i>gains</i>, an
243 ARRAY of <code>SOUND</code>s (in other words, a Nyquist multichannel <code>SOUND</code>). Any sound in the
244 array may be replaced by a <code>FLONUM</code>. The bands are
245 geometrically equally spaced from the lowest frequency <i>lowf</i> to the
246 highest frequency <i>highf</i> (both are <code>FLONUM</code>s).<br><br>
247 <dt><code>nband(<a name="index1392"></a><i>input</i>, <i>gains</i>)</code> [SAL]<br>
248
249 <code>(nband <i>input</i> <i>gains</i>)</code> [LISP]</dt>
250 <dd>A graphical equalizer, identical
251 to <code>nband-range</code> with a range of 20 to 20,000 Hz.
252 </dd></dl><a name = "196"><h3>Sound Reversal</h3></a>
253 <p>The <code>reverse</code> extension implements functions to play sounds in reverse.
254 <dl>
255 <dt>
256 <code>s-reverse(<a name="index1393"></a><a name="index1394"></a><a name="index1395"></a><a name="index1396"></a><i>snd</i>)</code> [SAL]<br>
257
258 <code>(s-reverse <i>snd</i>)</code> [LISP]</dt>
259 <dd>Reverses <i>snd</i> (a <code>SOUND</code>). Sound must be shorter
260 than <code>*max-reverse-samples*</code>, which is currently initialized to
261 25 million samples. Reversal allocates about 4 bytes per sample. This function
262 uses XLISP in the inner sample loop, so do not be surprised if it calls the
263 garbage collector a lot and runs slowly. The result starts at the starting
264 time given by the current environment (not necessarily the starting time
265 of <i>snd</i>). If <i>snd</i> has multiple channels, a multiple channel,
266 reversed sound is returned.</p>
267 <dt><code>s-read-reverse(<a name="index1397"></a><a name="index1398"></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>
268
269 <code>(s-read-reverse <i>filename</i> :time-offset <i>offset</i>
270 :srate <i>sr</i> :dur <i>dur</i> :nchans <i>chans</i> :format <i>format</i> :mode <i>mode</i>
271 :bits <i>n</i> :swap <i>flag</i>)</code> [LISP]</dt>
272 <dd>This function is
273 identical to <code>s-read</code> (see Section <a href = "part8.html#100">Sound File Input and Output</a>), except it reads
274 the indicated samples in reverse. Like
275 <code>s-reverse</code> (see above), it uses XLISP in the inner loop, so it is slow.
276 Unlike <code>s-reverse</code>, <code>s-read-reverse</code> uses a fixed amount of
277 memory that is independent of how many samples are computed. Multiple channels
278 are handled.
279 </dd></dl><a name = "197"><h3>Time Delay Functions</h3></a>
280 <p>The <code>time-delay-fns.lsp</code> library implements chorus, phaser, and
281 flange effects.</p>
282 <dl>
283 <dt>
284 <code>phaser(<a name="index1399"></a><a name="index1400"></a><i>snd</i>)</code> [SAL]<br>
285
286 <code>(phaser <i>snd</i>)</code> [LISP]</dt>
287 <dd>A phaser effect
288 applied to <i>snd</i> (a <code>SOUND</code>). There are no parameters,
289 but feel free to modify the source code of this one-liner.<br><br>
290 <dt><code>flange(<a name="index1401"></a><a name="index1402"></a><a name="index1403"></a><i>snd</i>)</code> [SAL]<br>
291
292 <code>(flange <i>snd</i>)</code> [LISP]</dt>
293 <dd>A flange effect
294 applied to <i>snd</i>. To vary the rate and other parameters, see the source code.<br><br>
295 <dt><code>stereo-chorus(<a name="index1404"></a><a name="index1405"></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>
296
297 <code>(stereo-chorus <i>snd</i> :delay <i>delay</i> :depth <i>depth</i>
298 :rate1 <i>rate1</i> :rate2 <i>rate2</i> :saturation <i>saturation</i>)</code> [LISP]</dt>
299 <dd>A chorus effect
300 applied to <i>snd</i>,
301 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>
302 <dt><code>chorus(<a name="index1406"></a><a name="index1407"></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>
303
304 <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]</dt>
305 <dd>A chorus effect applied to <i>snd</i>. All parameters may be arrays
306 as usual. The chorus is implemented as a variable delay
307 modulated by a sinusoid shifted by <i>phase</i> degrees (a <code>FLONUM</code>) oscillating
308 at <i>rate</i> Hz (a <code>FLONUM</code>). The sinusoid is
309 scaled by <i>depth</i> (a <code>FLONUM</code>. The delayed signal is mixed
310 with the original, and <i>saturation</i> (a <code>FLONUM</code>) gives the fraction of
311 the delayed signal
312 (from 0 to 1) in the mix.
313 Default values are <i>delay</i> 0.03, <i>depth</i> 0.003, <i>rate</i> 0.3,
314 <i>saturation</i> 1.0, and <i>phase</i> 0.0 (degrees).
315 </dd></dl><a name = "198"><h3>Multiple Band Effects</h3></a><a name="index1408"></a><a name="index1409"></a>
316 <p>The <code>bandfx</code> extension implements several effects based on multiple
317 frequency bands. The idea is to separate a signal into different frequency
318 bands, apply a slightly different effect to each band, and sum the effected
319 bands back together to form the result. This file includes its own set of
320 examples. After loading the file, try <code>f2()</code>, <code>f3()</code>, <code>f4()</code>,
321 and <code>f5()</code> to hear them.
322 Further discussion and examples can be found in
323 <code>nyquist/lib/bandfx/bandfx.lsp</code><a name="index1410"></a>. </p>
324
325 <p>There is much room for expansion and experimentation with this
326 library. Other effects might include distortion in certain bands (for
327 example, there are commercial effects that add distortion to low
328 frequencies to enhance the sound of the bass), separating bands into
329 different channels for stereo or multichannel effects, adding
330 frequency-dependent reverb, and performing dynamic compression,
331 limiting, or noise gate functions on each band. There are also
332 opportunities for cross-synthesis: using the content of bands
333 extracted from one signal to modify the bands of another. The simplest
334 of these would be to apply amplitude envelopes of one sound to
335 another. Please contact us ([email protected]) if you are
336 interested in working on this library.</p>
337 <dl>
338 <dt>
339 <code>apply-banded-delay(<a name="index1411"></a><a name="index1412"></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>
340
341 <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]</dt>
342 <dd>Separates
343 input <code>SOUND</code> <i>s</i> into <code>FIXNUM</code> <i>num-bands</i> bands from a
344 low frequency of <i>lowp</i> to a high frequency of <i>highp</i> (these are
345 <code>FLONUMS</code> that specify steps, not Hz), and applies a delay to
346 each band. The delay for the lowest band is given by the <code>FLONUM</code>
347 <i>lowd</i> (in seconds) and the delay for the highest band is given by
348 the <code>FLONUM</code> <i>highd</i>. The delays for other bands are linearly
349 interpolated between these values. Each delay has feedback gain
350 controlled by <code>FLONUM</code> <i>fb</i>. The delayed bands are scaled by
351 <code>FLONUM</code> <i>wet</i>, and the original sound is scaled by 1 -
352 <i>wet</i>. All are summed to form the result, a <code>SOUND</code>.<br><br>
353 <dt><code>apply-banded-bass-boost(<a name="index1413"></a><a name="index1414"></a><i>s</i>, <i>lowp</i>, <i>highp</i>, <i>num-bands</i>, <i>num-boost</i>, <i>gain</i>)</code> [SAL]<br>
354
355 <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]</dt>
356 <dd>Applies a boost to low frequencies.
357 Separates input <code>SOUND</code> <i>s</i> into <code>FIXNUM</code> <i>num-bands</i>
358 bands from a low frequency of <i>lowp</i> to a high frequency of
359 <i>highp</i> (these are <code>FLONUMS</code> that specify steps, not Hz), and
360 scales the lowest <i>num-boost</i> (a <code>FIXNUM</code>) bands by <i>gain</i>, a
361 <code>FLONUM</code>. The bands are summed to form the result, a
362 <code>SOUND</code>.<br><br>
363 <dt><code>apply-banded-treble-boost(<a name="index1415"></a><a name="index1416"></a><i>s</i>, <i>lowp</i>, <i>highp</i>, <i>num-bands</i>, <i>num-boost</i>, <i>gain</i>)</code> [SAL]<br>
364
365 <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]</dt>
366 <dd>Applies a boost to
367 high frequencies. Separates input <code>SOUND</code> <i>s</i> into
368 <code>FIXNUM</code> <i>num-bands</i> bands from a low frequency of <i>lowp</i> to
369 a high frequency of <i>highp</i> (these are <code>FLONUMS</code> that specify
370 steps, not Hz), and scales the highest <i>num-boost</i> (a <code>FIXNUM</code>)
371 bands by <i>gain</i>, a <code>FLONUM</code>. The bands are summed to form the
372 result, a <code>SOUND</code>. </dd></dl><a name = "199"><h3>Granular Synthesis</h3></a>
373 <p>Some granular synthesis functions are implemented in the
374 <code>gran</code> extension. There are many variations and control
375 schemes one could adopt for granular synthesis, so it is impossible to
376 create a single universal granular synthesis function. One of the
377 advantages of Nyquist is the integration of control and synthesis
378 functions, and users are encouraged to build their own granular
379 synthesis functions incorporating their own control schemes. The
380 <code>gran.lsp</code> file includes many comments and is intended to be a
381 useful starting point. Another possibility is to construct a score
382 with an event for each grain. Estimate a few hundred bytes per score
383 event (obviously, size depends on the number of parameters) and avoid
384 using all of your computer's memory.</p>
385 <dl>
386 <dt>
387 <code>sf-granulate(<a name="index1417"></a><a name="index1418"></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>
388
389 <code>(sf-granulate <i>filename</i> <i>grain-dur</i> <i>grain-dev</i> <i>ioi</i>
390 <i>ioi-dev</i> <i>pitch-dev</i> [<i>file-start</i> <i>file-end</i>])</code> [LISP]</dt>
391 <dd>Granular synthesis
392 using a sound file
393 named <i>filename</i> as the source for grains. Grains are extracted from
394 a sound file named by <i>filename</i> by stepping through the file in equal
395 increments. Each grain duration is the
396 sum of <i>grain-dur</i> and a random number from 0 to <i>grain-dev</i>. Grains are
397 then multiplied by a raised cosine smoothing window and resampled at a ratio
398 between 1.0 and <i>pitch-dev</i>. If <i>pitch-dev</i> is greater than one, grains are
399 stretched and the pitch (if any) goes down. If <i>pitch-dev</i> is less than one,
400 grains are shortened and the pitch goes up. Grains are then output
401 with an
402 inter-onset interval between successive grains (which may overlap)
403 determined by the sum of
404 <i>ioi</i> and a random number from 0 to <i>ioi-dev</i>.
405 The duration of the resulting sound is determined by
406 the stretch factor (not by the sound file). The number of grains is
407 the total sound duration (determined by the stretch factor)
408 divided by the mean inter-onset interval,
409 which is <i>ioi</i> + <i>ioi-dev</i> * 0.5.
410 The grains are taken from equally-spaced starting points in <i>filename</i>,
411 and depending on grain size and number, the grains may or may not overlap.
412 The output duration will simply be the sum of the inter-onset intervals
413 and the duration of the last grain. If <i>ioi-dev</i> is non-zero, the
414 output duration will vary, but the expected value of the duration is
415 the stretch factor.
416 To achieve a rich granular synthesis effect, it is often a good idea to
417 sum four or more copies of <code>sf-granulate</code> together. (See the <code>gran-test</code>
418 function in <code>gran.lsp</code>.)
419 </dd></dl><a name = "200"><h3>Chowning FM Voices</h3></a>
420 <p>John Chowning developed voice synthesis methods using FM to simulate
421 resonances for his 1981 composition "Phone." He later recreated the
422 synthesis algorithms in Max, and Jorge Sastre ported these to SAL.
423 See <code>fm-voices-chowning</code> extension and documentation for more details.</p>
424 <a name = "201"><h3>Atonal Melody Composition</h3></a>
425 <p>Jorge Sastre contributed the <code>atonal-melodies</code> extension
426 that generates atonal melodies. You can find links to an example
427 score and audio file in the code and also at
428 <code>http://algocompbook.com/examples.html</code>.</p>
429 <a name = "202"><h3>MIDI Utilities</h3></a>
430 <p>The <code>midishow.lsp</code> library has functions that can print the contents of MIDI
431 files. This intended as a debugging aid.</p>
432 <dl>
433 <dt>
434 <code>midi-show-file(<a name="index1419"></a><a name="index1420"></a><a name="index1421"></a><i>file-name</i>)</code> [SAL]<br>
435
436 <code>(midi-show-file <i>file-name</i>)</code> [LISP]</dt>
437 <dd>Print the contents of a MIDI file to the console.<br><br>
438 <dt><code>midi-show(<a name="index1422"></a><i>the-seq</i> [, <i>out-file</i>])</code> [SAL]<br>
439
440 <code>(midi-show <i>the-seq</i> [<i>out-file</i>])</code> [LISP]</dt>
441 <dd>Print the
442 contents of the sequence <i>the-seq</i> to the file <i>out-file</i> (whose default value
443 is the console.)
444 </dd></dl><a name = "203"><h3>Reverberation</h3></a>
445 <p>The <code>reverb.lsp</code> library implements artificial reverberation.</p>
446 <dl>
447 <dt>
448 <code>reverb(<a name="index1423"></a><a name="index1424"></a><i>snd</i>,
449 <i>time</i>)</code> [SAL]<br>
450
451 <code>(reverb <i>snd</i> <i>time</i>)</code> [LISP]</dt>
452 <dd>Artificial reverberation applied to <i>snd</i> with a decay time of
453 <i>time</i>.
454 </dd></dl><a name = "204"><h3>DTMF Encoding</h3></a><a name="index1425"></a><a name="index1426"></a>
455 <p>The <code>dtmf</code> extension implements DTMF encoding. DTMF is the
456 &ldquo;touch tone&rdquo; code used by telephones.</p>
457 <dl>
458 <dt>
459 <code>dtmf-tone(<a name="index1427"></a><i>key</i>, <i>len</i>, <i>space</i>)</code> [SAL]<br>
460
461 <code>(dtmf-tone <i>key</i> <i>len</i> <i>space</i>)</code> [LISP]</dt>
462 <dd>Generate a
463 single DTMF tone. The <i>key</i> parameter is either a digit (a <code>FIXNUM</code>
464 from 0 through 9) or the atom <code>STAR</code> or <code>POUND</code>. The duration of
465 the done is given by <i>len</i> (a <code>FLONUM</code>) and the tone is followed by
466 silence of duration <i>space</i> (a <code>FLONUM</code>).<br><br>
467 <dt><code>speed-dial(<a name="index1428"></a><i>thelist</i>)</code> [SAL]<br>
468
469 <code>(speed-dial <i>thelist</i>)</code> [LISP]</dt>
470 <dd>Generates a sequence
471 of DTMF tones using the keys in <i>thelist</i> (a <code>LIST</code> of keys as
472 described above under <code>dtmf-tone</code>). The duration of each tone is 0.2
473 seconds, and the space between tones is 0.1 second. Use <code>stretch</code> to
474 change the &ldquo;dialing&rdquo; speed.
475 </dd></dl><a name = "205"><h3>Dolby Surround(R), Stereo and Spatialization Effects</h3></a><a name="index1429"></a><a name="index1430"></a><a name="index1431"></a><a name="index1432"></a>
476 <p>The <code>spatial</code> extension implements various functions for stereo
477 manipulation and spatialization. It also includes some functions for
478 Dolby Pro-Logic panning, which encodes left, right, center, and surround
479 channels into stereo. The stereo signal can then be played through
480 a Dolby decoder to drive a surround speaker array. This library has
481 a somewhat simplified encoder, so you should certainly test the
482 output. Consider using a high-end encoder for critical work. There
483 are a number of functions in <code>spatial.lsp</code> for testing. See the
484 source code and extension documentation for more information.</p>
485 <dl>
486 <dt>
487 <code>stereoize(<a name="index1433"></a><a name="index1434"></a><a name="index1435"></a><i>snd</i>)</code> [SAL]<br>
488
489 <code>(stereoize <i>snd</i>)</code> [LISP]</dt>
490 <dd>Convert a mono sound, <i>snd</i>, to stereo. Four bands of
491 equalization and some delay are used to create a stereo effect.<br><br>
492 <dt><code>widen(<a name="index1436"></a><a name="index1437"></a><i>snd</i>, <i>amt</i>)</code> [SAL]<br>
493
494 <code>(widen <i>snd</i> <i>amt</i>)</code> [LISP]</dt>
495 <dd>Artificially
496 widen the stereo field in <i>snd</i>, a two-channel sound. The amount of widening
497 is <i>amt</i>, which varies from 0 (<i>snd</i> is unchanged) to 1 (maximum widening).
498 The <i>amt</i> can be a <code>SOUND</code> or a number.<br><br>
499 <dt><code>span(<a name="index1438"></a><a name="index1439"></a><a name="index1440"></a><a name="index1441"></a><i>snd</i>, <i>amt</i>)</code> [SAL]<br>
500
501 <code>(span <i>snd</i> <i>amt</i>)</code> [LISP]</dt>
502 <dd>Pan the virtual center channel of a stereo sound, <i>snd</i>,
503 by <i>amt</i>, where 0 pans all the way to the left, while 1 pans all the way
504 to the right. The <i>amt</i> can be a <code>SOUND</code> or a number.<br><br>
505 <dt><code>swapchannels(<a name="index1442"></a><a name="index1443"></a><a name="index1444"></a><i>snd</i>)</code> [SAL]<br>
506
507 <code>(swapchannels <i>snd</i>)</code> [LISP]</dt>
508 <dd>Swap left and right channels in <i>snd</i>, a stereo sound.<br><br>
509 <dt><code>prologic(<a name="index1445"></a><a name="index1446"></a><a name="index1447"></a><i>l</i>, <i>c</i>,
510 <i>r</i>, <i>s</i>)</code> [SAL]<br>
511
512 <code>(prologic <i>l</i> <i>c</i> <i>r</i> <i>s</i>)</code> [LISP]</dt>
513 <dd>Encode four monaural <code>SOUND</code>s representing the front-left,
514 front-center, front-right, and rear channels, respectively.
515 The return value is a stereo sound, which is a Dolby-encoded mix of the
516 four input sounds. <br><br>
517 <dt><code>pl-left(<a name="index1448"></a><i>snd</i>)</code> [SAL]<br>
518
519 <code>(pl-left <i>snd</i>)</code> [LISP]</dt>
520 <dd>Produce a Dolby-encoded (stereo)
521 signal with <i>snd</i>, a <code>SOUND</code>, encoded as the front left channel.<br><br>
522 <dt><code>pl-center(<a name="index1449"></a><i>snd</i>)</code> [SAL]<br>
523
524 <code>(pl-center <i>snd</i>)</code> [LISP]</dt>
525 <dd>Produce a Dolby-encoded (stereo)
526 signal with <i>snd</i>, a <code>SOUND</code>, encoded as the front center channel.<br><br>
527 <dt><code>pl-right(<a name="index1450"></a><i>snd</i>)</code> [SAL]<br>
528
529 <code>(pl-right <i>snd</i>)</code> [LISP]</dt>
530 <dd>Produce a Dolby-encoded (stereo)
531 signal with <i>snd</i>, a <code>SOUND</code>, encoded as the front right channel.<br><br>
532 <dt><code>pl-rear(<a name="index1451"></a><i>snd</i>)</code> [SAL]<br>
533
534 <code>(pl-rear <i>snd</i>)</code> [LISP]</dt>
535 <dd>Produce a Dolby-encoded (stereo)
536 signal with <i>snd</i>, a <code>SOUND</code>, encoded as the rear, or surround, channel.<br><br>
537 <dt><code>pl-pan2d(<a name="index1452"></a><i>snd</i>, <i>x</i>, <i>y</i>)</code> [SAL]<br>
538
539 <code>(pl-pan2d <i>snd</i> <i>x</i> <i>y</i>)</code> [LISP]</dt>
540 <dd>Comparable to Nyquist's
541 existing pan function, <code>pl-pan2d</code> provides not only left-to-right
542 panning, but front-to-back panning as well. The function
543 accepts three parameters: <i>snd</i> is the (monophonic) input <code>SOUND</code>,
544 <i>x</i> is a left-to-right position, and <i>y</i> is a front-to-back position.
545 Both position parameters may be numbers or <code>SOUND</code>s. An <i>x</i> value
546 of 0 means left, and 1 means right. Intermediate values map linearly
547 between these extremes. Similarly, a <i>y</i> value of 0 causes the sound
548 to play entirely through the front speakers(s), while 1 causes it to play
549 entirely through the rear. Intermediate values map linearly.
550 Note that, although there are usually two rear speakers in Pro-Logic systems,
551 they are both driven by the same signal. Therefore any sound that is
552 panned totally to the rear will be played over both rear speakers. For
553 example, it is not possible to play a sound exclusively through the
554 rear left speaker.<br><br>
555 <dt><code>pl-position(<a name="index1453"></a><i>snd</i>, <i>x</i>, <i>y</i>, <i>config</i>)</code> [SAL]<br>
556
557 <code>(pl-position <i>snd</i> <i>x</i> <i>y</i> <i>config</i>)</code> [LISP]</dt>
558 <dd>The
559 position function builds upon speaker panning to allow more abstract
560 placement of sounds. Like <code>pl-pan2d</code>, it accepts a (monaural) input
561 sound as well as left-to-right (<i>x</i>) and front-to-back (<i>y</i>) coordinates,
562 which may be <code>FLONUM</code>s or <code>SOUND</code>s. A fourth parameter <i>config</i>
563 specifies the distance from listeners to the speakers (in meters). Current
564 settings assume this to be constant for all speakers, but this assumption
565 can be changed easily (see comments in the code for more detail).
566 There are several important differences between <code>pl-position</code> and
567 <code>pl-pan2d</code>. First, <code>pl-position</code> uses a Cartesian coordinate
568 system that allows x and y coordinates outside of the
569 range (0, 1). This model assumes a listener position of (0,0). Each speaker
570 has a predefined position as well. The input sound's position,
571 relative to the listener, is given by the vector (<i>x</i>,<i>y</i>).<br><br>
572 <dt><code>pl-doppler(<a name="index1454"></a><a name="index1455"></a><i>snd</i>,
573 <i>r</i>)</code> [SAL]<br>
574
575 <code>(pl-doppler <i>snd</i> <i>r</i>)</code> [LISP]</dt>
576 <dd>Pitch-shift moving sounds according to the equation: <i>fr</i> =
577 <i>f0</i>((<i>c</i>+<i>vr</i>)/<i>c</i>), where <i>fr</i> is the output frequency,
578 <i>f0</i> is the emitted (source)
579 frequency, <i>c</i> is the speed of sound (assumed to be 344.31 m/s), and
580 <i>vr</i> is the speed at which the emitter approaches the receiver. (<i>vr</i>
581 is the first derivative of parameter <i>r</i>, the distance from the listener
582 in meters.
583 </dd></dl><a name = "206"><h3>Drum Machine</h3></a><a name="index1456"></a>
584 <p>The drum machine software in the <code>plight</code> extension
585 deserves further explanation. There is documentation associated
586 with the extension and available in the NyquistIDE Extension Manager.
587 To use the software, install the extension and load the code by evaluating:
588 </p>
589 <pre>
590 load "plight/drum.lsp"
591 exec load-props-file(strcat(*plight-drum-path*,
592 "beats.props"))
593 exec create-drum-patches()
594 exec create-patterns()
595 </pre>
596
597 <p></p>
598
599 <p>Drum sounds and patterns are specified in the <code>beats.props</code> file (or
600 whatever name you give to <code>load-props-file</code>). This file
601 contains two types of specifications. First, there are sound file specifications.
602 Sound files are located by a line of the form:
603 </p>
604 <pre>
605 set sound-directory = "kit/"
606 </pre>
607
608 <p>
609 This gives the name of the sound file directory, relative to the
610 <code>beats.props</code> file. Then, for each sound file, there should be a line of
611 the form:
612 </p>
613 <pre>
614 track.2.5 = big-tom-5.wav
615 </pre>
616
617 <p>
618 This says that on track 2, a velocity value of 5 means to play the sound file
619 <code>big-tom-5.wav</code>. (Tracks and velocity values are described below.)
620 The <code>beats.props</code> file contains specifications for all the sound files
621 in <code>nyquist/lib/plight/plight/kit</code> using 8 tracks. If you make your own specifications
622 file, tracks should be numbered consecutively from 1, and velocities should be
623 in the range of 1 to 9.</p>
624
625 <p>The second set of specifications is of beat patterns. A beat pattern is given
626 by a line in the following form:
627 </p>
628 <pre>
629 beats.5 = 2--32--43-4-5---
630 </pre>
631
632 <p>
633 The number after <code>beats</code> is just a pattern number. Each pattern
634 is given a unique number. After the equal sign, the digits and dashes are
635 velocity values where a dash means &ldquo;no sound.&rdquo; Beat patterns should be
636 numbered consecutively from 1.</p>
637
638 <p>Once data is loaded, there are several functions to access drum patterns and
639 create drum sounds (described below). The <code>nyquist/lib/plight/plight/drums.lsp</code> file
640 contains an example function <code>plight-drum-example</code> to play some drums.
641 There is also the file <code>nyquist/lib/plight/beats.props</code> to serve as an
642 example of how to specify sound files and beat patterns.</p>
643 <dl>
644 <dt>
645 <code>drum(<a name="index1457"></a><i>tracknum</i>, <i>patternnum</i>, <i>bpm</i>)</code> [SAL]<br>
646
647 <code>(drum <i>tracknum</i> <i>patternnum</i> <i>bpm</i>)</code> [LISP]</dt>
648 <dd>Create
649 a sound by playing drums sounds associated with track <i>tracknum</i> (a
650 FIXNUM) using pattern <i>patternnum</i>. The tempo is given by <i>bpm</i> in
651 beats per minute. Normally patterns are a sequence of sixteenth notes, so
652 the tempo is in <i>sixteenth notes per minute</i>. For example,
653 if <i>patternnum</i> is 10,
654 then use the pattern specified for <code>beats.10</code>. If the third character
655 of this pattern is 3 and <i>tracknum</i> is 5, then on the third beat, play
656 the soundfile assigned to <code>track.5.3</code>. This function returns a <code>SOUND</code>.<br><br>
657 <dt><code>drum-loop(<a name="index1458"></a><i>snd</i>, <i>duration</i>, <i>numtimes</i>)</code> [SAL]<br>
658
659 <code>(drum-loop <i>snd</i> <i>duration</i> <i>numtimes</i>)</code> [LISP]</dt>
660 <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>
661 <dt><code>length-of-beat(<a name="index1459"></a><i>bpm</i>)</code> [SAL]<br>
662
663 <code>(length-of-beat <i>bpm</i>)</code> [LISP]</dt>
664 <dd>Given a tempo of
665 <i>bpm</i>, return the duration of the beat in seconds. Note that this software
666 has no real notion of beat. A &ldquo;beat&rdquo; is just the duration of each character
667 in the beat pattern strings. This function returns a <code>FLONUM</code>.
668 </dd></dl>
669
670 <p></p>
671
672 <p></p>
673
674 <p></p>
675
676 <p></p>
677
678
679 <hr>
680 <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>
681 </body></html>