Debian Codegraph @

doc/part8.html

raw
1 <!DOCTYPE html>
2 <html><head><title>Nyquist Functions</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 = "part7.html">Previous Section</a> | <a href = "part9.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 = "82"><h2>Nyquist Functions</h2></a>
11 <p>This chapter provides a language reference for Nyquist. Operations
12 are categorized by functionality and abstraction level.
13 Nyquist is implemented in two important levels: the &ldquo;high level&rdquo; supports
14 behavioral abstraction, which means that operations like <code>stretch</code> and
15 <code>at</code> can be applied. These functions are the ones that typical users
16 are expected to use, and most of these functions are written in XLISP.</p>
17
18 <p>The &ldquo;low-level&rdquo; primitives directly operate on sounds, but know nothing of
19 environmental variables (such as <code>*warp*</code>, etc.). The
20 names of most of these low-level functions start with &ldquo;<code>snd-</code>&rdquo;. In
21 general, programmers should avoid any function with the &ldquo;<code>snd-</code>&rdquo;
22 prefix. Instead, use the &ldquo;high-level&rdquo; functions, which know about the
23 environment and react appropriately. The names of high-level functions
24 do not have prefixes like the low-level functions. </p>
25
26 <p>There are certain low-level operations that apply directly to sounds (as
27 opposed to behaviors) and are relatively &ldquo;safe&rdquo; for ordinary use. These
28 are marked as such.</p>
29
30 <p>Nyquist uses both linear frequency and equal-temperament pitch numbers to
31 specify repetition rates. Frequency is always specified in either cycles
32 per second (hz), or pitch numbers, also referred to as &ldquo;steps,&rdquo; as in
33 steps of the chromatic scale. Steps are floating point numbers such that 60
34 = Middle C, 61 = C#, 61.23 is C# plus 23 cents, etc. The mapping from pitch
35 number to frequency is the standard exponential conversion, and fractional
36 pitch numbers are allowed:
37
38 <blockquote>frequency = 440 * 2<sup>((pitch - 69)/12)</sup></blockquote>
39
40 There are many
41 predefined pitch names. By default these are tuned in equal temperament,
42 with A4 = 440Hz, but these may be changed. (See Section <a href = "part2.html#16">Predefined Constants</a>).</p>
43 <a name = "83"><h3>Sounds</h3></a><a name="index256"></a>
44 <p>A sound is a primitive data type in Nyquist. Sounds can be created, passed
45 as parameters, garbage collected, printed, and set to variables just like
46 strings, atoms, numbers, and other data types. </p>
47 <a name = "84"><h4>What is a Sound?</h4></a>
48 <p>Sounds have 5 components:
49 <ul>
50 <li>
51 <code>srate<a name="index257"></a></code> &ndash; the sample rate of the sound.</li>
52 <li><code>samples<a name="index258"></a></code> &ndash; the samples.</li>
53 <li><code>signal-start<a name="index259"></a></code> &ndash; the time of the first sample.</li>
54 <li><code>signal-stop<a name="index260"></a></code> &ndash; the time of one past the last sample.</li>
55 <li><code>logical-stop<a name="index261"></a></code> &ndash; the time at which the sound logically ends, e.g. a
56 sound may end at the beginning of a decay. This value defaults
57 to <code>signal-stop</code>,
58 but may be set to any value.
59 </li></ul>
60 It may seem that there should be <code>logical-start</code> to indicate the
61 logical or perceptual beginning of a sound as well as a <code>logical-stop</code>
62 to indicate the logical ending of a sound. In practice, only
63 <code>logical-stop</code> is needed; this attribute tells when the next sound
64 should begin to form a sequence of sounds. In this respect, Nyquist sounds
65 are asymmetric: it is possible to compute sequences forward in time by
66 aligning the logical start of each sound with the <code>logical-stop</code> of the
67 previous one, but one cannot compute &ldquo;backwards&rdquo;, aligning the logical end
68 of each sound with the logical start of its successor. The root of this
69 asymmetry is the fact that when we invoke a behavior, we say when to start,
70 and the result of the behavior tells us its logical duration. There is no
71 way to invoke a behavior with a direct specification of when to
72 stop <a href = "foot.html#foot3">(Footnote 3)</a> . </p>
73 <b><i>Note:</i></b> there is no way to enforce the
74 intended &ldquo;perceptual&rdquo; interpretation of
75 <code>logical-stop</code>. As far as Nyquist is concerned, these are just numbers to
76 guide the alignment of sounds within various control constructs.<a name = "85"><h4>Multichannel Sounds</h4></a><a name="index262"></a>
77 <p>Multichannel sounds are represented by Lisp arrays of sounds. To create an
78 array of sounds the XLISP <code>vector</code> function is useful. Most low-level
79 Nyquist functions (the ones starting with <code>snd-</code>) do not operate on
80 multichannel sounds. Most high-level functions do operate on multichannel
81 sounds.</p>
82 <a name = "86"><h4>Accessing and Creating Sound</h4></a>
83 <p>Several functions display information concerning a sound and can be used to
84 query the components of a sound. There are functions that access samples in
85 a sound and functions that construct sounds from samples.</p>
86 <dl>
87 <dt>
88 <code>sref(<a name="index263"></a><a name="Sound, accessing point264"></a><i>sound</i>, <i>time</i>)</code> [SAL]<br>
89
90 <code>(sref <i>sound</i> <i>time</i>)</code> [LISP]</dt>
91 <dd>Accesses <i>sound</i> at
92 the point <i>time</i>, which is a local time. If <i>time</i> does not
93 correspond to a sample time, then the nearest samples are linearly
94 interpolated to form the result. To access a particular sample, either
95 convert the sound to an array (see <code>snd-samples</code> below), or use
96 <code>snd-srate</code> and <code>snd-t0</code> (see below) to find the sample rate
97 and starting time, and compute a time (<i>t</i>) from the sample number (<i>n</i>):
98
99 <blockquote>t = (n / srate) + t0</blockquote>
100
101 Thus, the Lisp code to access the n<sup T>th</sup> sample of a sound would look like:
102
103 <p></p>
104 <pre>
105 (sref sound (global-to-local (+ (/ n (snd-srate sound)) (snd-t0 sound))))
106 </pre>
107
108 <p>
109 Or in SAL, it would look like:
110 </p>
111 <pre>
112 sref(sound, global-to-local(n / snd-srate(sound) + snd-t0(sound)))
113 </pre>
114
115 <p>
116 Here is why <code>sref</code> interprets its time argument
117 as a local time (shown first in LISP and then in SAL syntax):
118 </p>
119 <pre>
120 &gt; (sref (ramp 1) 0.5) <i>; evaluate a ramp at time 0.5</i>
121 0.5
122 SAL&gt; print sref(ramp(1), 0.5) <i>; evaluate a ramp at time 0.5</i>
123 0.5
124 &gt; (at 2.0 (sref (ramp 1) 0.5)) <i>; ramp is shifted to start at 2.0</i>
125 <i>; the time, 0.5, is shifted to 2.5</i>
126 0.5
127 SAL&gt; sref(ramp(1), 0.5) @ 2.0 <i>; ramp is shifted to start at 2.0</i>
128 <i>; the time, 0.5, is shifted to 2.5</i>
129 0.5
130 </pre>
131
132 <p>
133 If you were to use <code>snd-sref</code>, which treats time as global, instead
134 of <code>sref</code>, which treats time as local, then the first example above
135 would return the same answer (0.5), but the second example would return
136 0. Why? Because the <code>ramp</code> behavior would be shifted to start at
137 time 2.0, but the resulting sound would be evaluated at global time
138 0.5. By definition, sounds have a value of zero before their start time.</p>
139 <dt><code>sref-inverse(<a name="index265"></a><i>sound</i>, <i>value</i>)</code> [SAL]<br>
140
141 <code>(sref-inverse <i>sound</i> <i>value</i>)</code> [LISP]</dt>
142 <dd>Search <i>sound</i> for the first point at which it achieves <i>value</i> and return the corresponding (linearly interpolated) time. If no inverse exists, an error is raised. This function is used by Nyquist in the implementation of time warping.<br><br>
143 <dt>
144 <code>snd-from-array(<a name="Sound, creating from array266"></a><a name="index267"></a><i>t0</i>, <i>sr</i>,
145 <i>array</i>)</code> [SAL]<br>
146
147 <code>(snd-from-array <i>t0</i> <i>sr</i> <i>array</i>)</code> [LISP]</dt>
148 <dd>Converts a lisp array of <code>FLONUM</code>s into a sound with starting
149 time <i>t0</i> and sample rate <i>sr</i>. Safe for ordinary use. Be aware that
150 arrays of floating-point samples use 14 bytes per sample, and an additional
151 4 bytes per sample are allocated by this function to create a sound type.<br><br>
152 <dt><code>snd-fromarraystream(<a name="index268"></a><i>t0</i>, <i>sr</i>, <i>object</i>)</code> [SAL]<br>
153
154 <code>(snd-fromarraystream <i>t0</i> <i>sr</i> <i>object</i>)</code> [LISP]</dt>
155 <dd>Creates a
156 sound for which samples come from
157 <i>object</i>. The starting time is <i>t0</i> (a <code>FLONUM</code>), and the sample rate is
158 <i>sr</i>. The <i>object</i> is an XLISP object (see Section <a href = "part19.html#235">Objects</a> for
159 information on objects.) A sound is returned. When the sound needs samples,
160 they are generated by sending the message <code>:next</code> to <i>object</i>. If
161 <i>object</i> returns <code>NIL</code>, the sound terminates. Otherwise, <i>object</i>
162 must return an array of <code>FLONUM</code>s. The values in these arrays are
163 concatenated to form the samples of the resulting sound. In the current
164 implementation, all arrays must have the same length.
165 There is no provision for <i>object</i> to specify the
166 logical stop time of the sound, so the logical stop time is the termination
167 time. <br><br>
168 <dt><code>snd-fromobject(<a name="index269"></a><a name="index270"></a><i>t0</i>, <i>sr</i>, <i>object</i>)</code> [SAL]<br>
169
170 <code>(snd-fromobject <i>t0</i> <i>sr</i> <i>object</i>)</code> [LISP]</dt>
171 <dd>Creates a sound for which samples come from
172 <i>object</i>. The starting time is <i>t0</i> (a <code>FLONUM</code>), and the sample rate is
173 <i>sr</i>. The <i>object</i> is an XLISP object (see Section <a href = "part19.html#235">Objects</a> for
174 information on objects. A sound is returned. When the sound needs samples,
175 they are generated by sending the message <code>:next</code> to <i>object</i>. If
176 <i>object</i> returns <code>NIL</code>, the sound terminates. Otherwise, <i>object</i>
177 must return a <code>FLONUM</code>. There is no provision for <i>object</i> to specify the
178 logical stop time of the sound, so the logical stop time is the termination
179 time.<br><br>
180 <dt><code>snd-extent(<a name="index271"></a><i>sound</i>, <i>maxsamples</i>)</code> [SAL]<br>
181
182 <code>(snd-extent <i>sound</i> <i>maxsamples</i>)</code> [LISP]</dt>
183 <dd>Returns a list of two numbers: the starting time of <i>sound</i> and the terminate time of <i>sound</i>. Finding the terminate time requires that samples be computed. Like most Nyquist functions, this is non-destructive, so memory will be allocated to preserve the sound samples. If the sound is very long or infinite, this may exhaust all memory, so the <i>maxsamples</i> parameter specifies a limit on how many samples to compute. If this limit is reached, the terminate time will be (incorrectly) based on the sound having <i>maxsamples</i> samples. This function is safe for ordinary use.<br><br>
184 <dt><code>snd-fetch(<a name="index272"></a><a name="index273"></a><a name="index274"></a><a name="index275"></a><i>sound</i>)</code> [SAL]<br>
185
186 <code>(snd-fetch <i>sound</i>)</code> [LISP]</dt>
187 <dd>Reads samples
188 sequentially from <i>sound</i>. This returns a <code>FLONUM</code> after each call, or
189 <code>NIL</code> when <i>sound</i> terminates. <b><i>Note:</i></b> <code>snd-fetch</code> modifies
190 <i>sound</i>; it is strongly recommended to copy <i>sound</i> using
191 <code>snd-copy</code> and access only the copy with <code>snd-fetch</code>.<br><br>
192 <dt><code>snd-fetch-array(<a name="index276"></a><i>sound</i>, <i>len</i>,
193 <i>step</i>)</code> [SAL]<br>
194
195 <code>(snd-fetch-array <i>sound</i> <i>len</i> <i>step</i>)</code>
196 [LISP]</dt>
197 <dd>Reads
198 sequential arrays of samples from <i>sound</i>, returning either an array
199 of <code>FLONUM</code>s or <code>NIL</code> when the sound terminates. The <i>len</i>
200 parameter, a <code>FIXNUM</code>, indicates how many samples should be
201 returned in the result array. After the array is returned, <i>sound</i>
202 is modified by skipping over <i>step</i> (a <code>FIXNUM</code>) samples. If
203 <i>step</i> equals <i>len</i>, then every sample is returned once. If
204 <i>step</i> is less than <i>len</i>, each returned array will overlap the
205 previous one, so some samples will be returned more than once. If
206 <i>step</i> is greater than <i>len</i>, then some samples will be skipped
207 and not returned in any array. The <i>step</i> and <i>len</i> may change at
208 each call, but in the current implementation, an internal buffer is
209 allocated for <i>sound</i> on the first call, so subsequent calls may not
210 specify a greater <i>len</i> than the first. When an array is returned,
211 it will have <i>len</i> samples. If necessary, <code>snd-fetch-array</code>
212 will read zeros beyond the end of the sound to fill the array. When
213 this happens, <code>*rslt*</code> is set to a FIXNUM number of samples in
214 the array that were read from the sound before the physical stop time
215 of the sound. If all samples in the array are &ldquo;valid&rdquo; samples from
216 the sound (coming from the sound before the sound
217 terminates), <code>*rslt*</code> is set to <code>NIL</code>. The <code>*rslt*</code>
218 variable is global and used to return extra results from other
219 functions, so programs should not assume <code>*rslt*</code> is valid after
220 subsequent function calls. <b><i>Note:</i></b> <code>snd-fetch-array</code> modifies
221 <i>sound</i>; it is strongly recommended to copy <i>sound</i> using
222 <code>snd-copy</code> and access only the copy with <code>snd-fetch-array</code>.<br><br>
223 <dt><code>snd-flatten(<a name="index277"></a><i>sound</i>, <i>maxlen</i>)</code> [SAL]<br>
224
225 <code>(snd-flatten <i>sound</i> <i>maxlen</i>)</code> [LISP]</dt>
226 <dd>This function is identical
227 to <code>snd-length</code>. You would use this function to force samples to be computed in memory. Normally, this is not a good thing to do, but here is one appropriate use: In the case of sounds intended for wavetables, the unevaluated
228 sound may be larger than the evaluated (and typically short) one.
229 Calling <code>snd-flatten</code> will compute the samples and allow the unit generators to be freed in the next garbage collection. <b><i>Note:</i></b> If a sound is computed from many instances of table-lookup oscillators, calling <code>snd-flatten</code> will free the oscillators and their tables. Calling <code>(stats)</code> will print how many total bytes have been allocated to tables.<br><br>
230 <dt><code>snd-length(<a name="index278"></a><a name="index279"></a><a name="index280"></a><i>sound</i>, <i>maxlen</i>)</code> [SAL]<br>
231
232 <code>(snd-length <i>sound</i> <i>maxlen</i>)</code> [LISP]</dt>
233 <dd>Counts the
234 number of samples in <i>sound</i> up to the physical stop time. If the sound
235 has more than <i>maxlen</i> samples, <i>maxlen</i> is returned. Calling this
236 function will cause all samples of the sound to be computed and saved in
237 memory (about 4 bytes per sample). Otherwise, this function is safe for ordinary use.<br><br>
238 <dt><code>snd-maxsamp(<a name="index281"></a><i>sound</i>)</code> [SAL]<br>
239
240 <code>(snd-maxsamp <i>sound</i>)</code> [LISP]</dt>
241 <dd>Computes the maximum of
242 the absolute value of the samples in <i>sound</i>. Calling this function will
243 cause samples to be computed and saved in memory. (This function should
244 have a <i>maxlen</i> parameter to allow self-defense against sounds that would
245 exhaust available memory.) Otherwise, this function is safe for ordinary use.
246 This function will probably be removed in a future version. See <code>peak</code>, a replacement (<a href = "#103">Signal Operations</a>).<br><br>
247 <dt><code>snd-play(<a name="index282"></a><a name="index283"></a><a name="index284"></a><i>expression</i>)</code> [SAL]<br>
248
249 <code>(snd-play <i>expression</i>)</code> [LISP]</dt>
250 <dd>Evaluates <i>expression</i>
251 to obtain a sound, computes all of the samples (without
252 retaining them in memory), and returns the number of samples computed.
253 Originally, this was a placeholder
254 for a facility to play samples directly to an audio output device, but
255 playback is now accomplished by <code>s-save</code>.
256 Meanwhile, since this function does not write samples to a file, it is
257 useful in determining how much time is spent calculating samples. See
258 <code>s-save</code> (Section <a href = "#100">Sound File Input and Output</a>) for saving samples to a file, and
259 <code>play</code> (Section <a href = "#100">Sound File Input and Output</a>) to play a sound. This function is
260 safe for ordinary use. Note that it does not accept multichannel sounds.
261 To time mult-channel sound computation, you might try applying
262 <code>to-mono</code> (see Section <a href = "#87">Miscellaneous Functions</a>) to get a SOUND.<br><br>
263 <dt><code>snd-print-tree(<a name="index285"></a><i>sound</i>)</code> [SAL]<br>
264
265 <code>(snd-print-tree <i>sound</i>)</code> [LISP]</dt>
266 <dd>Prints an ascii
267 representation of the internal data structures representing a sound. This
268 is useful for debugging Nyquist. This function is
269 safe for ordinary use.<br><br>
270 <dt><code>snd-samples(<a name="index286"></a><a name="index287"></a><a name="index288"></a><a name="index289"></a><i>sound</i>, <i>limit</i>)</code> [SAL]<br>
271
272 <code>(snd-samples <i>sound</i> <i>limit</i>)</code> [LISP]</dt>
273 <dd>Converts the
274 samples into a lisp array. The data is taken directly from the samples,
275 ignoring shifts. For example, if the sound starts at 3.0 seconds, the first
276 sample will refer to time 3.0, not time 0.0. A maximum of <i>limit</i> samples
277 is returned. This function is safe for ordinary use, but like
278 <code>snd-from-array</code>, it requires a total of slightly over 18 bytes per
279 sample.<br><br>
280 <dt><code>snd-srate(<a name="index290"></a><a name="index291"></a><i>sound</i>)</code> [SAL]<br>
281
282 <code>(snd-srate <i>sound</i>)</code> [LISP]</dt>
283 <dd>Returns the sample rate of
284 the sound. Safe for ordinary use.
285 <br><br>
286 <dt><code>snd-time(<a name="index292"></a><i>sound</i>)</code> [SAL]<br>
287
288 <code>(snd-time <i>sound</i>)</code> [LISP]</dt>
289 <dd>Returns the start time of the
290 sound. This will probably go away in a future version, so use <code>snd-t0</code>
291 instead.<br><br>
292 <dt><code>snd-t0(<a name="index293"></a><i>sound</i>)</code> [SAL]<br>
293
294 <code>(snd-t0 <i>sound</i>)</code> [LISP]</dt>
295 <dd>Returns the time of the
296 first sample of the sound. Note that Nyquist operators such as add always
297 copy the sound and are allowed to shift the copy up to one half sample
298 period in either direction to align the samples of two operands. Safe for
299 ordinary use.<br><br>
300 <dt><code>snd-print(<a name="index294"></a><i>expression</i>, <i>maxlen</i>)</code> [SAL]<br>
301
302 <code>(snd-print <i>expression</i> <i>maxlen</i>)</code> [LISP]</dt>
303 <dd>Evaluates
304 <i>expression</i> to yield a sound or an array of sounds, then prints up to
305 <i>maxlen</i> samples to the screen (stdout). This is similar to
306 <code>snd-save</code>, but samples appear in text on the screen instead of in
307 binary in a file. This function is intended for debugging<a name="index295"></a>.
308 Safe for ordinary use.<br><br>
309 <dt><code>snd-set-logical-stop(<a name="index296"></a><i>sound</i>,
310 <i>time</i>)</code> [SAL]<br>
311
312 <code>(snd-set-logical-stop <i>sound</i> <i>time</i>)</code> [LISP]</dt>
313 <dd>Returns a sound which is
314 <i>sound</i>, except that the logical stop of the sound occurs at <i>time</i>.
315 <b><i>Note:</i></b> do not call this function. When defining a behavior, use
316 <code>set-logical-stop</code> or <code>set-logical-stop-abs</code> instead.<br><br>
317 <dt><code>snd-sref(<a name="index297"></a><i>sound</i>, <i>time</i>)</code> [SAL]<br>
318
319 <code>(snd-sref <i>sound</i> <i>time</i>)</code> [LISP]</dt>
320 <dd>Evaluates <i>sound</i>
321 at the global time given by <i>time</i>. Safe for ordinary use, but normally, you should
322 call <code>sref</code> instead.<br><br>
323 <dt><code>snd-stop-time(<a name="index298"></a><i>sound</i>)</code> [SAL]<br>
324
325 <code>(snd-stop-time <i>sound</i>)</code> [LISP]</dt>
326 <dd>Returns the stop time of <i>sound</i>.
327 Sounds can be &ldquo;clipped&rdquo; or truncated at a particular time. This function
328 returns that time or MAX-STOP-TIME if he programmer has not specified a stop
329 time for the sound. Safe for ordinary use.<br><br>
330 <dt><code>soundp(<a name="index299"></a><i>sound</i>)</code> [SAL]<br>
331
332 <code>(soundp <i>sound</i>)</code> [LISP]</dt>
333 <dd>Returns true iff <i>sound</i> is a
334 SOUND. Safe for ordinary use.<br><br>
335 <dt><code>stats(<a name="index300"></a><a name="index301"></a><a name="index302"></a>)</code> [SAL]<br>
336
337 <code>(stats)</code> [LISP]</dt>
338 <dd>Prints the memory usage status.
339 See also the
340 XLISP <code>mem</code> function. Safe for ordinary use. This is the only way to find out how much memory is being used by table-lookup oscillator instances.<br><br>
341 <dt><code>snd-set-max-audio-mem(<a name="index303"></a><a name="index304"></a><a name="index305"></a><a name="index306"></a><i>bytes</i>)</code> [SAL]<br>
342
343 <code>(snd-set-max-audio-mem <i>bytes</i>)</code> [LISP]</dt>
344 <dd>Sets
345 a limit (a FIXNUM in bytes) on the amount of main memory that
346 Nyquist will allocate
347 for SOUNDs (this does not count table memory). The default is about 1GB.
348 The return value is the previous limit, in bytes. This is not a limit on
349 how big sounds can be. Since Nyquist computes sound incrementally, it can
350 generally play sounds or write sounds to files without storing them in
351 memory. However, if you store large sounds in variables, memory usage can
352 exceed your available RAM, causing extremely slow computation as main memory
353 is swapped to and from disk or Nyquist might run out of memory and crash. The
354 goal of placing a limit on audio memory is to terminate computations before
355 memory is totally exhausted, allowing Nyquist to print an error message and
356 allowing the user to view or save work. Generally, if you see the message
357 &ldquo;The maximum number of sample blocks has been reached, ...,&rdquo; you should
358 fix your code to avoid accumulating samples in memory, e.g. do not assign
359 sounds to global variables. Alternatively, you can use this function to
360 increase the limit, but of course you are still limited by the actual size
361 of memory on your computer, and exceeding that could cause severe performance
362 problems in Nyquist and and any other applications that are running.
363 See also Section <a href = "part2.html#7">Command Line</a> for command line options to limit
364 yquist memory, run time, and file access (these options are not available through
365 the NyquistIDE.)
366 </dd></dl><a name = "87"><h4>Miscellaneous Functions</h4></a>
367 <p>These are all safe and recommended for ordinary use.</p>
368 <dl>
369 <dt>
370
371 <code>to-mono(<a name="index307"></a><i>sound</i>)</code> [SAL]<br>
372
373 <code>(to-mono <i>sound</i>)</code> [LISP]</dt>
374 <dd>Returns the sum of all
375 channels of <i>sound</i> if it is a multichannel sound. If <i>sound</i>
376 is a SOUND, it is simply returned unchanged.
377 See <code>sim</code> (Section <a href = "#99">Combination and Time Structure</a>) for more details on how
378 channels are summed.<br><br>
379 <dt><code>db-to-linear(<a name="index308"></a><i>x</i>)</code> [SAL]<br>
380
381 <code>(db-to-linear <i>x</i>)</code> [LISP]</dt>
382 <dd>Returns the
383 conversion of <i>x</i> from decibels to linear. 0dB is converted to 1.
384 20dB represents a linear factor of 10. If <i>x</i> is a sound, each
385 sample is converted and a sound is returned. If <i>x</i> is a
386 multichannel sound, each channel is converted and a multichannel sound
387 (array) is returned. <b><i>Note:</i></b> With sounds, conversion is only
388 performed on actual samples, not on the implicit zeros before the
389 beginning and after the termination of the sound. Sample rates, start
390 times, etc. are taken from <i>x</i>. <br><br>
391 <dt><code>db-to-vel(<a name="index309"></a><i>x</i> [, <i>float</i>])</code> [SAL]<br>
392
393 <code>(db-to-vel <i>x</i> [<i>float</i>])</code> [LISP]</dt>
394 <dd>Returns the
395 conversion of <i>x</i> from decibels to MIDI velocity using a rule that
396 maps -60 dB to 1 and 0 dB to 127. The MIDI velocity varies linearly
397 with the square root of amplitude. The default value of <i>float</i> is
398 <code>nil</code> and the result is a <code>FIXNUM</code> clipped to fall in the
399 legal range of 1-127, but if a non-<code>nil</code> value
400 is provided, the result is a <code>FLONUM</code> that is not
401 rounded or clipped. The input parameter must be a <code>FIXNUM</code> or
402 <code>FLONUM</code>. Sounds are not allowed.<br><br>
403 <dt><code>follow(<a name="index310"></a><a name="index311"></a><a name="index312"></a><a name="index313"></a><i>sound</i>, <i>floor</i>, <i>risetime</i>, <i>falltime</i>, <i>lookahead</i>)</code> [SAL]<br>
404
405 <code>(follow <i>sound</i> <i>floor</i> <i>risetime</i> <i>falltime</i> <i>lookahead</i>)</code> [LISP]</dt>
406 <dd>An envelope follower intended as a commponent for compressor and limiter functions. The basic goal of this function is to generate a smooth signal
407 that rides on the peaks of the input signal. The usual objective is to
408 produce an amplitude envelope given a low-sample rate (control rate)
409 signal representing local RMS measurements. The first argument is the
410 input signal. The <i>floor</i> is the minimum output value. The <i>risetime</i>
411 is the time (in seconds) it takes for the output to rise (exponentially)
412 from <i>floor</i> to unity (1.0) and the <i>falltime</i> is the time it takes
413 for the output to fall (exponentially) from unity to <i>floor</i>. The
414 algorithm looks ahead for peaks and will begin to increase the output
415 signal according to <i>risetime</i> in anticipation of a peak. The amount
416 of anticipation (in seconds) is given by <i>lookahead</i>. The algorithm
417 is as follows: the output value is allowed to increase according to
418 <i>risetime</i> or decrease according to <i>falltime</i>. If the next input
419 sample is in this range, that sample is simply output as the next output
420 sample. If the next input sample is too large, the algorithm goes back in
421 time as far as necessary to compute an envelope that rises according to
422 <i>risetime</i> to meet the new value. The algorithm will only work backward
423 as far as <i>lookahead</i>. If that is not far enough, then there is a final
424 forward pass computing a rising signal from the earliest output sample. In
425 this case, the output signal will be at least momentarily less than the
426 input signal and will continue to rise exponentially until it intersects
427 the input signal. If the input signal falls faster than indicated by
428 <i>falltime</i>, the output fall rate will be limited by <i>falltime</i>,
429 and the fall in output will stop when the output reaches <i>floor</i>.
430 This algorithm can make two passes througth the buffer on sharply rising
431 inputs, so it is not particularly fast. With short buffers and low sample
432 rates this should not matter. See <code>snd-avg</code> for a function that
433 can help to generate a low-sample-rate input for <code>follow</code>.
434 See <code>snd-chase</code> in Section <a href = "#104">Filters</a> for a related filter.<br><br>
435 <dt>
436 <code>gate(<a name="index314"></a><a name="index315"></a><i>sound</i>,
437 <i>lookahead</i>, <i>risetime</i>, <i>falltime</i>, <i>floor</i>,
438 <i>threshold</i>)</code> [SAL]<br>
439
440 <code>(gate <i>sound</i> <i>lookahead</i> <i>risetime</i> <i>falltime</i> <i>floor</i> <i>threshold</i>)</code> [LISP]</dt>
441 <dd>Generate an exponential rise and decay intended
442 for noise gate implementation. The decay starts when the signal drops
443 below <i>threshold</i> and stays there for longer than <i>lookahead</i> (a
444 <code>FLONUM</code> in seconds). (The signal begins to drop when the signal
445 crosses <i>threshold</i>, not after <i>lookahead</i>.) Decay continues until
446 the value reaches <i>floor</i> (a <code>FLONUM</code>), at which point the decay
447 stops and the output value is held constant. Either during the decay or
448 after the floor is reached, if the signal goes above <i>threshold</i>, then
449 the output value will rise to unity (1.0) at the point the signal crosses
450 the threshold. Because of internal lookahead, the signal actually begins
451 to rise before the signal crosses <i>threshold</i>. The rise is a
452 constant-rate exponential and set so that a rise from <i>floor</i> to unity
453 occurs in <i>risetime</i>. Similary, the fall is a constant-rate exponential
454 such that a fall from unity to <i>floor</i> takes <i>falltime</i>.<br><br>
455 <dt><code>noise-gate(<a name="index316"></a><i>sound</i> [, <i>lookahead</i>, <i>risetime</i>, <i>falltime</i>, <i>floor</i>, <i>threshold</i>] [, rms: <i>use-rms</i>, link: <i>link-option</i>])</code> [SAL]<br>
456
457 <code>(noise-gate <i>sound</i> [<i>lookahead</i> <i>risetime</i> <i>falltime</i> <i>floor</i> <i>threshold</i>] [:rms <i>use-rms</i> :link <i>link-option</i>])</code> [LISP]</dt>
458 <dd>A
459 simple noise gate implementation based on <code>gate</code>. All parameters
460 except <i>snd</i> are optional and default values are <i>lookahead</i>:
461 0.5, <i>risetime</i>: 0.02, <i>falltime</i>: 0.5, <i>floor</i>: 0.01,
462 <i>threshold</i>: 0.01. The keyword parameters <code>:rms</code> and <code>:link</code> are
463 also optional with default values of <i>use-rms</i>: <code>NIL</code> (false) and
464 <i>link-option</i>: T (true). The result is the input <i>snd</i>, where
465 below-threshold segments of sound are attenuated to a maximum of <i>floor</i> (see the
466 <code>gate</code> function above). If <i>use-rms</i> is non-NIL,
467 the <i>threshold</i> applies to the RMS of the <i>sound</i> computed with
468 10 ms non-overlapping rectangular windows. Otherwise, <i>threshold</i> applies
469 to the absolute value of each sample in <i>sound</i>. If <i>link-option</i> is
470 non-NIL, and if the input <i>sound</i> is multichannel, then a single gate
471 is computed and applied to all channels. The gate threshold is considered
472 to be exceeded when <i>any</i> channel would exceed the threshold and open
473 the gate. (In other words, whether <i>use-rms</i> or not, a maximum value is
474 computed from all the channels and used to control the gate.)<br><br>
475 <dt><code>hz-to-step(<a name="index317"></a><i>freq</i>)</code> [SAL]<br>
476
477 <code>(hz-to-step <i>freq</i>)</code> [LISP]</dt>
478 <dd>Returns a step number for <i>freq</i> (in hz), which can be either a number of a <code>SOUND</code>. The result has the same type as the argument. See also <code>step-to-hz</code> (below).<br><br>
479 <dt><code>linear-to-db(<a name="index318"></a><i>x</i>)</code> [SAL]<br>
480
481 <code>(linear-to-db <i>x</i>)</code> [LISP]</dt>
482 <dd>Returns the conversion of <i>x</i> from linear to decibels. 1 is converted to 0. 0 is converted to -INF (a special IEEE floating point value.) A factor of 10 represents a 20dB change. If <i>x</i> is a sound, each sample is converted and a sound is returned. If <i>x</i> is a multichannel sound, each channel is converted and a multichannel sound (array) is returned. <b><i>Note:</i></b> With sounds, conversion is only performed on actual samples, not on the implicit zeros before the beginning and after the termination of the sound. Start times, sample rates, etc. are taken from <i>x</i>.<br><br>
483 <dt><code>linear-to-vel(<a name="index319"></a><i>x</i> [, <i>float</i>])</code> [SAL]<br>
484
485 <code>(linear-to-vel <i>x</i> [<i>float</i>])</code> [LISP]</dt>
486 <dd>Returns the
487 conversion of <i>x</i> from linear amplitude to MIDI velocity using a rule that
488 maps -60 dB to 1 and 0 dB to 127. The MIDI velocity varies linearly
489 with the square root of amplitude. The default value of <i>float</i> is
490 <code>nil</code> and the result is a <code>FIXNUM</code> clipped to fall in the
491 legal range of 1-127, but if a non-<code>nil</code> value
492 is provided, the result is a <code>FLONUM</code> that is not
493 rounded or clipped. The input parameter must be a <code>FIXNUM</code> or
494 <code>FLONUM</code>. Sounds are not allowed.<br><br>
495 <dt><code>log(<a name="index320"></a><a name="index321"></a><i>x</i>)</code> [SAL]<br>
496
497 <code>(log <i>x</i>)</code> [LISP]</dt>
498 <dd>Calculates the natural log of <i>x</i> (a <code>FLONUM</code>). (See <code>s-log</code> for a version that operates on signals.)<br><br>
499 <dt><code>set-control-srate(<a name="index322"></a><a name="index323"></a><i>rate</i>)</code> [SAL]<br>
500
501 <code>(set-control-srate <i>rate</i>)</code> [LISP]</dt>
502 <dd>Sets the default sampling rate for control signals to <i>rate</i> by setting <code>*default-control-srate*</code> and reinitializing the environment. Do not call this within any synthesis function (see the <code>control-srate-abs</code> transformation, Section <a href = "#98">Transformations</a>).<br><br>
503 <dt><code>set-sound-srate(<a name="index324"></a><a name="index325"></a><i>rate</i>)</code> [SAL]<br>
504
505 <code>(set-sound-srate <i>rate</i>)</code> [LISP]</dt>
506 <dd>Sets the default sampling rate for audio signals to <i>rate</i> by setting <code>*default-sound-srate*</code> and reinitializing the environment. Do not call this within any synthesis function (see the <code>sound-srate-abs</code> transformation, Section <a href = "#98">Transformations</a>).<br><br>
507 <dt><code>set-pitch-names(<a name="index326"></a><a name="index327"></a><a name="index328"></a>)</code> [SAL]<br>
508
509 <code>(set-pitch-names)</code> [LIS]</dt>
510 <dd>Initializes pitch
511 variables (<code>c0</code>, <code>cs0</code>, <code>df0</code>, <code>d0</code>, ... <code>b0</code>,
512 <code>c1</code>, ... <code>b7</code>). A440 (the default tuning) is represented by
513 the step 69.0, so the variable <code>a4</code> (fourth octave A) is set to 69.0.
514 You can change the tuning by
515 setting <code>*A4-Hertz*</code><a name="index329"></a><a name="index330"></a><a name="index331"></a> to a
516 value (in Hertz) and calling <code>set-pitch-names</code> to reinitialize the pitch
517 variables. Note that this will result in non-integer step values. It does not
518 alter the mapping from step values to frequency. There is no built-in
519 provision for stretched scales or non-equal temperament, although users
520 can write or compute any desired fractional step values.<br><br>
521 <dt><code>step-to-hz(<a name="index332"></a><i>pitch</i>)</code> [SAL]<br>
522
523 <code>(step-to-hz <i>pitch</i>)</code> [LISP]</dt>
524 <dd>Returns a frequency in hz
525 for <i>pitch</i>, a step number or a <code>SOUND</code> type representing a time-varying step number. The result is a <code>FLONUM</code> if <i>pitch</i> is a number, and a <code>SOUND</code> if <i>pitch</i> is a <code>SOUND</code>. See also <code>hz-to-step</code> (above).<br><br>
526 <dt><code>get-ioi(<a name="index333"></a><a name="index334"></a><i>dur</i>)</code> [SAL]<br>
527
528 <code>(get-ioi <i>dur</i>)</code> [LISP]</dt>
529 <dd>Gets the duration of of
530 something starting at a local time of 0 and ending at a local time of
531 <i>dur</i>. For convenience, <code>*rslt*</code> is set to the global time
532 corresponding to local time zero. Note that sustain is ignored in this
533 calculation. The intent is to calculate the nominal start time of the
534 next event in a sequence (or the logical stop time of the current event)
535 rather than the actual sound duration of the current event.<br><br>
536 <dt><code>get-duration(<a name="index335"></a><i>dur</i>)</code> [SAL]<br>
537
538 <code>(get-duration <i>dur</i>)</code> [LISP]</dt>
539 <dd>Gets the actual duration of of something starting at a local time of 0 and ending at a local time of <i>dur</i> times the current sustain. For convenience, <code>*rslt*</code> is set to the global time corresponding to local time zero. See also <code>get-ioi</code> (above).<br><br>
540 <dt><code>get-loud(<a name="index336"></a>)</code> [SAL]<br>
541
542 <code>(get-loud)</code> [LISP]</dt>
543 <dd>Gets the current value of the <code>*loud*</code> environment variable. If <code>*loud*</code> is a signal, it is evaluated at local time 0 and a number (<code>FLONUM</code>) is returned.<br><br>
544 <dt><code>get-sustain(<a name="index337"></a>)</code> [SAL]<br>
545
546 <code>(get-sustain)</code> [LISP]</dt>
547 <dd>Gets the current value of the <code>*sustain*</code> environment variable. If <code>*sustain*</code> is a signal, it is evaluated at local time 0 and a number (<code>FLONUM</code>) is returned.<br><br>
548 <dt><code>get-transpose(<a name="index338"></a>)</code> [SAL]<br>
549
550 <code>(get-transpose)</code> [LISP]</dt>
551 <dd>Gets the current value of the <code>*transpose*</code> environment variable. If <code>*transpose*</code> is a signal, it is evaluated at local time 0 and a number (<code>FLONUM</code>) is returned.<br><br>
552 <dt><code>get-warp(<a name="index339"></a>)</code> [SAL]<br>
553
554 <code>(get-warp)</code> [LISP]</dt>
555 <dd>Gets a function corresponding to
556 the current value of the <code>*warp*</code> environment variable. For
557 efficiency, <code>*warp*</code> is stored in three parts representing a shift,
558 a scale factor, and a continuous warp function. <code>Get-warp</code> is used
559 to retrieve a signal that maps logical time to real time. This signal
560 combines the information of all three components of <code>*warp*</code> into
561 a single signal. If the continuous warp function component is not present
562 (indicating that the time warp is a simple combination of <code>at</code>
563 and <code>stretch</code> transformations), an error is raised. This
564 function is mainly for internal system use. In the future,
565 <code>get-warp</code> will probably be reimplemented to always return
566 a signal and never raise an error.<br><br>
567 <dt><code>local-to-global(<a name="index340"></a><i>local-time</i>)</code> [SAL]<br>
568
569 <code>(local-to-global <i>local-time</i>)</code> [LISP]</dt>
570 <dd>Converts a score (local) time to a real (global) time according to the current environment.<br><br>
571 <dt><code>round(<a name="index341"></a><a name="index342"></a><i>x</i>)</code> [SAL]<br>
572
573 <code>(round <i>x</i>)</code> [LISP]</dt>
574 <dd>Round <i>x</i> to the nearest integer. If <i>x</i> is <i>n</i> + 0.5, where <i>n</i> is an integer, then return <i>n</i> + 1, even if <i>n</i> is negative.<br><br>
575 <dt><code>snd-set-latency(<a name="index343"></a><a name="index344"></a><i>latency</i>)</code> [SAL]<br>
576
577 <code>(snd-set-latency <i>latency</i>)</code> [LISP]</dt>
578 <dd>Set the latency requested when Nyquist plays sound to
579 <i>latency</i>, a <code>FLONUM</code>. The previous value is returned. The default is 0.3 seconds. To avoid glitches, the latency should be
580 greater than the time required for garbage collection and message printing and any other system activity external to Nyquist.<br><br>
581 <dt><code>vel-to-db(<a name="index345"></a><i>x</i>)</code> [SAL]<br>
582
583 <code>(vel-to-db <i>x</i>)</code> [LISP]</dt>
584 <dd>Returns the conversion
585 of <i>x</i> from MIDI velocity to decibels using a rule that maps MIDI
586 velocity 1 to -60 dB and 127 to 0 dB. The amplitude is proportional to
587 the square of MIDI velocity. The input <i>x</i> can be a <code>FIXNUM</code> or
588 <code>FLONUM</code> but not a sound. The result is a <code>FLONUM</code>.<br><br>
589 <dt><code>vel-to-linear(<a name="index346"></a><i>x</i>)</code> [SAL]<br>
590
591 <code>(vel-to-linear <i>x</i>)</code> [LISP]</dt>
592 <dd>Returns
593 the conversion of <i>x</i> from MIDI velocity to linear amplitude
594 ratio using a rule that maps MIDI
595 velocity 1 to -60 dB (0.001) and 127 to unity gain. The amplitude is proportional to
596 the square of MIDI velocity. The input <i>x</i> can be a <code>FIXNUM</code> or
597 <code>FLONUM</code> but not a sound. The result is a <code>FLONUM</code>.
598 </dd></dl><a name = "88"><h3>Behaviors</h3></a><a name="index347"></a><a name = "89"><h4>Using Previously Created Sounds</h4></a>
599 <p>These behaviors take a sound and transform that sound according to the
600 environment. These are useful when writing code to make
601 a high-level function from a low-level function, or when cuing sounds
602 which were previously created:
603 <dl>
604 <dt>
605 <code>cue(<a name="index348"></a><i>sound</i>)</code> [SAL]<br>
606
607 <code>(cue <i>sound</i>)</code> [LISP]</dt>
608 <dd>Applies <code>*loud*</code>, the starting time from <code>*warp*</code>, <code>*start*</code>,
609 and <code>*stop*</code> to <i>sound</i>.</p>
610 <dt><code>cue-file(<a name="index349"></a><i>filename</i>)</code> [SAL]<br>
611
612 <code>(cue-file <i>filename</i>)</code> [LISP]</dt>
613 <dd>Same as <code>cue</code>, except
614 the sound comes from the named file, samples from which are coerced to the current default <code>*sound-srate*</code> sample rate.<br><br>
615 <dt><code>sound(<a name="index350"></a><i>sound</i>)</code> [SAL]<br>
616
617 <code>(sound <i>sound</i>)</code> [LISP]</dt>
618 <dd>Applies <code>*loud*</code>, the starting
619 time and (possibly continuously varying) stretching from <code>*warp*</code>,
620 <code>*start*</code>, and <code>*stop*</code> to <i>sound</i>.<br><br>
621 <dt><code>control(<a name="index351"></a><i>sound</i>)</code> [SAL]<br>
622
623 <code>(control <i>sound</i>)</code> [LISP]</dt>
624 <dd>This function is identical to
625 <code>sound</code>, but by convention is used when <i>sound</i> is a control signal
626 rather than an audio signal.
627 </dd></dl><a name = "90"><h4>Sound Synthesis</h4></a>
628 <p>These functions provide musically interesting creation behaviors that
629 react to their environment; these are the &ldquo;unit generators&rdquo; of Nyquist:</p>
630 <dl>
631 <dt>
632 <code>const(<a name="index352"></a><a name="index353"></a><i>value</i> [, <i>duration</i>])</code> [SAL]<br>
633
634 <code>(const <i>value</i> [<i>duration</i>])</code> [LISP]</dt>
635 <dd>Creates a constant function at the <code>*control-srate*</code>. Every sample has the given <i>value</i>, and the default <i>duration</i> is 1.0. See also <code>s-rest</code>, which is equivalent to calling <code>const</code> with zero, and note that you can pass scalar constants (numbers) to <code>sim</code>, <code>sum</code>, and <code>mult</code> where they are handled more efficiently than constant functions.<br><br>
636 <dt><code>env(<a name="index354"></a><i>t<sub>1</sub></i>, <i>t<sub>2</sub></i>, <i>t<sub>4</sub></i>, <i>l<sub>1</sub></i>, <i>l<sub>2</sub></i>, <i>l<sub>3</sub></i>,
637 [<i>dur</i>])</code> [SAL]<br>
638
639 <code>(env <i>t<sub>1</sub></i> <i>t<sub>2</sub></i> <i>t<sub>4</sub></i> <i>l<sub>1</sub></i> <i>l<sub>2</sub></i> <i>l<sub>3</sub></i> <i>dur</i>)</code> [LISP]</dt>
640 <dd>Creates a 4-phase envelope.
641 <i>t<sub><i>i</i></sub></i> is the duration of phase <i>i</i>, and <i>l<sub><i>i</i></sub></i>
642 is the final level of phase <i>i</i>. <i>t<sub>3</sub></i> is implied by the duration
643 <i>dur</i>, and <i>l<sub>4</sub></i> is <code>0.0</code>. If <i>dur</i> is not supplied, then
644 <code>1.0</code> is assumed. The envelope duration is the product of <i>dur</i>,
645 <code>*stretch*</code>, and <code>*sustain*</code>. If
646 <i>t<sub>1</sub></i> + <i>t<sub>2</sub></i> + 2ms + <i>t<sub>4</sub></i> is greater than the envelope
647 duration, then a two-phase envelope is
648 substituted that has an attack/release time ratio of <i>t<sub>1</sub></i>/<i>t<sub>4</sub></i>.
649 The sample rate of the returned sound is <code>*control-srate*</code>. (See
650 <code>pwl</code> for a more general piece-wise linear function generator.)
651 The effect of time warping is to warp the starting time and ending time.
652 The intermediate breakpoints are then computed as described above.<br><br>
653 <dt><code>exp-dec(<a name="index355"></a><a name="index356"></a><i>hold</i>, <i>halfdec</i>, <i>length</i>)</code> [SAL]<br>
654
655 <code>(exp-dec <i>hold</i> <i>halfdec</i> <i>length</i>)</code> [LISP]</dt>
656 <dd>This convenient envelope shape is a special case of <code>pwev</code> (see Section <a href = "#92">Piece-wise Approximations</a>). The envelope starts at 1 and is constant for <i>hold</i> seconds. It then decays with a half life of <i>halfdec</i> seconds until <i>length</i>. (The total duration is <i>length</i>.) In other words, the amplitude falls by half each <i>halfdec</i> seconds. When stretched, this envelope scales linearly, which means the hold time increases and the half decay time increases.<br><br>
657 <dt>
658 <code>force-srate(<a name="index357"></a><a name="index358"></a><a name="index359"></a><i>srate</i>, <i>sound</i>)</code> [SAL]<br>
659
660 <code>(force-srate <i>srate</i> <i>sound</i>)</code> [LISP]</dt>
661 <dd>Returns a sound which is up- or
662 down-sampled to <i>srate</i>. Interpolation is linear, and no prefiltering is
663 applied in the down-sample case, so aliasing may occur. See also
664 <code>resample</code>.<br><br>
665 <dt><code>lfo(<a name="index360"></a><a name="index361"></a><i>freq</i> [, <i>duration</i>, <i>table</i>, <i>phase</i>])</code> [SAL]<br>
666
667 <code>(lfo <i>freq</i> <i>duration</i> <i>table</i> <i>phase</i>)</code> [LISP]</dt>
668 <dd>Just
669 like <code>osc</code> (below)
670 except this computes at the <code>*control-srate*</code> and frequency
671 is specified in Hz. Initial <i>phase</i> is specified in degrees, defaulting to zero.
672 The <code>*transpose*</code> and <code>*sustain*</code> is not
673 applied. The effect of time warping is to warp the starting and ending
674 times. The signal itself will have a constant unwarped frequency.<br><br>
675 <dt><code>fmlfo(<a name="index362"></a><i>freq</i> [, <i>table</i>, <i>phase</i>])</code> [SAL]<br>
676
677 <code>(fmlfo <i>freq</i> [<i>table</i> <i>phase</i>])</code> [LISP]</dt>
678 <dd>A low-frequency oscillator
679 that computes at the <code>*control-srate*</code> using a sound to specify a time-varying
680 frequency in Hz. Initial <i>phase</i> is a <code>FLONUM</code> in degrees. The duration of the result is determined by <i>freq</i>.<br><br>
681 <dt><code>maketable(<a name="index363"></a><i>sound</i>)</code> [SAL]<br>
682
683 <code>(maketable <i>sound</i>)</code> [LISP]</dt>
684 <dd>Assumes that
685 the samples in <i>sound</i> constitute one period of a wavetable, and returns a wavetable
686 suitable for use as the <i>table</i> argument to the <code>osc</code> function (see
687 below). Currently, tables are limited to 100,000,000 samples. This limit is the compile-time constant <code>max_table_len</code> set in <code>sound.h</code>. A wavetable is a list of the form
688 <blockquote>
689 (<i>sound</i> <i>pitch-number</i> <i>periodic</i>)</blockquote>
690 where the first element is a sound, the second is the pitch of the sound
691 (this is not redundant, because the sound may represent any number of
692 periods), and the third element is <code>T</code> if the sound is one period of
693 a periodic signal, or <code>nil</code> if the sound is a sample that should not
694 be looped. Wavetables are used by <code>osc</code>, <code>osc</code>, <code>hzosc</code>,
695 <code>amosc</code>, <code>fmosc</code>, <code>lfo</code>, and <code>fmlfo</code>.<br><br>
696 <dt><code>build-harmonic(<a name="index364"></a><a name="index365"></a><i>n</i>, <i>table-size</i>)</code> [SAL]<br>
697
698 <code>(build-harmonic <i>n</i> <i>table-size</i>)</code> [LISP]</dt>
699 <dd>Intended for
700 constructing wavetables<a name="index366"></a><a name="index367"></a>, this function returns a sound of length <i>table-size</i>
701 samples containing <i>n</i> periods of a sinusoid. These can be scaled and
702 summed to form a waveform with the desired harmonic content. See <a href = "part2.html#11">Non-Sinusoidal Waveforms</a> for an example. A scaled sum of these harmonics can be passed to <code>maketable</code> to construct a wavetable suitable for <code>osc</code> and other oscillators.<br><br>
703 <dt><code>control-warp(<a name="index368"></a><i>warp-fn</i>, <i>signal</i>, [<i>wrate</i>])</code> [SAL]<br>
704
705 <code>(control-warp <i>warp-fn</i> <i>signal</i> <i>wrate</i>)</code> [LISP]</dt>
706 <dd>Applies a
707 warp function <i>warp-fn</i> to <i>signal</i> using function composition. If <i>wrate</i> is omitted, linear
708 interpolation is used. <i>warp-fn</i> is a mapping from score (logical) time
709 to real time, and <i>signal</i> is a function from score time to real values.
710 The result is a function from real time to real values at a sample rate of
711 <code>*control-srate*</code>. See <code>sound-warp</code> for an explanation of
712 <i>wrate</i> and high-quality warping.<br><br>
713 <dt>
714 <code>mult(<a name="index369"></a><i>beh<sub>1</sub></i>, <i>beh<sub>2</sub></i>, <span style="font-style:normal">...</span>)</code> [SAL]<br>
715
716 <code>(mult <i>beh<sub>1</sub></i> <i>beh<sub>2</sub> <span style="font-style:normal">...</span></i>)</code> [LISP]</dt>
717 <dd>Returns the product of
718 behaviors. The arguments may also be numbers, in which case simple multiplication is performed. If a number and sound are mixed, the <code>scale</code> function is used to scale the sound by the number. When sounds are multiplied, the resulting sample rate is the maximum sample rate of the factors.<br><br>
719 <dt><code>prod(<a name="index370"></a><i>beh<sub>1</sub></i>, <i>beh<sub>2</sub></i>, <span style="font-style:normal">...</span>)</code> [SAL]<br>
720
721 <code>(prod <i>beh<sub>1</sub></i> <i>beh<sub>2</sub></i> <span style="font-style:normal">...</span>)</code> [LISP]</dt>
722 <dd>Same as <code>mult</code>.<br><br>
723 <dt>
724 <code>pan(<a name="index371"></a><a name="index372"></a><i>sound</i>, <i>where</i>)</code> [SAL]<br>
725
726 <code>(pan <i>sound</i> <i>where</i>)</code> [LISP]</dt>
727 <dd>Pans <i>sound</i> (a behavior) according to <i>where</i> (another behavior or a number). <i>Sound</i> must be monophonic. <i>Where</i> may be a monophonic sound (e.g. <code>(ramp)</code> or simply a number (e.g. <code>0.5</code>). In either case, <i>where</i> should range from 0 to 1, where 0 means pan completely left, and 1 means pan completely right. For intermediate values, the sound to each channel is scaled linearly. Presently, <code>pan</code> does not check its arguments carefully.<br><br>
728 <dt><code>prod(<a name="index373"></a><i>beh<sub>1</sub></i>, <i>beh<sub>2</sub></i>, <span style="font-style:normal">...</span>)</code> [SAL]<br>
729
730 <code>(prod <i>beh<sub>1</sub></i> <i>beh<sub>2</sub></i> <span style="font-style:normal">...</span>)</code> [LISP]</dt>
731 <dd>Same as <code>mult</code>.<br><br>
732 <dt>
733 <code>resample(<a name="index374"></a><i>sound</i>, <i>srate</i>)</code> [SAL]<br>
734
735 <code>(resample <i>sound</i> <i>srate</i>)</code> [LISP]</dt>
736 <dd>Similar to <code>force-srate</code>, except
737 high-quality interpolation is used to prefilter and reconstruct the signal
738 at the new sample rate. Also, the result is scaled by 0.95 to reduce problems with
739 clipping. (See also <code>sound-warp</code>.)<br><br>
740 <dt>
741 <code>scale(<a name="index375"></a><i>scale</i>, <i>sound</i>)</code> [SAL]<br>
742
743 <code>(scale <i>scale</i> <i>sound</i>)</code> [LISP]</dt>
744 <dd>Scales the amplitude of <i>sound</i> by the factor <i>scale</i>. Identical function to <code>snd-scale</code>, except that it handles multichannel sounds. Sample rates, start times, etc. are taken from <i>sound</i>.<br><br>
745 <dt><code>scale-db(<a name="index376"></a><i>db</i>, <i>sound</i>)</code> [SAL]<br>
746
747 <code>(scale-db <i>db</i> <i>sound</i>)</code> [LISP]</dt>
748 <dd>Scales the amplitude of <i>sound</i> by the factor <i>db</i>, expressed in decibels. Sample rates, start times, etc. are taken from <i>sound</i>.<br><br>
749 <dt><code>scale-srate(<a name="index377"></a><i>sound</i>, <i>scale</i>)</code> [SAL]<br>
750
751 <code>(scale-srate <i>sound</i> <i>scale</i>)</code> [LISP]</dt>
752 <dd>Scales the sample rate of <i>sound</i> by <i>scale</i> factor. This has the effect of linearly shrinking or stretching time (the sound is not upsampled or downsampled). This is a special case of <code>snd-xform</code> (see Section <a href = "#103">Signal Operations</a>).<br><br>
753 <dt><code>shift-time(<a name="index378"></a><i>sound</i>, <i>shift</i>)</code> [SAL]<br>
754
755 <code>(shift-time <i>sound</i> <i>shift</i>)</code> [LISP]</dt>
756 <dd>Shift <i>sound</i>
757 by <i>shift</i> seconds. If the sound is
758
759 f(t), then the result is
760
761 f(t - shift).
762 See Figure <a href = "#90">5</a>. This is a special
763 case of <code>snd-xform</code> (see Section <a href = "#103">Signal Operations</a>).
764 </dd></dl>
765 <hr>
766 <blockquote>
767 </blockquote>
768 <img src="fig5.gif"><br><br>
769
770 <p><b>Figure 5: </b>The <code>shift-time</code> function shifts a sound in time
771 according to its <i>shift</i> argument.
772
773 </p>
774 <hr>
775 <dl>
776 <dt>
777 <code>sound-warp(<a name="index379"></a><i>warp-fn</i>, <i>signal</i> [, <i>wrate</i>])</code> [SAL]<br>
778
779 <code>(sound-warp <i>warp-fn</i> <i>signal</i> [<i>wrate</i>])</code> [LISP]</dt>
780 <dd>Applies a
781 warp function <i>warp-fn</i> to <i>signal</i> using function composition. If the optional parameter <i>wrate</i> is omitted or NIL, linear
782 interpolation is used. Otherwise, high-quality sample interpolation is used, and the
783 result is scaled by 0.95 to reduce problems with clipping (interpolated samples can
784 exceed the peak values of the input samples.)
785 <i>warp-fn</i> is a mapping from score (logical) time
786 to real time, and <i>signal</i> is a function from score time to real values.
787 The result is a function from real time to real values at a sample rate of <code>*sound-srate*</code>.
788 See also <code>control-warp</code>.
789
790 If <i>wrate</i> is not NIL, it must be a number. The parameter indicates that
791 high-quality resampling should be used and specifies the sample rate for the
792 inverse of <i>warp-fn</i>. Use the lowest number you can.
793 (See below for details.) Note that high-quality resampling is
794 much slower than linear interpolation.
795
796 To perform high-quality resampling by a fixed ratio, as opposed to a
797 variable ratio allowed in <code>sound-warp</code>, use <code>scale-srate</code> to
798 stretch or shrink the sound, and then <code>resample</code> to restore the
799 original sample rate.
800
801 <code>Sound-warp</code> and <code>control-warp</code> both take the inverse of
802 <i>warp-fn</i> to get a function from real time to score time. Each sample
803 of this inverse is thus a score time; <i>signal</i> is evaluated at each of
804 these score times to yield a value, which is the desired result. The
805 sample rate of the inverse warp function is somewhat arbitrary. With linear
806 interpolation, the inverse warp function sample rate is taken to be the
807 output sample rate. Note, however, that the samples of the inverse warp
808 function are stored as 32-bit floats, so they have limited precision. Since
809 these floats represent sample times, rounding can be a problem. Rounding
810 in this case is equivalent to adding jitter to the sample times. Nyquist
811 ignores this problem for ordinary warping, but for high-quality warping, the
812 jitter cannot be ignored.
813
814 The solution is to use a rather low sample rate
815 for the inverse warp function. <code>Sound-warp</code> can then linearly
816 interpolate this signal using double-precision floats to minimize jitter
817 between samples. The sample rate is a compromise: a low sample rate
818 minimizes jitter, while a high sample rate does a better job of capturing
819 detail (e.g. rapid fluctuations) in the warp function. A good rule of thumb
820 is to use at most 1,000 to 10,000 samples for the inverse warp function. For
821 example, if the result will be 1 minute of sound, use a sample rate of
822 3000 samples / 60 seconds = 50 samples/second. Because Nyquist has no
823 advance information about the warp function, the inverse warp function
824 sample rate must be provided as a parameter. When in doubt, just try
825 something and let your ears be the judge.<br><br>
826 <dt><code>integrate(<a name="index380"></a><a name="index381"></a><i>signal</i>)</code> [SAL]<br>
827
828 <code>(integrate <i>signal</i>)</code> [LISP]</dt>
829 <dd>Computes the integral of <i>signal</i>. The start time, sample rate, etc. are taken from <i>signal</i>.<br><br>
830 <dt><code>slope(<a name="index382"></a><a name="index383"></a><a name="index384"></a><i>signal</i>)</code> [SAL]<br>
831
832 <code>(slope <i>signal</i>)</code> [LISP]</dt>
833 <dd>Computes the first derivative (slope) of <i>signal</i>. The start time, sample rate, etc. are taken from <i>signal</i>.
834 </dd></dl><a name = "91"><h5>Oscillators</h5></a><dl>
835 <dt>
836 <code>osc(<a name="index385"></a><i>pitch</i> [, <i>duration</i>, <i>table</i>, <i>phase</i>])</code> [SAL]<br>
837
838 <code>(osc <i>pitch</i> [<i>duration</i> <i>table</i> <i>phase</i>])</code> [LISP]</dt>
839 <dd>Returns
840 a sound which
841 is the <i>table</i> oscillated at <i>pitch</i> for the given <i>duration</i>,
842 starting with the <i>phase</i> (in degrees).
843 Defaults are: <i>duration</i> <code>1.0</code>
844 (second), <i>table</i> <code>*table*</code>,
845 <i>phase</i> <code>0.0</code>. The default value of <code>*table*</code> is a
846 sinusoid. Duration is stretched by <code>*warp*</code> and <code>*sustain*</code>,
847 amplitude is nominally 1, but scaled by <code>*loud*</code> (in dB), the
848 start time is logical time 0, transformed by <code>*warp*</code>, and
849 the sample rate is <code>*sound-srate*</code>.
850 The effect of time-warping is to warp the starting and ending
851 times only; the signal has a constant unwarped frequency.<br>
852
853 <b><i>Note 1:</i></b> A <code>table</code> is 3-element list. See <code>maketable</code> for a detailed
854 description.<br>
855
856 <b><i>Note 2:</i></b> in the current implementation, it is assumed that the
857 output should be periodic. See <code>snd-down</code> and <code>snd-up</code> for resampling one-shot sounds to a desired sample rate. A future version of <code>osc</code>
858 will handle both cases.<br>
859
860 <b><i>Note 3:</i></b> When <code>osc</code> is called, memory is allocated for the table, and samples are copied from the sound (the first element of the list which is the <i>table</i> parameter) to the memory. Every instance of <code>osc</code> has a private copy of the table, so the total storage can become large in some cases, for example in granular synthesis with many instances of <code>osc</code>. In some cases, it may make sense to use <code>snd-flatten</code> (see Section <a href = "#86">Accessing and Creating Sound</a>) to cause the sound to be fully realized, after which the <code>osc</code> and its table memory can be reclaimed by garbage collection. The <code>partial</code> function (see below) does not need a private table and does not use much space.<br><br>
861 <dt>
862 <code>partial(<a name="index386"></a><i>pitch</i>, <i>env</i>)</code> [SAL]<br>
863
864 <code>(partial <i>pitch</i> <i>env</i>)</code> [LISP]</dt>
865 <dd>Returns a sinusoid at
866 the indicated pitch; the sound is multiplied by <i>env</i>. The start time and
867 duration are taken from <i>env</i>, which is of course subject to
868 transformations. The sample rate is <code>*sound-srate*</code>. The <code>partial</code>
869 function is faster than <code>osc</code>.<br><br>
870 <dt>
871 <code>sine(<a name="index387"></a><i>pitch</i> [, <i>duration</i>])</code> [SAL]<br>
872
873 <code>(sine <i>pitch</i> [<i>duration</i>])</code> [LISP]</dt>
874 <dd>Returns a sinusoid at
875 the indicated pitch. The sample rate is <code>*sound-srate*</code>.
876 This function is like <code>osc</code> with
877 respect to transformations. The <code>sine</code> function is faster than
878 <code>osc</code>.<br><br>
879 <dt><code>hzosc(<a name="index388"></a><i>hz</i> [, <i>table</i>, <i>phase</i>])</code> [SAL]<br>
880
881 <code>(hzosc <i>hz</i> [<i>table</i> <i>phase</i>])</code> [LISP]</dt>
882 <dd>Returns a sound
883 which is the <i>table</i> oscillated at <i>hz</i> starting at <i>phase</i> degrees. The
884 default <i>table</i> is <code>*table*</code> and the default <i>phase</i> is <i>0.0</i>
885 degrees. The default duration is <code>1.0</code>, but this is stretched as
886 in <code>osc</code> (see above). The <i>hz</i> parameter may be a <code>SOUND</code>, in
887 which case the duration of the result is the duration of <i>hz</i>. The
888 sample rate is <code>*sound-srate*</code>.<br><br>
889 <dt><code>osc-saw(<a name="index389"></a><a name="index390"></a><i>hz</i>)</code> [SAL]<br>
890
891 <code>(osc-saw <i>hz</i>)</code> [LISP]</dt>
892 <dd>Returns a sawtooth waveshape at the indicated frequency (in Hertz). The sample rate is <code>*sound-srate*</code>. The <i>hz</i> parameter may be a sound as in <i>hzosc</i> (see above).<br><br>
893 <dt><code>osc-tri(<a name="index391"></a><a name="index392"></a><i>hz</i>)</code> [SAL]<br>
894
895 <code>(osc-tri <i>hz</i>)</code> [LISP]</dt>
896 <dd>Returns a triangle waveshape at the indicated frequency (in Hertz). The sample rate is <code>*sound-srate*</code>. The <i>hz</i> parameter may be a sound as in <i>hzosc</i> (see above).<br><br>
897 <dt><code>osc-pulse(<a name="index393"></a><a name="index394"></a><a name="index395"></a><a name="index396"></a><i>hz</i>, <i>bias</i> [, <i>compare-shape</i>])</code> [SAL]<br>
898
899 <code>(osc-pulse <i>hz</i> <i>bias</i> [<i>compare-shape</i>])</code> [LISP]</dt>
900 <dd>Returns a square pulse with variable width at the indicated frequency (in Hertz). The <i>bias</i> parameter controls the pulse width and should be between <code>-1</code> and <code>+1</code>, giving a pulse width from 0% (always at <code>-1</code>) to 100% (always at <code>+1</code>). When bias is zero, a square wave is generated. Bias may be a <code>SOUND</code> to create varying pulse width. If bias changes rapidly, strange effects may occur. The optional <i>compare-shape</i> defaults to a hard step at zero, but other shapes may be used to achieve non-square pulses. The <code>osc-pulse</code> behavior is written in terms of other behaviors and defined in the file <code>nyquist.lsp</code> using just a few lines of code. Read the code for the complete story.<br><br>
901 <dt>
902 <code>amosc(<a name="index397"></a><i>pitch</i>, <i>modulation</i> [, <i>table</i>,
903 <i>phase</i>])</code> [SAL]<br>
904
905 <code>(amosc <i>pitch</i> <i>modulation</i> [<i>table</i> <i>phase</i>])</code> [LISP]</dt>
906 <dd>Returns a
907 sound which is <i>table</i> oscillated at <i>pitch</i>. The output
908 is multiplied by <i>modulation</i>
909 for the duration of the sound <i>modulation</i>.
910 <i>osc-table</i> defaults to
911 <code>*table*</code>, and <i>phase</i> is the starting phase (default 0.0 degrees)
912 within <i>osc-table</i>. The sample rate is <code>*sound-srate*</code>. <br><br>
913 <dt>
914 <code>fmosc(<a name="index398"></a><i>pitch</i>, <i>modulation</i> [, <i>table</i>,
915 <i>phase</i>])</code> [SAL]<br>
916
917 <code>(fmosc <i>pitch</i> <i>modulation</i> [<i>table</i> <i>phase</i>])</code> [LISP]</dt>
918 <dd>Returns a
919 sound which is <i>table</i> oscillated at <i>pitch</i> plus <i>modulation</i>
920 for the duration of the sound <i>modulation</i>.
921 <i>osc-table</i> defaults to
922 <code>*table*</code>, and <i>phase</i> is the starting phase (default 0.0 degrees)
923 within <i>osc-table</i>. The <i>modulation</i>
924 is expressed in hz, e.g. a sinusoid modulation signal with an
925 amplitude of 1.0 (2.0 peak to peak), will cause a +/- 1.0 hz
926 frequency deviation in <i>sound</i>. Negative frequencies are correctly
927 handled. The sample rate is <code>*sound-srate*</code>. <br><br>
928 <dt>
929 <code>fmfb(<a name="index399"></a><a name="index400"></a><i>pitch</i>, <i>index</i> [, <i>dur</i>])</code> [SAL]<br>
930
931 <code>(fmfb <i>pitch</i> <i>index</i> [<i>dur</i>])</code> [LISP]</dt>
932 <dd>Returns
933 a sound generated by feedback FM synthesis. The <i>pitch</i> parameter
934 (given in the usual half-step units)
935 controls the fundamental frequency. The <i>index</i> is the amount of
936 feedback, which may be a <code>SOUND</code> or a <code>FLONUM</code>. If <i>index</i> is
937 a <code>FLONUM</code>, <i>dur</i> must be provided (a <code>FLONUM</code>) to specify
938 the duration. Otherwise, <i>dur</i> is ignored if present and the duration is
939 determined by that of <i>index</i>. The sample rate is <code>*sound-srate*</code>.
940 A sinusoid table is used.
941 If <i>index</i> is below 1.1, this generates a sawtooth-like waveform.<br><br>
942 <dt>
943 <code>buzz(<a name="index401"></a><i>n</i>, <i>pitch</i>, <i>modulation</i>)</code> [SAL]<br>
944
945 <code>(buzz <i>n</i> <i>pitch</i> <i>modulation</i>)</code> [LISP]</dt>
946 <dd>Returns a
947 sound with <i>n</i> harmonics of equal amplitude and a total amplitude
948 of 1.0, using a well-known function of two cosines. If <i>n</i> (an integer)
949 is less than 1, it is set to 1. Aliasing will occur if <i>n</i> is too large.
950 The <i>pitch</i>specifies the fundamental frequency (a number, in steps)
951 assuming no modulation.
952 The duration is
953 determined by the duration of the sound <i>modulation</i>, which is a
954 frequency modulation term expressed in Hz (see Section <a href = "#91">Oscillators</a>).
955 Negative frequencies are correctly handled.
956 The sample rate is <code>*sound-srate*</code>.<br><br>
957 <dt>
958 <code>pluck(<a name="index402"></a><a name="index403"></a><a name="index404"></a><a name="index405"></a><i>pitch</i> [, <i>duration</i>, <i>final-amplitude</i>])</code> [SAL]<br>
959
960 <code>(pluck <i>pitch</i> [<i>duration</i> <i>final-amplitude</i>])</code> [LISP]</dt>
961 <dd>Returns a sound at the
962 given <i>pitch</i> created using a modified Karplus-Strong plucked string
963 algorithm. The tone decays from an amplitude of about 1.0 to about
964 <i>final-amplitude</i> in <i>duration</i> seconds. The default values are to
965 decay to 0.001 (-60dB) in 1 second. The sample rate is <code>*sound-srate*</code>.<br><br>
966 <dt>
967 <code>siosc(<a name="index406"></a><a name="index407"></a><i>pitch</i>,
968 <i>modulation</i>, <i>tables</i>)</code> [SAL]<br>
969
970 <code>(siosc <i>pitch</i> <i>modulation</i> <i>tables</i>)</code> [LISP]</dt>
971 <dd>Returns a sound constructed by
972 interpolating through a succession of periodic waveforms. The frequency is
973 given (in half steps) by <i>pitch</i> to which a <i>modulation</i> signal (in hz)
974 is added, exactly as in <code>fmosc</code>. The <i>tables</i> specify a list of
975 waveforms as follows: (<i>table0</i> <i>time1</i> <i>table2</i> ... <i>timeN</i>
976 <i>tableN</i>), where each <i>table</i> is a sound representing one period. Each
977 <i>time</i> is a time interval measured from the starting time. The time is
978 scaled by the nominal duration (computed using <code>(local-to-global
979 (get-sustain))</code>) to get the actual time. Note that this implies linear
980 stretching rather than continuous timewarping of the interpolation or the
981 breakpoints. The waveform is <i>table0</i> at the starting time, <i>table1</i>
982 after <i>time1</i> (scaled as described), and so on. The duration and logical
983 stop time is given by <i>modulation</i>. If <i>modulation</i> is shorter than
984 <i>timeN</i>, then the full sequence of waveforms is not used. If
985 <i>modulation</i> is longer than <i>timeN</i>, <i>tableN</i> is used after <i>timeN</i>
986 without further interpolation.<br><br>
987 <dt>
988 <code>sampler(<a name="index408"></a><i>pitch</i>, <i>modulation</i>
989 [, <i>sample</i>, <i>npoints</i>])</code> [SAL]<br>
990
991 <code>(sampler <i>pitch</i> <i>modulation</i> [<i>sample</i> <i>npoints</i>])</code> [LISP]</dt>
992 <dd>Returns a sound constructed by reading a sample from
993 beginning to end and then splicing on copies of the same sound from
994 a loop point to the end.
995 The <i>pitch</i> and <i>modulation</i> parameters are used as in <code>fmosc</code>
996 described above. The optional <i>sample</i> (which defaults to 2048-point
997 sinusoid) is a list of the form
998 <blockquote>
999 (<i>sound</i> <i>pitch-number</i> <i>loop-start</i>)</blockquote> where the first element is a sound containing the sample, the second is the
1000 pitch of the sample, and the third element is the time of the loop point. If
1001 the loop point is not in the bounds of the sound, it is set to zero.
1002 The optional <i>npoints</i> specifies how many points should be used for sample
1003 interpolation. Currently this parameter defaults to 2 and only 2-point
1004 (linear) interpolation is implemented. It is an error to modulate such that the frequency
1005 is negative. Note also that the loop point may be fractional.
1006 The sample rate is <code>*sound-srate*</code>.
1007 </dd></dl>
1008 <a name = "92"><h5>Piece-wise Approximations</h5></a><a name="index409"></a><a name="index410"></a><a name="index411"></a> There are a number of related behaviors for piece-wise approximations to functions. The simplest of these, <code>pwl</code> was mentioned earlier in the manual. It takes a list of breakpoints, assuming an initial point at (0, 0), and a final value of 0. An analogous piece-wise exponential function, <code>pwe</code>, is provided. Its implicit starting and stopping values are 1 rather than 0 because exponential decays never reach zero. This inability to reach zero can be addressed by a pseudo-exponential function, <code>pwz</code>, whose design was borrowed from the ZynAddSubFx software synthesizer, where we add a small bias (0.01) to breakpoints, compute the exponential envelope between these new breakpoints, then subtract 0.01 so that the envelope can actually decay all the way to zero. These curves are very close to exponential (within 0.01) until they approach zero, where they become essentially linear. Like <code>pwl</code> (linear), the <code>pwz</code> envelopes assume an initial point at (0, 0) and a final value of 0. For amplitude envelopes, the <code>linear-attack</code> option for the <code>pwz</code> variants is suggested for a more natural-sounding envelope.
1009 <p>Each of these three forms has variants.
1010 You can specify the initial and final values (instead of taking the
1011 default). You can specify time in intervals rather than cummulative
1012 time. Finally, you can pass a list rather than an argument list. This leads to 24 versions:
1013 <pre><b>Piece-wise Linear Functions:</b>
1014 <i>Cummulative Time:</i>
1015 <i>Default initial point at (0, 0), final value at 0:</i>
1016 pwl
1017 pwl-list
1018 <i>Explicit initial value:</i>
1019 pwlv
1020 pwlv-list
1021 <i>Relative Time:</i>
1022 <i>Default initial point at (0, 0), final value at 0:</i>
1023 pwlr
1024 pwlr-list
1025 <i>Explicit initial value:</i>
1026 pwlvr
1027 pwlvr-list
1028
1029 <b>Piece-wise Exponential Functions:</b>
1030 <i>Cummulative Time:</i>
1031 <i>Default initial point at (0, 1), final value at 1:</i>
1032 pwe
1033 pwe-list
1034 <i>Explicit initial value:</i>
1035 pwev
1036 pwev-list
1037 <i>Relative Time:</i>
1038 <i>Default initial point at (0, 1), final value at 1:</i>
1039 pwer
1040 pwer-list
1041 <i>Explicit initial value:</i>
1042 pwevr
1043 pwevr-list
1044 <b>Piece-wise Pseudo-Exponential Functions with Bias:</b>
1045 <i>Cummulative Time:</i>
1046 <i>Default initial point at (0, 0), final value at 0:</i>
1047 pwz
1048 pwz-list
1049 <i>Explicit initial value:</i>
1050 pwzv
1051 pwzv-list
1052 <i>Relative Time:</i>
1053 <i>Default initial point at (0, 0), final value at 0:</i>
1054 pwzr
1055 pwzr-list
1056 <i>Explicit initial value:</i>
1057 pwzvr
1058 pwzvr-list
1059 </pre> </p>
1060
1061 <p></p>
1062
1063 <p></p>
1064
1065 <p></p>
1066 All of these functions are implemented in terms of <code>pwl</code> (see <code>nyquist.lsp</code> for the implementations. There are infinite opportunities for errors in these functions: if you leave off a data point, try to specify points in reverse order, try to create an exponential that goes to zero or negative values, or many other bad things, the behavior is not well-defined. Nyquist should not crash, but Nyquist does not necessarily attempt to report errors at this time.<dl>
1067 <dt>
1068
1069 <code>pwl(<a name="index412"></a><i>t<sub>1</sub></i>, <i>l<sub>1</sub></i>, <i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>, <span style="font-style:normal">...</span> <i>t<sub>n</sub></i>)</code> [SAL]<br>
1070
1071 <code>(pwl <i>t<sub>1</sub></i> <i>l<sub>1</sub></i> <i>t<sub>2</sub></i> <i>l<sub>2</sub></i> <span style="font-style:normal">...</span> <i>t<sub>n</sub></i>)</code> [LISP]</dt>
1072 <dd>Creates
1073 a piece-wise linear envelope with breakpoints at (0, 0), (<i>t<sub>1</sub></i>,
1074 <i>l<sub>1</sub></i>), (<i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>), ... (<i>t<sub>n</sub></i>, 0). The breakpoint
1075 times are scaled linearly by the value of <code>*sustain*</code> (if
1076 <code>*sustain*</code> is a <code>SOUND</code>, it is evaluated once at the starting
1077 time of the envelope). Each breakpoint time is then mapped according to
1078 <code>*warp*</code>. The result is a linear interpolation (unwarped) between
1079 the breakpoints. The sample rate is <code>*control-srate*</code>. Breakpoint
1080 times are quantized to the nearest sample time. If you specify one or more
1081 breakpoints withing one sample period, <code>pwl</code> attempts to give a good
1082 approximation to the specified function. In particular, if two breakpoints
1083 are simultaneous, <code>pwl</code> will move one of them to an adjacent sample,
1084 producing a steepest possible step in the signal. The exact details of this
1085 &ldquo;breakpoint munging&rdquo; is subject to change in future versions. Please report
1086 any cases where breakpoint lists give unexpected behaviors. The author will
1087 try to apply the &ldquo;principle of least surprise&rdquo; to the design. Note that
1088 the times are relative to 0; they are not durations of each envelope
1089 segment.<br><br>
1090 <dt><code>pwl-list(<a name="index413"></a><i>breakpoints</i>)</code> [SAL]<br>
1091
1092 <code>(pwl-list <i>breakpoints</i>)</code> [LISP]</dt>
1093 <dd>If you have a list of
1094 breakpoints, you can use <code>apply</code> to apply the <code>pwl</code> function to
1095 the breakpoints, but if the list is very long (hundreds or thousands of
1096 points), you might get a stack overflow because XLISP has a fixed-size
1097 argument stack. Instead, call <code>pwl-list</code>, passing one argument, the
1098 list of breakpoints.<br><br>
1099 <dt><code>pwlv(<a name="index414"></a><i>l<sub>1</sub></i>, <i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>, <i>t<sub>3</sub></i>, <i>l<sub>3</sub></i>, ... <i>t<sub>n</sub></i>, <i>l<sub>n</sub></i>)</code> [SAL]<br>
1100
1101 <code>(pwlv <i>l<sub>1</sub></i> <i>t<sub>2</sub></i> <i>l<sub>2</sub></i> <i>t<sub>3</sub></i> <i>l<sub>3</sub></i> <span style="font-style:normal">...</span> <i>t<sub>n</sub></i> <i>l<sub>n</sub></i>)</code> [LISP]</dt>
1102 <dd>Creates
1103 a piece-wise linear envelope with breakpoints at (0, l<sub>1</sub>),
1104 (<i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>), etc., ending with (<i>t<sub>n</sub></i>, <i>l<sub>n</sub></i>).
1105 Otherwise, the behavior is like that of <code>pwl</code>.<br><br>
1106 <dt><code>pwlv-list(<a name="index415"></a><i>breakpoints</i>)</code> [SAL]<br>
1107
1108 <code>(pwlv-list <i>breakpoints</i>)</code> [LISP]</dt>
1109 <dd>A version
1110 of <code>pwlv</code> that takes a single list of breakpoints as its
1111 argument. See <code>pwl-list</code> above for the rationale.<br><br>
1112 <dt><code>pwlr(<a name="index416"></a><i>i<sub>1</sub></i>, <i>l<sub>1</sub></i>, <i>i<sub>2</sub></i>, <i>l<sub>2</sub></i>, ... <i>i<sub>n</sub></i>)</code> [SAL]<br>
1113
1114 <code>(pwlr <i>i<sub>1</sub></i> <i>l<sub>1</sub></i> <i>i<sub>2</sub></i> <i>l<sub>2</sub></i> <span style="font-style:normal">...</span> <i>i<sub>n</sub></i>)</code> [LISP]</dt>
1115 <dd>Creates
1116 a piece-wise linear envelope with breakpoints at (0, 0), (<i>t<sub>1</sub></i>,
1117 <i>l<sub>1</sub></i>), (<i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>), ... (<i>t<sub>n</sub></i>, 0), where
1118 <i>t<sub>j</sub></i> is the sum of <i>i<sub>1</sub></i> through <i>i<sub>j</sub></i>. In other
1119 words, the breakpoint times are specified in terms of intervals rather
1120 than cummulative time. Otherwise, the behavior is like that of
1121 <code>pwl</code>.<br><br>
1122 <dt><code>pwlr-list(<a name="index417"></a><i>breakpoints</i>)</code> [SAL]<br>
1123
1124 <code>(pwlr-list <i>breakpoints</i>)</code> [LISP]</dt>
1125 <dd>A version
1126 of <code>pwlr</code> that takes a single list of breakpoints as its
1127 argument. See <code>pwl-list</code> above for the rationale.<br><br>
1128 <dt><code>pwlvr(<a name="index418"></a><i>l<sub>1</sub></i>, <i>i<sub>2</sub></i>, <i>l<sub>2</sub></i>, <i>i<sub>3</sub></i>, <i>i<sub>3</sub></i>, ... <i>i<sub>n</sub></i>, <i>l<sub>n</sub></i>)</code> [SAL]<br>
1129
1130 <code>(pwlvr <i>l<sub>1</sub></i> <i>i<sub>2</sub></i> <i>l<sub>2</sub></i> <i>i<sub>3</sub></i> <i>i<sub>3</sub></i> <span style="font-style:normal">...</span> <i>i<sub>n</sub></i> <i>l<sub>n</sub></i>)</code> [LISP]</dt>
1131 <dd>Creates
1132 a piece-wise linear envelope with breakpoints at (0, l<sub>1</sub>),
1133 (<i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>), etc., ending with (<i>t<sub>n</sub>, <i>l<sub>n</sub></i></i>,
1134 where <i>t<sub>j</sub></i> is the sum of <i>i<sub>2</sub></i> through <i>i<sub>j</sub></i>. In
1135 other words, the breakpoint times are specified in terms of intervals
1136 rather than cummulative time. Otherwise, the behavior is like that of
1137 <code>pwlv</code>.<br><br>
1138 <dt><code>pwlvr-list(<a name="index419"></a><i>breakpoints</i>)</code> [SAL]<br>
1139
1140 <code>(pwlvr-list <i>breakpoints</i>)</code> [LISP]</dt>
1141 <dd>A version
1142 of <code>pwlvr</code> that takes a single list of breakpoints as its
1143 argument. See <code>pwl-list</code> above for the rationale.<br><br>
1144 <dt><code>pwe(<a name="index420"></a><i>t<sub>1</sub></i>, <i>l<sub>1</sub></i>, <i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>, <span style="font-style:normal">...</span> <i>t<sub>n</sub></i>)</code> [SAL]<br>
1145
1146 <code>(pwe <i>t<sub>1</sub></i> <i>l<sub>1</sub></i> <i>t<sub>2</sub></i> <i>l<sub>2</sub></i> <span style="font-style:normal">...</span> <i>t<sub>n</sub></i>)</code> [LISP]</dt>
1147 <dd>Creates
1148 a piece-wise exponential envelope with breakpoints at (0, 1),
1149 (<i>t<sub>1</sub></i>, <i>l<sub>1</sub></i>), (<i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>), ... (<i>t<sub>n</sub></i>,
1150 1). Exponential segments means that the ratio of values from sample
1151 to sample is constant within the segment. (The current implementation
1152 actually takes the log of each value, computes a piece-wise
1153 exponential from the points using <code>pwl</code>, then exponentiates each
1154 resulting sample. A faster implementation is certainly possible!)
1155 Breakpoint values (<i>l<sub>j</sub></i>) must be greater than zero. Otherwise,
1156 this function is similar to <code>pwl</code>, including stretch by
1157 <code>*sustain*</code>, mapping according to <code>*warp*</code>, sample rate
1158 based on <code>*control-srate*</code>, and "breakpoint munging" (see
1159 <code>pwl</code> described above). <i>Default initial and final values are
1160 of dubious value with exponentials. See the <code>pwz</code> functions
1161 which allow decay to zero, and <code>pwev</code> which has explicit initial
1162 and final values.</i><br><br>
1163 <dt><code>pwe-list(<a name="index421"></a><i>breakpoints</i>)</code> [SAL]<br>
1164
1165 <code>(pwe-list <i>breakpoints</i>)</code> [LISP]</dt>
1166 <dd>A version
1167 of <code>pwe</code> that takes a single list of breakpoints as its argument.
1168 See <code>pwl-list</code> above for the rationale.<br><br>
1169 <dt>
1170 <code>pwev(<a name="index422"></a><i>l<sub>1</sub></i>, <i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>, <i>t<sub>3</sub></i>, <i>t<sub>3</sub></i>, <span style="font-style:normal">...</span> <i>t<sub>n</sub></i>, <i>l<sub>n</sub></i>)</code> [SAL]<br>
1171
1172 <code>(pwev <i>l<sub>1</sub></i> <i>t<sub>2</sub></i> <i>l<sub>2</sub></i> <i>t<sub>3</sub></i> <i>t<sub>3</sub></i> <span style="font-style:normal">...</span> <i>t<sub>n</sub></i> <i>l<sub>n</sub></i>)</code> [LISP]</dt>
1173 <dd>Creates
1174 a piece-wise exponential envelope with breakpoints at (0, <i>l<sub>1</sub></i>),
1175 (<i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>), etc., ending with (<i>t<sub>n</sub></i>, <i>l<sub>n</sub></i>).
1176 Otherwise, the behavior is like that of <code>pwe</code>.<br><br>
1177 <dt><code>pwev-list(<a name="index423"></a><i>breakpoints</i>)</code> [SAL]<br>
1178
1179 <code>(pwev-list <i>breakpoints</i>)</code> [LISP]</dt>
1180 <dd>A version
1181 of <code>pwev</code> that takes a single list of breakpoints as its
1182 argument. See <code>pwl-list</code> above for the rationale.<br><br>
1183 <dt><code>pwer(<a name="index424"></a><i>i<sub>1</sub></i>, <i>l<sub>1</sub></i>, <i>i<sub>2</sub></i>, <i>l<sub>2</sub></i>, <span style="font-style:normal">...</span> <i>i<sub>n</sub></i>)</code> [SAL]<br>
1184
1185 <code>(pwer <i>i<sub>1</sub></i> <i>l<sub>1</sub></i> <i>i<sub>2</sub></i> <i>l<sub>2</sub></i> <span style="font-style:normal">...</span> <i>i<sub>n</sub></i>)</code> [LISP]</dt>
1186 <dd>Creates
1187 a piece-wise exponential envelope with breakpoints at (0, 1),
1188 (<i>t<sub>1</sub></i>, <i>l<sub>1</sub></i>), (<i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>), ... (<i>t<sub>n</sub></i>,
1189 1), where <i>t<sub>j</sub></i> is the sum of <i>i<sub>1</sub></i> through <i>i<sub>j</sub></i>. In
1190 other words, the breakpoint times are specified in terms of intervals
1191 rather than cummulative time. Otherwise, the behavior is like that of
1192 <code>pwe</code>. Consider using <code>pwerv</code> instead of this one.<br><br>
1193 <dt><code>pwer-list(<a name="index425"></a><i>breakpoints</i>)</code> [SAL]<br>
1194
1195 <code>(pwer-list <i>breakpoints</i>)</code> [LISP]</dt>
1196 <dd>A version
1197 of <code>pwer</code> that takes a single list of breakpoints as its
1198 argument. See <code>pwl-list</code> above for the rationale.<br><br>
1199 <dt><code>pwevr(<a name="index426"></a><a name="index427"></a><i>l<sub>1</sub></i>, <i>i<sub>2</sub></i>, <i>l<sub>2</sub></i>, <i>i<sub>3</sub></i>, <i>i<sub>3</sub></i>, <span style="font-style:normal">...</span> <i>i<sub>n</sub></i>, <i>l<sub>n</sub></i>)</code> [SAL]<br>
1200
1201 <code>(pwevr <i>l<sub>1</sub></i> <i>i<sub>2</sub></i> <i>l<sub>2</sub></i> <i>i<sub>3</sub></i> <i>i<sub>3</sub></i> <span style="font-style:normal">...</span> <i>i<sub>n</sub></i> <i>l<sub>n</sub></i>)</code> [LISP]</dt>
1202 <dd>Creates
1203 a piece-wise exponential envelope with breakpoints at (0, l<sub>1</sub>),
1204 (<i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>), etc., ending with (<i>t<sub>n</sub>, <i>l<sub>n</sub></i></i>,
1205 where <i>t<sub>j</sub></i> is the sum of <i>i<sub>2</sub></i> through <i>i<sub>j</sub></i>. In
1206 other words, the breakpoint times are specified in terms of intervals
1207 rather than cummulative time. Otherwise, the behavior is like that of
1208 <code>pwev</code>. Note that this is similar to the csound GEN05 generator.
1209 Which is uglier, <i>GEN05</i> or <i>pwevr</i>?<br><br>
1210 <dt><code>pwevr-list(<a name="index428"></a><i>breakpoints</i>)</code> [SAL]<br>
1211
1212 <code>(pwevr-list <i>breakpoints</i>)</code> [LISP]</dt>
1213 <dd>A version
1214 of <code>pwevr</code> that takes a single list of breakpoints as its
1215 argument. See <code>pwl-list</code> above for the rationale.<br><br>
1216 <dt><code>pwz(<a name="index429"></a><i>t<sub>1</sub></i>, <i>l<sub>1</sub></i>, <i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>, <span style="font-style:normal">...</span> <i>t<sub>n</sub></i>, [bias: <i>bias</i>], [linear-attack: <i>linatk</i>])</code> [SAL]<br>
1217
1218 <code>(pwz <i>t<sub>1</sub></i> <i>l<sub>1</sub></i> <i>t<sub>2</sub></i> <i>l<sub>2</sub></i> <span style="font-style:normal">...</span> <i>t<sub>n</sub></i> [:bias <i>bias</i>] [:linear-attack <i>linatk</i>])</code> [LISP]</dt>
1219 <dd>Creates
1220 a piece-wise pseudo-exponential envelope with breakpoints at (0, 0),
1221 (<i>t<sub>1</sub></i>, <i>l<sub>1</sub></i>), (<i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>), ... (<i>t<sub>n</sub></i>,
1222 0). Each breakpoint value is first incremented by <i>bias</i>, then
1223 interpolated with exponentials as in <code>pwe</code> (see above), then
1224 <i>bias</i> is subtracted from all samples so that the envelope passes
1225 through the original breakpoints as specified, including decay to zero.
1226 Breakpoint values (<i>l<sub>j</sub></i>) must be non-negative. Otherwise,
1227 this function is similar to <code>pwl</code>, including stretch by
1228 <code>*sustain*</code>, mapping according to <code>*warp*</code>, sample rate
1229 based on <code>*control-srate*</code>, and "breakpoint munging" (see
1230 <code>pwl</code> described above).
1231 The <code>linear-attack</code> keyword parameter,
1232 if true (default is false), causes a linear interpolation from (0, 0) to
1233 (<i>t<sub>1</sub></i>, <i>l<sub>1</sub></i>) rather than exponential.
1234 The <code>bias</code> keyword parameter
1235 is optional, and defaults
1236 to 0.01 (about -40dB). As bias grows large, the &ldquo;half-life&rdquo; of the
1237 decay becomes large, so the decay is more linear. Even large values
1238 such as 1 are possible. As bias grows small, the &ldquo;half-life&rdquo; of
1239 the decay becomes small, so the decay is more rapid.
1240 Example: If bias is 0.01 (default), a decay from 1 to 0 in 1 second
1241 will decay to about -20dB in 0.5 seconds. If bias is 0.0001 (-80dB),
1242 the envelope will decay to about -20dB in only 0.25 seconds.
1243 You can think of bias as approximately how much attenuation you
1244 want to occur exponentially before the final decay to zero where the
1245 envelope becomes more linear. With bias values at or below 0.01, the
1246 &ldquo;linear part&rdquo; occurs when the signal is barely audible anyway.<br><br>
1247 <dt><code>pwz-list(<a name="index430"></a><i>breakpoints</i>, [bias: <i>bias</i>], [linear-attack: <i>linatk</i>])</code> [SAL]<br>
1248
1249 <code>(pwz-list <i>breakpoints</i> [:bias <i>bias</i>] [:linear-attack <i>linatk</i>])</code> [LISP]</dt>
1250 <dd>A
1251 version of <code>pwz</code> that takes a single list of breakpoints as its argument.
1252 See <code>pwl-list</code> above for the rational for
1253 this &ldquo;-list&rdquo; form of <code>pwz</code> and for an explanation of
1254 the <code>linear-attack</code> keyword parameter.<br><br>
1255 <dt>
1256 <code>pwzv(<a name="index431"></a><i>l<sub>1</sub></i>, <i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>, <i>t<sub>3</sub></i>, <i>t<sub>3</sub></i>, <span style="font-style:normal">...</span> <i>t<sub>n</sub></i>, <i>l<sub>n</sub></i>, [bias: <i>bias</i>], [linear-attack: <i>linatk</i>])</code> [SAL]<br>
1257
1258 <code>(pwzv <i>l<sub>1</sub></i> <i>t<sub>2</sub></i> <i>l<sub>2</sub></i> <i>t<sub>3</sub></i> <i>t<sub>3</sub></i> <span style="font-style:normal">...</span> <i>t<sub>n</sub></i> <i>l<sub>n</sub></i> [:bias <i>bias</i>] [:linear-attack <i>linatk</i>])</code> [LISP]</dt>
1259 <dd>Creates
1260 a piece-wise pseudo-exponential envelope with breakpoints at (0, <i>l<sub>1</sub></i>),
1261 (<i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>), etc., ending with (<i>t<sub>n</sub></i>, <i>l<sub>n</sub></i>). If the
1262 <code>linear-attack</code> parameter is true (default is false), linear interpolation is used
1263 from (0, <i>l<sub>1</sub></i>) to (<i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>).
1264 Otherwise, the behavior is like that of <code>pwz</code>.<br><br>
1265 <dt><code>pwzv-list(<a name="index432"></a><i>breakpoints</i>, [bias: <i>bias</i>], [linear-attack: <i>linatk</i>])</code> [SAL]<br>
1266
1267 <code>(pwzv-list <i>breakpoints</i> [:bias <i>bias</i>] [:linear-attack <i>linatk</i>])</code> [LISP]</dt>
1268 <dd>A
1269 version of <code>pwzv</code> that takes a single list of breakpoints as its
1270 argument. See <code>pwl-list</code> above for the
1271 rational for this &ldquo;-list&rdquo; form of <code>pwzv</code>.<br><br>
1272 <dt><code>pwzr(<a name="index433"></a><i>i<sub>1</sub></i>, <i>l<sub>1</sub></i>, <i>i<sub>2</sub></i>, <i>l<sub>2</sub></i>, <span style="font-style:normal">...</span> <i>i<sub>n</sub></i>, [bias: <i>bias</i>], [linear-attack: <i>linatk</i>])</code> [SAL]<br>
1273
1274 <code>(pwzr <i>i<sub>1</sub></i> <i>l<sub>1</sub></i> <i>i<sub>2</sub></i> <i>l<sub>2</sub></i> <span style="font-style:normal">...</span> <i>i<sub>n</sub></i> [:bias <i>bias</i>] [:linear-attack <i>linatk</i>])</code> [LISP]</dt>
1275 <dd>Creates
1276 a piece-wise pseudo-exponential envelope with breakpoints at (0, 0),
1277 (<i>t<sub>1</sub></i>, <i>l<sub>1</sub></i>), (<i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>), ... (<i>t<sub>n</sub></i>,
1278 0), where <i>t<sub>j</sub></i> is the sum of <i>i<sub>1</sub></i> through <i>i<sub>j</sub></i>. In
1279 other words, the breakpoint times are specified in terms of intervals
1280 rather than cummulative time. Otherwise, the behavior is like that of
1281 <code>pwz</code>.<br><br>
1282 <dt><code>pwzr-list(<a name="index434"></a><i>breakpoints</i>, [bias: <i>bias</i>], [linear-attack: <i>linatk</i>])</code> [SAL]<br>
1283
1284 <code>(pwzr-list <i>breakpoints</i> [:bias <i>bias</i>] [:linear-attack <i>linatk</i>])</code> [LISP]</dt>
1285 <dd>A
1286 version of <code>pwzr</code> that takes a single list of breakpoints as its
1287 argument. See <code>pwl-list</code> above for the
1288 rational for this &ldquo;-list&rdquo; form of <code>pwzr</code>.<br><br>
1289 <dt><code>pwzvr(<a name="index435"></a><a name="index436"></a><i>l<sub>1</sub></i>, <i>i<sub>2</sub></i>, <i>l<sub>2</sub></i>, <i>i<sub>3</sub></i>, <i>i<sub>3</sub></i>, <span style="font-style:normal">...</span> <i>i<sub>n</sub></i>, <i>l<sub>n</sub></i>, [bias: <i>bias</i>], [linear-attack: <i>linatk</i>])</code> [SAL]<br>
1290
1291 <code>(pwzvr <i>l<sub>1</sub></i> <i>i<sub>2</sub></i> <i>l<sub>2</sub></i> <i>i<sub>3</sub></i> <i>i<sub>3</sub></i> <span style="font-style:normal">...</span> <i>i<sub>n</sub></i> <i>l<sub>n</sub></i> [:bias <i>bias</i>] [:linear-attack <i>linatk</i>])</code> [LISP]</dt>
1292 <dd>Creates
1293 a piece-wise exponential envelope with breakpoints at (0, l<sub>1</sub>),
1294 (<i>t<sub>2</sub></i>, <i>l<sub>2</sub></i>), etc., ending with (<i>t<sub>n</sub>, <i>l<sub>n</sub></i></i>,
1295 where <i>t<sub>j</sub></i> is the sum of <i>i<sub>2</sub></i> through <i>i<sub>j</sub></i>. In
1296 other words, the breakpoint times are specified in terms of intervals
1297 rather than cummulative time. Otherwise, the behavior is like that of
1298 <code>pwzv</code>. See <code>pwz</code> (above) for an explanation of <i>bias</i> and <i>linatk</i>.<br><br>
1299 <dt><code>pwzvr-list(<a name="index437"></a><i>breakpoints</i>, [bias: <i>bias</i>], [linear-attack: <i>linatk</i>])</code> [SAL]<br>
1300
1301 <code>(pwzvr-list <i>breakpoints</i> [:bias <i>bias</i>] [:linear-attack <i>linatk</i>])</code> [LISP]</dt>
1302 <dd>A
1303 version of <code>pwzvr</code> that takes a single list of breakpoints as its
1304 argument. See <code>pwl-list</code> above for the
1305 rational for this &ldquo;-list&rdquo; form of <code>pwzvr</code>.
1306 </dd></dl>
1307 <a name = "93"><h5>Filter Behaviors</h5></a><dl>
1308 <dt>
1309
1310 <code>alpass(<a name="index438"></a><a name="index439"></a><a name="index440"></a><i>sound</i>, <i>decay</i>, <i>hz</i> [, <i>minhz</i>])</code> [SAL]<br>
1311
1312 <code>(alpass <i>sound</i> <i>decay</i> <i>hz</i> [<i>minhz</i>])</code> [LISP]</dt>
1313 <dd>Applies an all-pass filter to <i>sound</i>. This all-pass filter creates a delay effect without the resonances of a comb filter. The decay time of the filter is given by <i>decay</i>. The <i>hz</i> parameter must be a number or sound greater than zero. It is used to compute delay, which is then rounded to the nearest integer number of samples (so the frequency is not always exact. Higher sampling rates yield better delay resolution.) The <i>decay</i> may be a sound or a number. In either case, it must also be positive. (Implementation note: an exponentiation is needed to convert <i>decay</i> into the <i>feedback</i> parameter, and exponentiation is typically more time-consuming than the filter operation itself. To get high performance, provide <i>decay</i> at a low sample rate.) The resulting sound will have the start time, sample rate, etc. of <i>sound</i>. If <i>hz</i> is of type <code>SOUND</code>, the delay may be time-varying. Linear interpolation is then used for fractional sample delay, but it should be noted that linear interpolation implies a low-pass transfer function. Thus, this filter may behave differently with a constant <code>SOUND</code> than it does with a <code>FLONUM</code> value for <i>hz</i>. In addition, if <i>hz</i> is of type <code>SOUND</code>, then <i>minhz</i> is required. The <i>hz</i> parameter will be clipped to be greater than <i>minhz</i>, placing an upper bound on the delay buffer length.<br><br>
1314 <dt>
1315 <code>comb(<a name="index441"></a><a name="index442"></a><i>sound</i>, <i>decay</i>, <i>hz</i>)</code> [SAL]<br>
1316
1317 <code>(comb <i>sound</i> <i>decay</i> <i>hz</i>)</code> [LISP]</dt>
1318 <dd>Applies a comb filter to <i>sound</i>. A comb filter emphasizes (resonates at) frequencies that are multiples of a <i>hz</i>. The decay time of the resonance is given by <i>decay</i>. This is a variation on <code>feedback-delay</code> (see below). The <i>hz</i> parameter must be a number greater than zero. It is used to compute delay, which is then rounded to the nearest integer number of samples (so the frequency is not always exact. Higher sampling rates yield better delay resolution.) The <i>decay</i> may be a sound or a number. In either case, it must also be positive. (Implementation note: an exponentiation is needed to convert <i>decay</i> into the <i>feedback</i> parameter for <code>feedback-delay</code>, and exponentiation is typically more time-consuming than the filter operation itself. To get high performance, provide <i>decay</i> at a low sample rate.) The resulting sound will have the start time, sample rate, etc. of <i>sound</i>.<br><br>
1319 <dt>
1320 <code>congen(<a name="index443"></a><a name="index444"></a><a name="index445"></a><i>gate</i>, <i>risetime</i>, <i>falltime</i>)</code> [SAL]<br>
1321
1322 <code>(congen <i>gate</i> <i>risetime</i> <i>falltime</i>)</code> [LISP]</dt>
1323 <dd>Implements an analog synthesizer-style contour generator. The input <i>gate</i> normally goes from 0.0 to 1.0 to create an attack and from 1.0 to 0.0 to start a release. During the attack (output is increasing), the output converges half-way to <i>gate</i> in <i>risetime</i> (a <code>FLONUM</code>) seconds. During the decay, the half-time is <i>falltime</i> seconds. The sample rate, start time, logical stop, and terminate time all come from <i>gate</i>. If you want a nice decay, be sure that the <i>gate</i> goes to zero and stays there for awhile before <i>gate</i> terminates, because <code>congen</code> (and all Nyquist sounds) go immediately to zero at termination time. For example, you can use <code>pwl</code> to build a pulse followed by some zero time:
1324
1325 <p></p>
1326 <pre>
1327 (pwl 0 1 duty 1 duty 0 1)
1328 </pre>
1329
1330 <p>
1331 Assuming <i>duty</i> is less than 1.0, this will be a pulse of duration <i>duty</i> followed by zero for a total duration of 1.0.
1332 </p>
1333 <pre>
1334 (congen (pwl 0 1 duty 1 duty 0 1) 0.01 0.05)
1335 </pre>
1336
1337 <p>
1338 will have a duration of 1.0 because that is the termination time of the <code>pwl</code> input. The decaying release of the resulting envelope will be truncated to zero at time 1.0. (Since the decay is theoretically infinite, there is no way to avoid truncation, although you could multiply by another envelope that smoothly truncates to zero in the last millisecond or two to get both an exponential decay and a smooth final transition to zero.)</p>
1339 <dt>
1340 <code>convolve(<a name="index446"></a><a name="index447"></a><a name="index448"></a><i>sound</i>,
1341 <i>response</i>)</code> [SAL]<br>
1342
1343 <code>(convolve <i>sound</i> <i>response</i>)</code> [LISP]</dt>
1344 <dd>Convolves two signals. The first can be any length, but the total space required is proportional to
1345 the length of <i>response</i>. The start time, logical stop time, and sample
1346 rate of the output match those of the input <i>sound</i>. The physical stop
1347 time of the result is the physical stop time of <i>sound</i> plus the duration
1348 of the <i>response</i> so that the result sound includes the &ldquo;tail&rdquo; of the
1349 filter response. The response is linearly interpolated if necessary to have same sample rate as <i>sound</i>. The current implementation uses a &ldquo;fast convolution&rdquo; algorithm with a maximum FFT size of 64K, which after zero padding allows up to 32K point convolutions. If the impulse response is longer, it is broken into multiple blocks of 32K samples. There is no limit on the length of the impulse response. This is an Order(N x M) algorithm where N and M are the number of 32K sample blocks in the <i>sound</i> and <i>response</i>, respectively.
1350 Further discussion and examples can be found in
1351 <code>nyquist/lib/convolve/convolution.html</code><a name="index449"></a><a name="index450"></a>. <br><br>
1352 <dt>
1353 <code>feedback-delay(<a name="index451"></a><a name="index452"></a><a name="index453"></a><i>sound</i>, <i>delay</i>, <i>feedback</i>)</code> [SAL]<br>
1354
1355 <code>(feedback-delay <i>sound</i> <i>delay</i> <i>feedback</i>)</code> [LISP]</dt>
1356 <dd>Applies feedback delay to <i>sound</i>. The <i>delay</i> must be a number (in seconds). It is rounded to the nearest sample to determine the length of the delay. The sample rate is the maximum from <i>sound</i> and <i>feedback</i> (if feedback is also a sound). The amound of <i>feedback</i> should be less than one to avoid an exponential increase in amplitude. The start time and stop time, and logical stop time are taken from <i>sound</i>. Since output is truncated at the stop time of <i>sound</i>, you may want to append some silence to <i>sound</i> to give the filter time to decay.<br><br>
1357 <dt>
1358 <code>lp(<a name="index454"></a><a name="index455"></a><i>sound</i>, <i>cutoff</i>)</code> [SAL]<br>
1359
1360 <code>(lp <i>sound</i> <i>cutoff</i>)</code> [LISP]</dt>
1361 <dd>Filters <i>sound</i>
1362 using a first-order Butterworth low-pass filter. <i>Cutoff</i> may be a float
1363 or a signal (for time-varying filtering) and expresses hertz. Filter
1364 coefficients (requiring trig functions) are recomputed at the sample rate of
1365 <i>cutoff</i>. The resulting sample rate, start time, etc. are taken from <i>sound</i>.<br><br>
1366 <dt><code>tone(<a name="index456"></a><i>sound</i>, <i>cutoff</i>)</code> [SAL]<br>
1367
1368 <code>(tone <i>sound</i> <i>cutoff</i>)</code> [LISP]</dt>
1369 <dd>No longer defined; use <code>lp</code> instead, or define it by adding <code>(setfn tone lp)</code> to your program.<br><br>
1370 <dt>
1371 <code>hp(<a name="index457"></a><a name="index458"></a><i>sound</i>, <i>cutoff</i>)</code> [SAL]<br>
1372
1373 <code>(hp <i>sound</i> <i>cutoff</i>)</code> [LISP]</dt>
1374 <dd>Filters <i>sound</i>
1375 using a first-order Butterworth high-pass filter. <i>Cutoff</i> may be a
1376 float or a signal (for time-varying filtering) and expresses hertz. Filter
1377 coefficients (requiring trig functions) are recomputed at the sample rate of
1378 <i>cutoff</i>. This filter is an exact complement of <code>lp</code>.<br><br>
1379 <dt><code>atone(<a name="index459"></a><i>sound</i>, <i>cutoff</i>)</code> [SAL]<br>
1380
1381 <code>(atone <i>sound</i> <i>cutoff</i>)</code> [LISP]</dt>
1382 <dd>No longer defined; use <code>hp</code> instead, or define it by adding <code>(setfn atone hp)</code> to your program.<br><br>
1383 <dt>
1384 <code>reson(<a name="index460"></a><a name="index461"></a><i>sound</i>, <i>center</i>, <i>bandwidth</i> [, <i>n</i>])</code> [SAL]<br>
1385
1386 <code>(reson <i>sound</i> <i>center</i> <i>bandwidth</i> [<i>n</i>])</code> [LISP]</dt>
1387 <dd>Apply
1388 a resonating filter to <i>sound</i> with center frequency <i>center</i> (in hertz),
1389 which may be a float or a signal. <i>Bandwidth</i> is the filter bandwidth (in
1390 hertz), which may also be a signal. Filter coefficients (requiring trig
1391 functions) are recomputed at each new sample of either <i>center</i> or
1392 <i>bandwidth</i>, and coefficients are <i>not</i> interpolated. The last
1393 parameter <i>n</i> specifies the type of normalization as in Csound: A value of 1 specifies a peak amplitude
1394 response of 1.0; all frequencies other than <i>hz</i> are attenuated. A
1395 value of 2 specifies the overall RMS value of the amplitude response
1396 is 1.0; thus filtered white noise would retain the same power. A value of
1397 zero specifies no scaling. The resulting sample rate, start time, etc. are taken from <i>sound</i>.<br><br>
1398 <dt>One application of <code>reson</code> is to simulate resonances in the human vocal tract.
1399 See <code>nyquist/lib/voice/voice_synthesis.html</code><a name="index462"></a><a name="index463"></a>
1400 for sample code and documentation.<br><br>
1401 <dt>
1402 <code>areson(<a name="index464"></a><a name="index465"></a><i>sound</i>, <i>center</i>, <i>bandwidth</i> [, <i>n</i>])</code> [SAL]<br>
1403
1404 <code>(areson <i>sound</i> <i>center</i> <i>bandwidth</i> [<i>n</i>])</code> [LISP]</dt>
1405 <dd>The <code>areson</code> filter is an exact
1406 complement of <code>reson</code> such that if both are applied to the
1407 same signal with the same parameters, the sum of the results yeilds
1408 the original signal.<br><br>
1409 <dt>
1410 <code>shape(<a name="index466"></a><a name="index467"></a><a name="index468"></a><i>signal</i>, <i>table</i>, <i>origin</i>)</code> [SAL]<br>
1411
1412 <code>(shape <i>signal</i> <i>table</i> <i>origin</i>)</code> [LISP]</dt>
1413 <dd>A waveshaping function. Use <i>table</i> as a function; apply the function to each sample of <i>signal</i> to yield a new sound. <i>Signal</i> should range from -1 to +1. Anything beyond these bounds is clipped. <i>Table</i> is also a sound, but it is converted into a lookup table (similar to table-lookup oscillators). The <i>origin</i> is a <code>FLONUM</code> and gives the time which should be considered the origin of <i>table</i>. (This is important because <i>table</i> cannot have values at negative times, but <i>signal</i> will often have negative values. The <i>origin</i> gives an offset so that you can produce suitable tables.) The output at time <i>t</i> is:
1414 <blockquote>
1415 <i>table</i>(<i>origin</i> + clip(<i>signal</i>(<i>t</i>))</blockquote> where clip(<i>x</i>) = <i>max</i>(1, <i>min</i>(-1, <i>x</i>)).
1416 (E.g. if <i>table</i> is a signal defined over the interval [0, 2], then <i>origin</i> should be 1.0. The value of <i>table</i> at time 1.0 will be output when the input signal is zero.) The output has the same start time, sample rate, etc. as <i>signal</i>. The <code>shape</code> function will also accept multichannel <i>signal</i>s and <i>table</i>s.
1417
1418 Further discussion and examples can be found by installing the
1419 &ldquo;distortion&rdquo; extension with the NyquistIDE Extension Manager.
1420 The code will appear in
1421 <code>nyquist/lib/distortion/distortion.html</code><a name="index469"></a><a name="index470"></a>. The <code>shape</code> function is also
1422 used to map frequency to amplitude to achieve a spectral envelope for
1423 Shepard tones (install the &ldquo;shepard&rdquo; extension)
1424 in <code>nyquist/lib/shepard/shepard.lsp</code>.<a name="index471"></a><a name="index472"></a><br><br>
1425 <dt>
1426 <code>biquad(<a name="index473"></a><i>signal</i>, <i>b0</i>, <i>b1</i>, <i>b2</i>, <i>a0</i>, <i>a1</i>, <i>a2</i>)</code> [SAL]<br>
1427
1428 <code>(biquad <i>signal</i> <i>b0</i> <i>b1</i> <i>b2</i> <i>a0</i> <i>a1</i> <i>a2</i>)</code> [LISP]</dt>
1429 <dd>A fixed-parameter biquad filter. All filter coefficients are <code>FLONUM</code>s. See also <code>lowpass2</code>, <code>highpass2</code>, <code>bandpass2</code>, <code>notch2</code>, <code>allpass2</code>, <code>eq-lowshelf</code>, <code>eq-highshelf</code>, <code>eq-band</code>, <code>lowpass4</code>, <code>lowpass6</code>, <code>highpass4</code>, and <code>highpass8</code> in this section for convenient variations based on the same filter. The equations for the filter are: z<sub>n</sub> = s<sub>n</sub> + a1 * z<sub>n-1</sub> + a2 * z<sub>n-2</sub>, and y<sub>n</sub> = z<sub>n</sub> * b0 + z<sub>n-1</sub> * b1 + z<sub>n-2</sub> * b2.<br><br>
1430 <dt>
1431 <code>biquad-m(<a name="index474"></a><i>signal</i>, <i>b0</i>, <i>b1</i>, <i>b2</i>, <i>a0</i>, <i>a1</i>, <i>a2</i>)</code> [SAL]<br>
1432
1433 <code>(biquad-m <i>signal</i> <i>b0</i> <i>b1</i> <i>b2</i> <i>a0</i> <i>a1</i> <i>a2</i>)</code> [LISP]</dt>
1434 <dd>A fixed-parameter biquad filter with Matlab sign conventions for <i>a0</i>, <i>a1</i>, and <i>a2</i>. All filter coefficients are <code>FLONUM</code>s.<br><br>
1435 <dt>
1436 <code>lowpass2(<a name="index475"></a><i>signal</i>, <i>hz</i> [, <i>q</i>])</code> [SAL]<br>
1437
1438 <code>(lowpass2 <i>signal</i> <i>hz</i> [<i>q</i>])</code> [LISP]</dt>
1439 <dd>A fixed-parameter, second-order lowpass filter based on <code>snd-biquad</code>. The cutoff frequency is given by <i>hz</i> (a <code>FLONUM</code>) and an optional Q factor is given by <i>q</i> (a <code>FLONUM</code>).<br><br>
1440 <dt>
1441 <code>highpass2(<a name="index476"></a><i>signal</i>, <i>hz</i> [, <i>q</i>])</code> [SAL]<br>
1442
1443 <code>(highpass2 <i>signal</i> <i>hz</i> [<i>q</i>])</code> [LISP]</dt>
1444 <dd>A fixed-parameter, second-order highpass filter based on <code>snd-biquad</code>. The cutoff frequency is given by <i>hz</i> (a <code>FLONUM</code>) and an optional Q factor is given by <i>q</i> (a <code>FLONUM</code>).<br><br>
1445 <dt>
1446 <code>bandpass2(<a name="index477"></a><i>signal</i>, <i>hz</i> [, <i>q</i>])</code> [SAL]<br>
1447
1448 <code>(bandpass2 <i>signal</i> <i>hz</i> [<i>q</i>])</code> [LISP]</dt>
1449 <dd>A fixed-parameter, second-order bandpass filter based on <code>snd-biquad</code>. The center frequency is given by <i>hz</i> (a <code>FLONUM</code>) and an optional Q factor is given by <i>q</i> (a <code>FLONUM</code>).<br><br>
1450 <dt>
1451 <code>notch2(<a name="index478"></a><i>signal</i>, <i>hz</i> [, <i>q</i>])</code> [SAL]<br>
1452
1453 <code>(notch2 <i>signal</i> <i>hz</i> [<i>q</i>])</code> [LISP]</dt>
1454 <dd>A fixed-parameter, second-order notch filter based on <code>snd-biquad</code>. The center frequency is given by <i>hz</i> (a <code>FLONUM</code>) and an optional Q factor is given by <i>q</i> (a <code>FLONUM</code>).<br><br>
1455 <dt>
1456 <code>allpass2(<a name="index479"></a><i>signal</i>, <i>hz</i> [, <i>q</i>])</code> [SAL]<br>
1457
1458 <code>(allpass2 <i>signal</i> <i>hz</i> [<i>q</i>])</code> [LISP]</dt>
1459 <dd>A fixed-parameter, second-order allpass filter based on <code>snd-biquad</code>. The frequency is given by <i>hz</i> (a <code>FLONUM</code>) and an optional Q factor is given by <i>q</i> (a <code>FLONUM</code>).<br><br>
1460 <dt>
1461 <code>eq-lowshelf(<a name="index480"></a><a name="index481"></a><i>signal</i>, <i>hz</i>, <i>gain</i> [, <i>slope</i>])</code> [SAL]<br>
1462
1463 <code>(eq-lowshelf <i>signal</i> <i>hz</i> <i>gain</i> [<i>slope</i>])</code> [LISP]</dt>
1464 <dd>A fixed-parameter, second-order bass shelving equalization (EQ) filter based on <code>snd-biquad</code>. The <i>hz</i> parameter (a <code>FLONUM</code>)is the halfway point in the transition, and <i>gain</i> (a <code>FLONUM</code>) is the bass boost (or cut) in dB. The optional <i>slope</i> (a <code>FLONUM</code>) is 1.0 by default, and response becomes peaky at values greater than 1.0.<br><br>
1465 <dt>
1466 <code>eq-highshelf(<a name="index482"></a><a name="index483"></a><i>signal</i>, <i>hz</i>, <i>gain</i> [, <i>slope</i>])</code> [SAL]<br>
1467
1468 <code>(eq-highshelf <i>signal</i> <i>hz</i> <i>gain</i> [<i>slope</i>])</code> [LISP]</dt>
1469 <dd>A fixed-parameter, second-order treble shelving equalization (EQ) filter based on <code>snd-biquad</code>. The <i>hz</i> parameter (a <code>FLONUM</code>)is the halfway point in the transition, and <i>gain</i> (a <code>FLONUM</code>) is the treble boost (or cut) in dB. The optional <i>slope</i> (a <code>FLONUM</code>) is 1.0 by default, and response becomes peaky at values greater than 1.0.<br><br>
1470 <dt>
1471 <code>eq-band(<a name="index484"></a><a name="index485"></a><i>signal</i>, <i>hz</i>, <i>gain</i>, <i>width</i>)</code> [SAL]<br>
1472
1473 <code>(eq-band <i>signal</i> <i>hz</i> <i>gain</i> <i>width</i>)</code> [LISP]</dt>
1474 <dd>A fixed- or variable-parameter, second-order midrange equalization (EQ) filter based on <code>snd-biquad</code>, <code>eq-band-ccc</code> and <code>eq-band-vvv</code>. The <i>hz</i> parameter (a <code>FLONUM</code>) is the center frequency, <i>gain</i> (a <code>FLONUM</code>) is the boost (or cut) in dB, and <i>width</i> (a <code>FLONUM</code>) is the half-gain width in octaves. Alternatively, <i>hz</i>, <i>gain</i>, and <i>width</i> may be <code>SOUND</code>s, but they must all have the same sample rate, e.g. they should all run at the control rate or at the sample rate.<br><br>
1475 <dt>
1476 <code>lowpass4(<a name="index486"></a><i>signal</i>, <i>hz</i>)</code> [SAL]<br>
1477
1478 <code>(lowpass4 <i>signal</i> <i>hz</i>)</code> [LISP]</dt>
1479 <dd>A four-pole Butterworth lowpass filter. The cutoff frequency is <i>hz</i> (a <code>FLONUM</code>).<br><br>
1480 <dt>
1481 <code>lowpass6(<a name="index487"></a><i>signal</i>, <i>hz</i>)</code> [SAL]<br>
1482
1483 <code>(lowpass6 <i>signal</i> <i>hz</i>)</code> [LISP]</dt>
1484 <dd>A six-pole Butterworth lowpass filter. The cutoff frequency is <i>hz</i> (a <code>FLONUM</code>).<br><br>
1485 <dt>
1486 <code>lowpass8(<a name="index488"></a><i>signal</i>, <i>hz</i>)</code> [SAL]<br>
1487
1488 <code>(lowpass8 <i>signal</i> <i>hz</i>)</code> [LISP]</dt>
1489 <dd>An eight-pole Butterworth lowpass filter. The cutoff frequency is <i>hz</i> (a <code>FLONUM</code>).<br><br>
1490 <dt>
1491 <code>highpass4(<a name="index489"></a><i>signal</i>, <i>hz</i>)</code> [SAL]<br>
1492
1493 <code>(highpass4 <i>signal</i> <i>hz</i>)</code> [LISP]</dt>
1494 <dd>A four-pole Butterworth highpass filter. The cutoff frequency is <i>hz</i> (a <code>FLONUM</code>).<br><br>
1495 <dt>
1496 <code>highpass6(<a name="index490"></a><i>signal</i>, <i>hz</i>)</code> [SAL]<br>
1497
1498 <code>(highpass6 <i>signal</i> <i>hz</i>)</code> [LISP]</dt>
1499 <dd>A six-pole Butterworth highpass filter. The cutoff frequency is <i>hz</i> (a <code>FLONUM</code>).<br><br>
1500 <dt>
1501 <code>highpass8(<a name="index491"></a><i>signal</i>, <i>hz</i>)</code> [SAL]<br>
1502
1503 <code>(highpass8 <i>signal</i> <i>hz</i>)</code> [LISP]</dt>
1504 <dd>An eight-pole Butterworth highpass filter. The cutoff frequency is <i>hz</i> (a <code>FLONUM</code>).<br><br>
1505 <dt>
1506 <code>tapv(<a name="index492"></a><a name="index493"></a><a name="index494"></a><i>sound</i>, <i>offset</i>,
1507 <i>vardelay</i>, <i>maxdelay</i>)</code> [SAL]<br>
1508
1509 <code>(tapv <i>sound</i> <i>offset</i> <i>vardelay</i> <i>maxdelay</i>)</code> [LISP]</dt>
1510 <dd>A delay line with a variable position tap.
1511 Identical to <code>snd-tapv</code>. See it for details (page <a href = "#103">Signal Operations</a>).
1512 </dd></dl>
1513 <a name = "94"><h5>Effects</h5></a><dl>
1514 <dt>
1515
1516 <code>nrev(<a name="index495"></a><a name="index496"></a><a name="index497"></a><a name="index498"></a><i>sound</i>, <i>decay</i>, <i>mix</i>)</code> [SAL]<br>
1517
1518 <code>(nrev <i>sound</i> <i>decay</i> <i>mix</i>)</code> [LISP]<br><br>
1519 <dt><code>jcrev(<a name="index499"></a><a name="index500"></a><a name="index501"></a><a name="index502"></a><i>sound</i>, <i>decay</i>, <i>mix</i>)</code> [SAL]<br>
1520
1521 <code>(jcrev <i>sound</i> <i>decay</i> <i>mix</i>)</code> [LISP]<br><br>
1522 <dt><code>prcrev(<a name="index503"></a><a name="index504"></a><a name="index505"></a><a name="index506"></a><i>sound</i>, <i>decay</i>, <i>mix</i>)</code> [SAL]<br>
1523
1524 <code>(prcrev <i>sound</i> <i>decay</i> <i>mix</i>)</code> [LISP]</dt>
1525 <dd>These reverbs (<code>nrev</code>, <code>jcrev</code>, and <code>prcrev</code>) are implemented
1526 in STK (running within Nyquist). <code>nrev</code> derives from Common Music's
1527 NRev, which consists of 6 comb filters followed by 3 allpass filters, a
1528 lowpass filter, and another allpass in series followed by two allpass
1529 filters in parallel. <code>jcrev</code> is the John Chowning
1530 reverberator which is based on the use of networks of simple allpass
1531 and comb delay filters. This reverb implements three series allpass units,
1532 followed by four parallel comb filters, and two decorrelation delay
1533 lines in parallel at the output. <code>prcrev</code> is a Perry Cook's
1534 reverberator which is based on the Chowning/Moorer/Schroeder
1535 reverberators using networks of simple allpass and comb delay filters.
1536 This one implements two series allpass units and two parallel comb filters.
1537 The <i>sound</i> input may be single or multichannel. The <i>decay</i> time is
1538 in seconds, and <i>mix</i> sets the mixture of input sound reverb sound,
1539 where 0.0 means input only (dry) and 1.0 means reverb only (wet).<br><br>
1540 <dt>
1541 <code>stkchorus(<a name="index507"></a><a name="index508"></a><a name="index509"></a><a name="index510"></a><i>sound</i>, <i>depth</i>, <i>freq</i>, <i>mix</i> [, <i>delay</i>])</code> [SAL]<br>
1542
1543 <code>(stkchorus <i>sound</i> <i>depth</i> <i>freq</i> <i>mix</i> [<i>delay</i>])</code> [LISP]</dt>
1544 <dd>Chorus
1545 implemented in STK. The input <i>sound</i> can be single or multichannel.
1546 The <code>FLONUM</code> parameters <i>depth</i> and <i>freq</i> set
1547 the modulation
1548 depth from 0 to 1
1549 and modulation frequency (in Hz), and <i>mix</i> sets the mixture
1550 of input sound and chorused sound, where 0.0 means input sound only (dry)
1551 and 1.0 means chorused sound only (wet). The parameter <i>delay</i> is a
1552 <code>FIXNUM</code> representing the median desired delay length in samples. <br><br>
1553 <dt>
1554 <code>pitshift(<a name="index511"></a><a name="index512"></a><a name="index513"></a><a name="index514"></a><i>sound</i>, <i>shift</i>, <i>mix</i>)</code> [SAL]<br>
1555
1556 <code>(pitshift <i>sound</i> <i>shift</i> <i>mix</i>)</code> [LISP]</dt>
1557 <dd>A pitch
1558 shifter implemented in STK. The input <i>sound</i>, a single-channel
1559 or multichannel <code>SOUND</code> is pitch-shifted by <i>shift</i>,
1560 a <code>FLONUM</code> ratio. A value of 1.0 means no shift. The parameter <i>mix</i>
1561 sets the mixture of input and shifted sounds. A value of 0.0
1562 means input only (dry)
1563 and a value of 1.0 means shifted sound only (wet).
1564 </dd></dl><a name = "95"><h5>Physical Models</h5></a><a name="index515"></a><dl>
1565 <dt>
1566
1567 <code>clarinet(<a name="index516"></a><a name="index517"></a><i>step</i>, <i>breath-env</i>)</code> [SAL]<br>
1568
1569 <code>(clarinet <i>step</i> <i>breath-env</i>)</code> [LISP]</dt>
1570 <dd>A
1571 physical model of a clarinet from STK. The <i>step</i> parameter is a <code>FLONUM</code>
1572 that controls the tube length, and the <i>breath-env</i> (a <code>SOUND</code>)
1573 controls the air pressure
1574 and also determines the length of the resulting sound. The <i>breath-env</i> signal
1575 should range from zero to one.<br><br>
1576 <dt><code>clarinet-freq(<a name="index518"></a><a name="index519"></a><a name="index520"></a><i>step</i>, <i>breath-env</i>, <i>freq-env</i>)</code> [SAL]<br>
1577
1578 <code>(clarinet-freq <i>step</i> <i>breath-env</i> <i>freq-env</i>)</code> [LISP]</dt>
1579 <dd>A variation of <code>clarinet</code>
1580 that includes a variable frequency control, <i>freq-env</i>, which specifies
1581 frequency deviation in Hz. The duration of the resulting sound is the minimum
1582 duration of <i>breath-env</i> and <i>freq-env</i>. These parameters may be of type
1583 <code>FLONUM</code> or <code>SOUND</code>. <code>FLONUM</code>s are coerced into <code>SOUND</code>s
1584 with a nominal duration arbitrarily set to 30.<br><br>
1585 <dt><code>clarinet-all(<a name="index521"></a><a name="index522"></a><a name="index523"></a><i>step</i>, <i>breath-env</i>, <i>freq-env</i>, <i>vibrato-freq</i>, <i>vibrato-gain</i>, <i>reed-stiffness</i>, <i>noise</i>)</code> [SAL]<br>
1586
1587 <code>(clarinet-all <i>step</i> <i>breath-env</i> <i>freq-env</i> <i>vibrato-freq</i> <i>vibrato-gain</i> <i>reed-stiffness</i> <i>noise</i>)</code> [LISP]</dt>
1588 <dd>A variation of <code>clarinet-freq</code>
1589 that includes controls <i>vibrato-freq</i> (a <code>FLONUM</code> for vibrato frequency in Hertz),
1590 <i>vibrato-gain</i> (a <code>FLONUM</code> for the amount of amplitude vibrato),
1591 <i>reed-stiffness</i> (a <code>FLONUM</code> or <code>SOUND</code> controlling reed stiffness in the clarinet
1592 model), and <i>noise</i> (a <code>FLONUM</code> or <code>SOUND</code> controlling noise amplitude in the input
1593 air pressure). The <i>vibrato-gain</i> is a number from zero to one, where zero
1594 indicates no vibrato, and one indicates a plus/minus 50% change in breath
1595 envelope values. Similarly, the <i>noise</i> parameter ranges from zero to one where
1596 zero means no noise and one means white noise with a peak amplitude of
1597 plus/minus 40% of the <i>breath-env</i>. The <i>reed-stiffness</i> parameter varies
1598 from zero to one.
1599 The duration of the resulting sound is the minimum duration of
1600 <i>breath-env</i>, <i>freq-env</i>, <i>reed-stiffness</i>, and <i>noise</i>. As with
1601 <code>clarinet-freq</code>, these parameters may be either <code>FLONUM</code>s or
1602 <code>SOUND</code>s, and <code>FLONUM</code>s are coerced to sounds with a nominal
1603 duration of 30.<br><br>
1604 <dt>
1605 <code>sax(<a name="index524"></a><a name="index525"></a><i>step</i>, <i>breath-env</i>)</code> [SAL]<br>
1606
1607 <code>(sax <i>step</i> <i>breath-env</i>)</code> [LISP]</dt>
1608 <dd>A
1609 physical model of a sax from STK. The <i>step</i> parameter is a <code>FLONUM</code>
1610 that controls the tube length, and the <i>breath-env</i> controls the air pressure
1611 and also determines the length of the resulting sound. The <i>breath-env</i> signal
1612 should range from zero to one.<br><br>
1613 <dt><code>sax-freq(<a name="index526"></a><a name="index527"></a><a name="index528"></a><i>step</i>, <i>breath-env</i>, <i>freq-env</i>)</code> [SAL]<br>
1614
1615 <code>(sax-freq <i>step</i> <i>breath-env</i> <i>freq-env</i>)</code> [LISP]</dt>
1616 <dd>A variation of <code>sax</code>
1617 that includes a variable frequency control, <i>freq-env</i>, which specifies
1618 frequency deviation in Hz. The duration of the resulting sound is the minimum
1619 duration of <i>breath-env</i> and <i>freq-env</i>. These parameters may be of type
1620 <code>FLONUM</code> or <code>SOUND</code>. <code>FLONUM</code>s are coerced into <code>SOUND</code>s
1621 with a nominal duration arbitrarily set to 30.<br><br>
1622 <dt><code>sax-all(<a name="index529"></a><a name="index530"></a><a name="index531"></a><i>step</i>, <i>breath-env</i>, <i>freq-env</i>, <i>vibrato-freq</i>, <i>vibrato-gain</i>, <i>reed-stiffness</i>, <i>noise</i>, <i>blow-pos</i>, <i>reed-table-offset</i>)</code> [SAL]<br>
1623
1624 <code>(sax-all <i>step</i> <i>breath-env</i> <i>freq-env</i> <i>vibrato-freq</i> <i>vibrato-gain</i> <i>reed-stiffness</i> <i>noise</i> <i>blow-pos</i> <i>reed-table-offset</i>)</code> [LISP]</dt>
1625 <dd>A variation of
1626 <code>sax-freq</code>
1627 that includes controls <i>vibrato-freq</i> (a <code>FLONUM</code> for vibrato frequency in Hertz),
1628 <i>vibrato-gain</i> (a <code>FLONUM</code> for the amount of amplitude vibrato),
1629 <i>reed-stiffness</i> (a <code>SOUND</code> controlling reed stiffness in the sax
1630 model), <i>noise</i> (a <code>SOUND</code> controlling noise amplitude in the input
1631 air pressure), <i>blow-pos</i> (a <code>SOUND</code> controlling the point of excitation
1632 of the air column), and <i>reed-table-offset</i> (a <code>SOUND</code> controlling a
1633 parameter of the reed model). The <i>vibrato-gain</i> is a number from zero to one, where zero
1634 indicates no vibrato, and one indicates a plus/minus 50% change in breath
1635 envelope values. Similarly, the <i>noise</i> parameter ranges from zero to one where
1636 zero means no noise and one means white noise with a peak amplitude of
1637 plus/minus 40% of the <i>breath-env</i>. The <i>reed-stiffness</i>, <i>blow-pos</i>, and
1638 <i>reed-table-offset</i> parameters all vary from zero to one.
1639 The duration of the resulting sound is the minimum duration of
1640 <i>breath-env</i>, <i>freq-env</i>, <i>reed-stiffness</i>, <i>noise</i>, <i>breath-env</i>,
1641 <i>blow-pos</i>, and <i>reed-table-offset</i>. As with
1642 <code>sax-freq</code>, these parameters may be either <code>FLONUM</code>s or
1643 <code>SOUND</code>s, and <code>FLONUM</code>s are coerced to sounds with a nominal
1644 duration of 30.<br><br>
1645 <dt>
1646 <code>flute(<a name="index532"></a><a name="index533"></a><i>step</i>, <i>breath-env</i>)</code> [SAL]<br>
1647
1648 <code>(flute <i>step</i> <i>breath-env</i>)</code> [LISP]</dt>
1649 <dd>A physical model of a flute from STK.
1650 The <i>step</i> parameter is a <code>FLONUM</code> that controls the tube
1651 length, and the <i>breath-env</i>
1652 controls the air pressure and also determines the starting time and
1653 length of the resulting sound. The <i>breath-env</i> signal should
1654 range from zero to one.<br><br>
1655 <dt><code>flute-freq(<a name="index534"></a><a name="index535"></a><i>step</i>, <i>breath-env</i>, <i>freq-env</i>)</code> [SAL]<br>
1656
1657 <code>(flute-freq <i>step</i> <i>breath-env</i> <i>freq-env</i>)</code> [LISP]</dt>
1658 <dd>A variation of <code>flute</code>
1659 that includes a variable frequency control, <i>freq-env</i>, which
1660 specifies frequency deviation in Hz. The duration of the
1661 resulting sound is the minimum duration of <i>breath-env</i> and
1662 <i>freq-env</i>. These parameters may be of type <code>FLONUM</code> or
1663 <code>SOUND</code>. <code>FLONUM</code>s are coerced into SOUNDs with a
1664 nominal duration arbitrarily set to 30.<br><br>
1665 <dt><code>flute-all(<a name="index536"></a><a name="index537"></a><i>step</i>,
1666 <i>breath-env</i>, <i>freq-env</i>, <i>vibrato-freq</i>,
1667 <i>vibrato-gain</i>, <i>jet-delay</i>, <i>noise</i>)</code> [SAL]<br>
1668
1669 <code>(flute-all <i>step</i> <i>breath-env</i> <i>freq-env</i> <i>vibrato-freq</i> <i>vibrato-gain</i> <i>jet-delay</i> <i>noise</i>)</code> [LISP]</dt>
1670 <dd>A variation of
1671 <code>clarinet-freq</code> that includes controls <i>vibrato-freq</i> (a
1672 <code>FLONUM</code> for vibrato frequency in Hz), <i>vibrato-gain</i> (a
1673 <code>FLONUM</code> for the amount of amplitude vibrato), <i>jet-delay</i>
1674 (a <code>FLONUM</code> or <code>SOUND</code> controlling jet delay in the
1675 flute model), and
1676 noise (a <code>FLONUM</code> or <code>SOUND</code> controlling noise amplitude
1677 in the input air pressure). The <i>vibrato-gain</i> is a number from zero
1678 to one where zero means no vibrato, and one indicates a plus/minus
1679 50% change in breath envelope values. Similarly, the <i>noise</i> parameter
1680 ranges from zero to one, where zero means no noise and one means white
1681 noise with a peak amplitude of
1682 plus/minus 40% of the <i>breath-env</i>. The <i>jet-delay</i> is a ratio
1683 that controls a delay length from the flute model, and therefore it
1684 changes the pitch of the resulting sound. A value of 0.5 will maintain
1685 the pitch indicated by the step parameter. The duration of the
1686 resulting sound is the minimum duration of <i>breath-env</i>, <i>freq-env</i>,
1687 <i>jet-delay</i>, and <i>noise</i>. These parameters may be either
1688 <code>FLONUM</code>s or <code>SOUND</code>s, and <code>FLONUM</code>s are coerced
1689 to sounds with a nominal duration of 30. <br><br>
1690 <dt>
1691 <code>bowed(<a name="index538"></a><a name="index539"></a><i>step</i>, <i>bowpress-env</i>)</code> [SAL]<br>
1692
1693 <code>(bowed <i>step</i> <i>bowpress-env</i>)</code> [LISP]</dt>
1694 <dd>A physical model of a bowed string
1695 instrument from STK. The <i>step</i> parameter is a <code>FLONUM</code>
1696 that controls the string length,
1697 and the <i>bowpress-env</i> controls the bow pressure and also
1698 determines the duration of the resulting sound. The <i>bowpress-env</i>
1699 signal should range from zero to one.<br><br>
1700 <dt><code>bowed-freq(<a name="index540"></a><a name="index541"></a><i>step</i>, <i>bowpress-env</i>, <i>freq-env</i>)</code> [SAL]<br>
1701
1702 <code>(bowed-freq <i>step</i> <i>bowpress-env</i> <i>freq-env</i>)</code> [LISP]</dt>
1703 <dd>A variation of <code>bowed</code>
1704 that includes a variable frequency control, <i>freq-env</i>, which
1705 specifies frequency deviation in Hz. The duration of the resulting
1706 sound is the minimum duration of <i>bowpress-env</i> and <i>freq-env</i>.
1707 These parameters may be of type <code>FLONUM</code> or <code>SOUND</code>.
1708 <code>FLONUM</code>s are coerced into <code>SOUND</code>s
1709 with a nominal duration arbitrarily set to 30s.<br><br>
1710 <dt>
1711 <code>mandolin(<a name="index542"></a><a name="index543"></a><i>step</i>, <i>dur</i>, &amp;optional <i>detune</i>)</code> [SAL]<br>
1712
1713 <code>(mandolin <i>step</i> <i>dur</i> <i>detune</i>)</code> [LISP]</dt>
1714 <dd>A physical model of a
1715 plucked double-string instrument from STK. The <i>step</i> parameter
1716 is a <code>FLONUM</code> wich specifies the desired pitch, <i>dur</i>
1717 means the duration of the resulting sound and detune is a
1718 <code>FLONUM</code> that controls the relative detune of the two strings.
1719 A value of 1.0 means unison. The default value is 4.0.
1720 Note: <i>body-size</i> (see <code>snd-mandolin</code> does not seem to
1721 work correctly, so a default value is always used
1722 by <code>mandolin</code>.<br><br>
1723 <dt>
1724 <code>wg-uniform-bar(<a name="index544"></a><a name="index545"></a><i>step</i>, <i>bowpress-env</i>)</code> [SAL]<br>
1725
1726 <code>(wg-uniform-bar <i>step</i> <i>bowpress-env</i>)</code> [LISP]<br><br>
1727 <dt><code>wg-tuned-bar(<a name="index546"></a><a name="index547"></a><i>step</i>, <i>bowpress-env</i>)</code> [SAL]<br>
1728
1729 <code>(wg-tuned-bar <i>step</i> <i>bowpress-env</i>)</code> [LISP]<br><br>
1730 <dt><code>wg-glass-harm(<a name="index548"></a><a name="index549"></a><i>step</i>, <i>bowpress-env</i>)</code> [SAL]<br>
1731
1732 <code>(wg-glass-harm <i>step</i> <i>bowpress-env</i>)</code> [LISP]<br><br>
1733 <dt><code>wg-tibetan-bowl(<a name="index550"></a><a name="index551"></a><i>step</i>, <i>bowpress-env</i>)</code> [SAL]<br>
1734
1735 <code>(wg-tibetan-bowl <i>step</i> <i>bowpress-env</i>)</code> [LISP]</dt>
1736 <dd>These
1737 sounds are presets for a Banded Wave Guide Percussion instrument implemented in STK.
1738 The parameter <i>step</i> is a <code>FLONUM</code>
1739 that controls the resultant pitch, and <i>bowpress-env</i> is a <code>SOUND</code> ranging
1740 from zero to one that controls a parameter of the model. In addition,
1741 <i>bowpress-env</i> determines the duration of the resulting sound.
1742 (Note: The <i>bowpress-env</i> does not seems influence the timbral
1743 quality of the resulting sound).<br><br>
1744 <dt>
1745 <code>modalbar(<a name="index552"></a><a name="index553"></a><i>preset</i>, <i>step</i>, <i>dur</i>)</code> [SAL]<br>
1746
1747 <code>(modalbar <i>preset</i> <i>step</i> <i>dur</i>)</code> [LISP]</dt>
1748 <dd>A physical model of a struck bar
1749 instrument implemented in STK. The parameter <i>preset</i> is one of the
1750 symbols
1751 <code>MARIMBA</code>, <code>VIBRAPHONE</code>, <code>AGOGO</code>, <code>WOOD1</code>,
1752 <code>RESO</code>, <code>WOOD2</code>, <code>BEATS</code>, <code>TWO-FIXED</code>, or
1753 <code>CLUMP</code>. The symbol must be quoted, e.g. for SAL syntax use
1754 <code>quote(marimba)</code>, and for Lisp syntax use <code>'marimba</code>.
1755 The parameter <i>step</i> is a <code>FLONUM</code> that
1756 sets the pitch (in steps), and <i>dur</i> is the duration in seconds.<br><br>
1757 <dt>
1758 <code>sitar(<a name="index554"></a><a name="index555"></a><i>step</i>, <i>dur</i>)</code> [SAL]<br>
1759
1760 <code>(sitar <i>step</i> <i>dur</i>)</code> [LISP]</dt>
1761 <dd>A sitar physical model implemented in STK.
1762 The parameter <i>step</i> is a <code>FLONUM</code> that sets the pitch,
1763 and <i>dur</i> is the duration.<br><br>
1764 <dt>
1765 <code>stk-breath-env(<a name="index556"></a><a name="index557"></a><i>dur</i>, <i>note-on</i> <i>note-off</i>)</code> [SAL]<br>
1766
1767 <code>(stk-breath-env <i>dur</i> <i>note-on</i> <i>note-off</i>)</code> [LISP]</dt>
1768 <dd>A simple envelope function
1769 intended for STK instruments such as <code>CLARINET</code>, where <i>dur</i> is the duration, <i>note-on</i> is the
1770 attack time, and <i>note-off</i> is the decay time, all <code>FLONUM</code>s in seconds.
1771 </dd></dl><a name = "96"><h5>Phase Vocoder</h5></a><dl>
1772 <dt>
1773
1774 <code>phasevocoder(<a name="index558"></a><a name="index559"></a><a name="index560"></a><a name="index561"></a><i>s</i>,
1775 <i>map</i>, [<i>fftsize</i>, <i>hopsize</i>, <i>mode</i>])</code> [SAL]<br>
1776
1777 <code>(phasevocoder <i>s</i> <i>map</i> [<i>fftsize</i> <i>hopsize</i> <i>mode</i>])</code>
1778 [LISP]</dt>
1779 <dd>Phase vocoder: the input SOUND <i>s</i> is stretched in
1780 time according to the control signal (a SOUND) <i>map</i>. The <i>map</i> parameter
1781 must be strictly non-decreasing. It specifies the input time for each time
1782 in the output. E.g. if <i>map</i> at time 3 is 4, then the output at time 3 will
1783 sound like the input at time 4, assuming <i>s</i> and <i>map</i> start at time 0.
1784 In the general case, <i>s</i> and <i>map</i> must start at the same time. The phase
1785 vocoder operation is applied as if <i>s</i> and <i>map</i> started at time 0, and
1786 the result is shifted to start at the same starting time as <i>s</i> and <i>map</i>.
1787 The <i>fftsize</i> is a FIXNUM and power of 2, indicating the size of the
1788 analysis and synthesis windows in samples. The default is 2048.
1789 The <i>hopsize</i> is the hop size (in samples, a FIXNUM) of the
1790 synthesis stage where overlapping windows are added. The <i>hopsize</i>
1791 should be a power of 2 that is smaller than the <i>fftsize</i>. The default is
1792 the <i>fftsize</i>/8. Note that the analysis hopsize is determined by the <i>map</i>.
1793 If the playback speed (slope of <i>map</i>) is too great, the analysis hopsize
1794 will be large and the sound quality will suffer. You can always make the
1795 analysis hopsize smaller by making the synthesis hopsize smaller (at the
1796 cost of greater computation). The <i>mode</i> is a FIXNUM that defaults to
1797 0, meaning a standard phase vocoder. A value of 1 invokes a phase computation
1798 that attempts to reduce phase artifacts by preserving the phase relationships
1799 between peaks and nearby bins. A value of 2 invokes a &ldquo;robot voice&rdquo; mode
1800 that assigns fixed phases and creates a constant pitch (controlled
1801 by the hopsize) vocoder-like effect. (Thanks to M.C.Sharma for this idea.)
1802 A phase vocoder constructs output from overlapped and added windowed
1803 IFFT frames. This presents a special problem at the beginning and
1804 ending of the output sound. To output a sound starting at time <i>t</i>,
1805 the first frame is centered at <i>t</i> + <i>fftsize</i>/2, so the output at
1806 <i>t</i> will smoothly rise from zero because all frames are smoothed by
1807 a windowing function. Considerations are: (1) The output at time <i>t</i>
1808 will rise from zero rather than being the sum of multiple overlapping
1809 windows; (2) if <i>t</i> maps to an input window that begins before
1810 the start time of the input sound, the input window will be padded
1811 with zeros and may include an abrupt onset if one exists at the
1812 start of the input sound.<br><br>
1813 <dt><code>pv-time-pitch(<a name="index562"></a><a name="index563"></a><a name="index564"></a><i>s</i>,
1814 <i>stretchfn</i>, <i>pitchfn</i>, <i>dur</i>, [<i>fftsize</i>, <i>hopsize</i>, <i>mode</i>])</code> [SAL]<br>
1815
1816 <code>(pv-time-pitch <i>s</i> <i>stretchfn</i> <i>pitchfn</i> <i>dur</i> [<i>fftsize</i> <i>hopsize</i> <i>mode</i>])</code> [LISP]</dt>
1817 <dd>Combines phase vocoder and resampling
1818 to perform simultaneous time stretching and pitch shifting. The input SOUND
1819 <i>s</i> is stretched according to SOUND <i>stretchfn</i> and pitch-shifted according
1820 to SOUND <i>pitchfn</i>. The approximate output duration should be specified by
1821 <i>dur</i> (which is used to optimize the sample rate of computed control
1822 functions), and the remaining parameters <i>fftsize</i>, <i>hopsize</i> and
1823 <i>mode</i> are passed to the phase vocoder (see <code>phasevocoder</code> above). The
1824 <i>stretchfn</i> gives the factor by which the input should be stretched at each
1825 point in time; thus, the total duration is the <i>integral</i> of this function. The <i>pitchfn</i> specifies the amount by which pitch should be shifted at each
1826 point in time. For example, where <i>pitchfn</i> is 2, the sample rate will be
1827 doubled, increasing pitch and frequencies by an octave. The phase vocoder is
1828 used to compensate for time stretching caused by resampling,
1829 so <i>stretchfn</i> and <i>pitchfn</i> operate independently.
1830 </dd></dl><a name = "97"><h5>More Behaviors</h5></a><dl>
1831 <dt>
1832
1833 <code>clip(<a name="index565"></a><a name="index566"></a><i>sound</i>, <i>peak</i>)</code> [SAL]<br>
1834
1835 <code>(clip <i>sound</i> <i>peak</i>)</code> [LISP]</dt>
1836 <dd>Hard limit <i>sound</i>
1837 to the given <i>peak</i>, a positive number. The samples of <i>sound</i> are constrained between an upper value
1838 of <i>peak</i> and a lower value of -<i>peak</i>. If <i>sound</i> is a number, <code>clip</code> will return <i>sound</i> limited by <i>peak</i>. If <i>sound</i> is a multichannel sound, <code>clip</code> returns a multichannel sound where each channel is clipped. The result has the type, sample rate, starting time, etc. of <i>sound</i>.
1839 <b><i>Note:</i></b> Many systems clip output when converting to fixed-point audio, e.g. 16-bit samples. Instead Nyquist simply takes the low-order 16 bits, allowing
1840 samples to &ldquo;wrap around.&rdquo; This sounds <i>terrible</i>, but that is the point:
1841 It is hard to miss when your samples go out of range. One use of this function
1842 is to clip rather than wrap output. <b><i>Warning:</i></b> A floating point sample
1843 value of 1.0 maps to
1844 2<sup>15</sup>
1845 in 16-bit audio, but the maximum 16-bit sample
1846 value is
1847 2<sup>15</sup>-1!
1848 If your goal is to clip to the 16-bit range, you should
1849 set <i>peak</i> to the ratio 32767.0/32768.0. For 24-bit audio, use
1850 (2<sup>23</sup>-1)/2<sup>23</sup>, etc.<br><br>
1851 <dt>
1852 <code>s-abs(<a name="index567"></a><a name="index568"></a><i>sound</i>)</code> [SAL]<br>
1853
1854 <code>(s-abs <i>sound</i>)</code> [LISP]</dt>
1855 <dd>A generalized absolute value
1856 function. If <i>sound</i> is a <code>SOUND</code>, compute the absolute value
1857 of each sample. If <i>sound</i> is a number, just compute the absolute
1858 value. If <i>sound</i> is a multichannel sound, return a multichannel
1859 sound with <code>s-abs</code> applied to each element. The result has the
1860 type, sample rate, starting time, etc. of <i>sound</i>.<br><br>
1861 <dt>
1862 <code>s-avg(<a name="index569"></a><a name="index570"></a><a name="index571"></a><a name="index572"></a><a name="index573"></a><i>sound</i>, <i>blocksize</i>, <i>stepsize</i>, <i>operation</i>)</code> [SAL]<br>
1863
1864 <code>(s-avg <i>sound</i> <i>blocksize</i> <i>stepsize</i> <i>operation</i>)</code> [LISP]</dt>
1865 <dd>Computes the averages
1866 or peak values of blocks of samples. Each output sample is an average or
1867 peak of <i>blocksize</i> (a fixnum) adjacent samples from the input <i>sound</i>.
1868 After each average or peak is taken, the input is advanced by <i>stepsize</i>,
1869 a fixnum which may be greater or less than <i>blocksize</i>. The output
1870 sample rate is the <i>sound</i> (input) sample rate divided by
1871 <i>stepsize</i>. The duration of the output is the same (approximately,
1872 due to rounding) as that of <i>sound</i>. Notice however, that the
1873 features of the input will appear earlier in the output by half the
1874 window size. For example, a sharp peak in the input will result in a
1875 smoothed peak (using <code>OP-AVERAGE</code>) one half <i>blocksize</i>
1876 earlier. You can correct for this shift by inserting one half
1877 <i>blocksize</i> of silence before <i>sound</i>,
1878 e.g. if <code>s</code> has a sample rate of 44100 Hz, then
1879 <code>snd-avg(seq(s-rest(0.01), cue(s)), 882, 441, OP-AVERAGE)</code> will
1880 shift <code>s</code> by 0.01 s to compensate for the shift introduced by a
1881 smoothing window of size 0.02 s (882/44100).
1882 If <i>sound</i> is a multichannel sound, return a multichannel
1883 sound with <code>s-avg</code> applied to each element.
1884 This function is useful for computing low-sample-rate rms or peak
1885 amplitude signals for input to <code>snd-gate</code> or <code>snd-follow</code>.
1886 To select the operation, <i>operation</i> should be one of <code>OP-AVERAGE</code>
1887 or <code>OP-PEAK</code>. (These are global lisp variables; the actual
1888 <i>operation</i> parameter is an integer.) For RMS computation, see
1889 <code>rms</code> in Section <a href = "#97">More Behaviors</a>.<br><br>
1890 <dt>
1891 <code>s-sqrt(<a name="index574"></a><a name="index575"></a><i>sound</i>)</code> [SAL]<br>
1892
1893 <code>(s-sqrt <i>sound</i>)</code> [LISP]</dt>
1894 <dd>A generalized square root function. If <i>sound</i> is a <code>SOUND</code>, compute the square root of each sample. If <i>sound</i> is a number, just compute the square root. If <i>sound</i> is a multichannel sound, return a multichannel sound with <code>s-sqrt</code> applied to each element. The result has the type, sample rate, starting time, etc. of <i>sound</i>. In taking square roots, if an input sample is less than zero, the corresponding output sample is zero. This is done because the square root of a negative number is undefined.<br><br>
1895 <dt>
1896 <code>s-exp(<a name="index576"></a><a name="index577"></a><i>sound</i>)</code> [SAL]<br>
1897
1898 <code>(s-exp <i>sound</i>)</code> [LISP]</dt>
1899 <dd>A generalized exponential function. If <i>sound</i> is a <code>SOUND</code>, compute <i>e</i><sup T><i>x</i></sup> for each sample <i>x</i>. If <i>sound</i> is a number <i>x</i>, just compute <i>e</i><sup T><i>x</i></sup>. If <i>sound</i> is a multichannel sound, return a multichannel sound with <code>s-exp</code> applied to each element. The result has the type, sample rate, starting time, etc. of <i>sound</i>.<br><br>
1900 <dt>
1901 <code>s-log(<a name="index578"></a><a name="index579"></a><a name="index580"></a><i>sound</i>)</code> [SAL]<br>
1902
1903 <code>(s-log <i>sound</i>)</code> [LISP]</dt>
1904 <dd>A generalized natural log function. If <i>sound</i> is a <code>SOUND</code>, compute <i>ln</i>(<i>x</i>) for each sample <i>x</i>. If <i>sound</i> is a number <i>x</i>, just compute <i>ln</i>(<i>x</i>). If <i>sound</i> is a multichannel sound, return a multichannel sound with <code>s-log</code> applied to each element. The result has the type, sample rate, starting time, etc. of <i>sound</i>. Note that the <i>ln</i> of 0 is undefined (some implementations return negative infinity), so use this function with care.<br><br>
1905 <dt>
1906 <code>s-max(<a name="index581"></a><a name="index582"></a><i>sound1</i>, <i>sound2</i>)</code> [SAL]<br>
1907
1908 <code>(s-max <i>sound1</i> <i>sound2</i>)</code> [LISP]</dt>
1909 <dd>Compute
1910 the maximum of two functions, <i>sound1</i> and <i>sound2</i>. This function
1911 also accepts numbers and multichannel sounds and returns the
1912 corresponding data type. The start time of the result is the maximum
1913 of the start times of <i>sound1</i> and <i>sound2</i>. The logical stop time
1914 and physical stop time of the result is the minimum of the logical
1915 stop and physical stop times respectively of <i>sound1</i> and
1916 <i>sound2</i>. Note, therefore, that the result value is zero except
1917 within the bounds of <i>both</i> input sounds.<br><br>
1918 <dt><code>s-min(<a name="index583"></a><a name="index584"></a><i>sound1</i>, <i>sound2</i>)</code> [SAL]<br>
1919
1920 <code>(s-min <i>sound1</i> <i>sound2</i>)</code> [LISP]</dt>
1921 <dd>Compute the minimum of two functions, <i>sound1</i> and <i>sound2</i>. This function also accepts numbers and multichannel sounds and returns the corresponding data type. The start time of the result is the maximum of the start times of <i>sound1</i> and <i>sound2</i>. The logical stop time and physical stop time of the result is the minimum of the logical stop and physical stop times respectively of <i>sound1</i> and <i>sound2</i>. Note, therefore, that the result value is zero except within the bounds of <i>both</i> input sounds.<br><br>
1922 <dt><code>osc-note(<a name="index585"></a><i>pitch</i> [, <i>duration</i>, <i>env</i>, <i>loud</i>,
1923 <i>table</i>])</code> [SAL]<br>
1924
1925 <code>(osc-note <i>pitch</i> [<i>duration</i> <i>env</i> <i>loud</i> <i>table</i>])</code> [LISP]</dt>
1926 <dd>Same as <code>osc</code>, but <code>osc-note</code>
1927 multiplies the result by <i>env</i>. The <i>env</i> may be a sound,
1928 or a list supplying (<i>t<sub>1</sub></i> <i>t<sub>2</sub></i>
1929 <i>t<sub>4</sub></i> <i>l<sub>1</sub></i> <i>l<sub>2</sub></i> <i>l<sub>3</sub></i>). The result has a sample rate of <code>*sound-srate*</code>.<br><br>
1930 <dt>
1931 <code>quantize(<a name="index586"></a><i>sound</i>, <i>steps</i>)</code> [SAL]<br>
1932
1933 <code>(quantize <i>sound</i> <i>steps</i>)</code> [LISP]</dt>
1934 <dd>Quantizes <i>sound</i> as follows: <i>sound</i> is multiplied by <i>steps</i> and rounded to the nearest integer. The result is then divided by <i>steps</i>. For example, if <i>steps</i> is 127, then a signal that ranges from -1 to +1 will be quantized to 255 levels (127 less than zero, 127 greater than zero, and zero itself). This would match the quantization Nyquist performs when writing a signal to an 8-bit audio file. The <i>sound</i> may be multichannel.<br><br>
1935 <dt><code>ramp(<a name="index587"></a>[<i>duration</i>])</code> [SAL]<br>
1936
1937 <code>(ramp [<i>duration</i>])</code> [LISP]</dt>
1938 <dd>Returns a
1939 linear ramp from 0 to 1
1940 over <i>duration</i> (default is 1). The function actually reaches 1 at
1941 <i>duration</i>, and therefore has one extra sample, making the total duration
1942 be <i>duration</i> + 1/<code>*Control-srate*</code>. See Figure <a href = "#97">6</a> for
1943 more detail. Ramp is unaffected by the <code>sustain</code> transformation. The
1944 effect of time warping is to warp the starting and ending times only. The
1945 ramp itself is unwarped (linear). The sample rate is <code>*control-srate*</code>.<br><br>
1946 <dt>
1947 <code>rms(<a name="index588"></a><i>sound</i> [, <i>rate</i>, <i>window-size</i>])</code> [SAL]<br>
1948
1949 <code>(rms <i>sound</i> [<i>rate</i> <i>window-size</i>])</code> [LISP]</dt>
1950 <dd>Computes
1951 the RMS of <i>sound</i> using a square window of size
1952 <i>window-size</i>. The result has a sample rate of <i>rate</i>. The default
1953 value of <i>rate</i> is 100 Hz, and the default window size is 1/rate
1954 seconds (converted to samples). The <i>sound</i> is a SOUND or a multichannel
1955 sound (in which case the result is a multichannel sound).
1956 The <i>rate</i> is a <code>FLONUM</code> and <i>window-size</i> is a <code>FIXNUM</code>.<br><br>
1957 <dt>
1958 <code>recip(<a name="index589"></a><a name="index590"></a><a name="index591"></a><i>sound</i>)</code> [SAL]<br>
1959
1960 <code>(recip <i>sound</i>)</code> [LISP]</dt>
1961 <dd>A generalized reciprocal function.
1962 If <i>sound</i> is a <code>SOUND</code>, compute 1/<i>x</i> for each sample <i>x</i>. If <i>sound</i> is a number <i>x</i>, just compute 1/<i>x</i>. If <i>sound</i> is a multichannel sound, return a multichannel sound with <code>recip</code> applied to each element. The result has the type, sample rate, starting time, etc. of <i>sound</i>. Note that the reciprocal of 0 is undefined (some implementations return infinity), so use this function with care on sounds. Division of sounds is accomplished by multiplying by the reciprocal. Again, be careful not to divide by zero.
1963 </dd></dl>
1964 <hr>
1965 <blockquote>
1966 </blockquote>
1967 <img src="fig6.gif"><br><br>
1968
1969 <p><b>Figure 6: </b>Ramps generated by <code>pwl</code> and <code>ramp</code> functions. The
1970 <code>pwl</code> version ramps toward the breakpoint (1, 1), but in order to ramp
1971 back to zero at breakpoint (1, 0), the function never reaches an amplitude
1972 of 1. If used at the beginning of a <code>seq</code> construct, the next sound
1973 will begin at time 1. The <code>ramp</code> version actually reaches breakpoint
1974 (1, 1); notice that it is one sample longer than the <code>pwl</code> version. If
1975 used in a sequence, the next sound after <code>ramp</code> would start at time 1 +
1976 <i>P</i>, where <i>P</i> is the sample period.
1977
1978 </p>
1979 <hr>
1980 <dl>
1981 <dt>
1982 <code>s-rest(<a name="index592"></a><a name="index593"></a>[<i>duration</i>])</code> [SAL]<br>
1983
1984 <code>(s-rest [<i>duration</i>])</code> [LISP]</dt>
1985 <dd>Create silence (zero samples)
1986 for the given
1987 <i>duration</i> at the sample rate <code>*sound-srate*</code>.
1988 Default duration is 1.0 sec, and the sound is transformed in time according
1989 to <code>*warp*</code>. <b><i>Note:</i></b> <code>rest</code> is a Lisp function that is equivalent to <code>cdr</code>. Be careful to use <code>s-rest</code> when you need a sound!<br><br>
1990 <dt>
1991 <code>noise(<a name="index594"></a>[<i>duration</i>])</code> [SAL]<br>
1992
1993 <code>(noise <i>duration</i>)</code> [LISP]</dt>
1994 <dd>Generate noise with the given
1995 <i>duration</i>. Duration (default is 1.0)
1996 is transformed according to <code>*warp*</code>. The
1997 sample rate is <code>*sound-srate*</code> and the amplitude is +/- <code>*loud*</code>.<br><br>
1998 <dt>
1999 <code>yin(<a name="index595"></a><a name="index596"></a><a name="index597"></a><a name="index598"></a><a name="index599"></a><a name="index600"></a><i>sound</i>, <i>minstep</i>, <i>maxstep</i>, <i>stepsize</i>)</code> [SAL]<br>
2000
2001 <code>(yin <i>sound</i> <i>minstep</i> <i>maxstep</i> <i>stepsize</i>)</code> [LISP]</dt>
2002 <dd>Fundamental
2003 frequency estimation (pitch detection. Use the YIN algorithm to estimate
2004 the fundamental frequency of <i>sound</i>, which must be a <code>SOUND</code>.
2005 The <i>minstep</i>, a <code>FLONUM</code>, is the minimum frequency considered (in steps),
2006 <i>maxstep</i>, a <code>FLONUM</code>, is the maximum frequency considered (in steps), and
2007 <i>stepsize</i>, a <code>FIXNUM</code>, is the desired hop size. The result is
2008 a &ldquo;stereo&rdquo; signal,
2009 i.e. an array of two <code>SOUND</code>s, both at the same sample rate, which is
2010 approximately the sample rate of <i>sound</i> divided by <i>stepsize</i>.
2011 The first <code>SOUND</code> consists of frequency estimates (in units of
2012 steps, i.e. middle C = 60). The second sound consists
2013 of values that measure the confidence or reliability of the frequency estimate.
2014 A small value (less than 0.1) indicates fairly high confidence. A larger value
2015 indicates lower confidence. This number can also be thought of as a ratio of
2016 non-periodic power to periodic power. When the number is low, it means the signal
2017 is highly periodic at that point in time, so the period estimate will be
2018 reliable.
2019 Hint #1: See
2020 Alain de Cheveigne and Hideki Kawahara's article "YIN, a Fundamental Frequency
2021 Estimator for Speech and Music" in the Journal of the
2022 Acoustic Society of America, April 2002 for details on the yin algorithm.
2023 Hint #2: Typically, the <i>stepsize</i> should be at least the expected number
2024 of samples in one period so that the
2025 fundamental frequency estimates are calculated at a rate far below
2026 the sample rate of the signal. Frequency does not change rapidly and
2027 the yin algorithm is fairly slow. To optimize speed,
2028 you may want to use less than 44.1 kHz sample rates for input sounds.Yin
2029 uses interpolation to achieve potentially fractional-sample-accurate estimates,
2030 so higher sample rates do not necessarily help the algorithm and definitely
2031 slow it down. The computation time is O(<i>n</i><sup T>2</sup>) per estimate,
2032 where <i>n</i> is the number
2033 of samples in the longest period considered. Therefore, each increase
2034 of <i>minstep</i> by 12 (an octave) gives you a factor of 4 speedup, and
2035 each decrease of the sample rate of <i>sound</i> by a factor of
2036 two gives you another factor of 4 speedup. Finally, the number of estimates is
2037 inversely proportional to <i>stepsize</i>.
2038 Hint #3: Use <code>snd-srate</code> (see Section <a href = "#86">Accessing and Creating Sound</a>) to get
2039 the exact sample rate of the result, which will be the sample rate of
2040 <i>sound</i> divided by <i>stepsize</i>.
2041 E.g. <code>(snd-srate (aref yin-output 0))</code>,
2042 where <code>yin-output</code> is a result returned by <code>yin</code>, will be the
2043 sample rate of the estimates.
2044 </dd></dl><a name = "98"><h3>Transformations</h3></a><a name="index601"></a>
2045 <p>These functions change the environment that is seen by other high-level
2046 functions. Note that these changes are usually relative to the
2047 current environment. There are also &ldquo;absolute&rdquo; versions of each
2048 transformation function, with the exception of <code>seq</code>,
2049 <code>seqrep</code>, <code>sim</code>, and <code>simrep</code>. The
2050 &ldquo;absolute&rdquo; versions (starting or ending with &ldquo;abs&rdquo;) do not look at the
2051 current environment, but rather set an environment variable to a specific value.
2052 In this way, sections of code can be insulated from external
2053 transformations.</p>
2054 <dl>
2055 <dt>
2056 <code>abs-env(<a name="index602"></a><i>beh</i>)</code> [SAL]<br>
2057
2058 <code>(abs-env <i>beh</i>)</code> [LISP]</dt>
2059 <dd>Compute <i>beh</i> in the default environment.
2060 This is useful for computing waveform tables and signals that are
2061 &ldquo;outside&rdquo; of
2062 time. For example, <code>(at 10.0 (abs-env (my-beh)))</code> is equivalent to
2063 <code>(abs-env (my-beh))</code> because <code>abs-env</code> forces the default environment. Or in SAL, we would say <code>abs-env(my-beh()) @ 10</code> is equivalent to <code>abs-env(my-beh())</code>.<br><br>
2064 <dt><code>at(<a name="index603"></a><i>time</i>, <i>beh</i>)</code> [SAL]<br>
2065
2066 <code>(at <i>time</i> <i>beh</i>)</code> [LISP]</dt>
2067 <dd>Evaluate <i>beh</i> with
2068 <code>*warp*<a name="index604"></a></code> shifted by <i>time</i>. In SAL, you can use the infix
2069 operator <code>@</code> as in <code><i>beh</i> @ <i>time</i></code>. To discover how the
2070 environment is shifting time, use <code>local-to-global(<i>time</i>)</code>. Most
2071 commonly, you call <code>local-to-global(0)</code> to find when a sound created
2072 in the current environment will start, expressed in absolute (global) terms.
2073 This can be regarded as the &ldquo;current time.&rdquo;<br><br>
2074 <dt><code>at-abs(<a name="index605"></a><i>time</i>, <i>beh</i>)</code> [SAL]<br>
2075
2076 <code>(at-abs <i>time</i> <i>beh</i>)</code> [LISP]</dt>
2077 <dd>Evaluate <i>beh</i> with
2078 <code>*warp*<a name="index606"></a></code> shifted so that local time 0 maps to <i>time</i>. In SAL, you can use the infix operator <code>@@</code> as in <code><i>beh</i> @@ <i>time</i></code>.<br><br>
2079 <dt>
2080 <code>continuous-control-warp(<a name="index607"></a><i>beh</i>)</code> [SAL]<br>
2081
2082 <code>(continuous-control-warp <i>beh</i>)</code> [LISP]</dt>
2083 <dd>Applies the current warp environment to the signal returned by <i>beh</i>. The result has the default control sample rate <code>*control-srate*</code>. Linear interpolation is currently used. Implementation: <i>beh</i> is first evaluated without any shifting, stretching, or warping. The result is functionally composed with the inverse of the environment's warp function.<br><br>
2084 <dt>
2085 <code>continuous-sound-warp(<a name="index608"></a><i>beh</i>)</code> [SAL]<br>
2086
2087 <code>(continuous-sound-warp <i>beh</i>)</code> [LISP]</dt>
2088 <dd>Applies the current warp environment to the signal returned by <i>beh</i>. The result has the default sound sample rate <code>*sound-srate*</code>. Linear interpolation is currently used. See <code>continuous-control-warp</code> for implementation notes.<br><br>
2089 <dt>
2090 <code>control-srate-abs(<a name="index609"></a><i>srate</i>,
2091 <i>beh</i>)</code> [SAL]<br>
2092
2093 <code>(control-srate-abs <i>srate</i> <i>beh</i>)</code> [LISP]</dt>
2094 <dd>Evaluate <i>beh</i> with <code>*control-srate*<a name="index610"></a></code>
2095 set to sample rate <i>srate</i>. <b><i>Note:</i></b> there is no &ldquo;relative&rdquo; version of
2096 this function.<br><br>
2097 <dt><code>extract(<a name="index611"></a><i>start</i>, <i>stop</i>, <i>beh</i>)</code> [SAL]<br>
2098
2099 <code>(extract <i>start</i> <i>stop</i> <i>beh</i>)</code> [LISP]</dt>
2100 <dd>Returns a sound
2101 which is the portion of
2102 <i>beh</i> between <i>start</i> and <i>stop</i>. Note that this is done
2103 relative to the current <code>*warp*</code>. The result is shifted
2104 to start according to <code>*warp*</code>, so normally the result will start without a delay of <i>start</i>.<br><br>
2105 <dt><code>extract-abs(<a name="index612"></a><i>start</i>, <i>stop</i>, <i>beh</i>)</code> [SAL]<br>
2106
2107 <code>(extract-abs <i>start</i> <i>stop</i> <i>beh</i>)</code> [LISP]</dt>
2108 <dd>Returns a sound which
2109 is the portion of
2110 <i>beh</i> between <i>start</i> and <i>stop</i>, independent of the
2111 current <code>*warp*</code>. The result is shifted to start at time zero.
2112 Wrapping a call to <code>extract-abs</code> in <code>cue</code> will shift the result to
2113 start at the current time, which is <code>local-to-global(0</code>).<br><br>
2114 <dt><code>loud(<a name="index613"></a><i>volume</i>, <i>beh</i>)</code> [SAL]<br>
2115
2116 <code>(loud <i>volume</i> <i>beh</i>)</code> [LISP]</dt>
2117 <dd>Evaluates <i>beh</i> with <code>*loud*</code>
2118 incremented by <i>volume</i>. (Recall that <code>*loud*</code> is in decibels, so increment is the proper operation.)<br><br>
2119 <dt><code>loud-abs(<a name="index614"></a><i>volume</i>, <i>beh</i>)</code> [SAL]<br>
2120
2121 <code>(loud-abs <i>volume</i> <i>beh</i>)</code> [LISP]</dt>
2122 <dd>Evaluates <i>beh</i> with <code>*loud*</code>
2123 set to <i>volume</i>.<br><br>
2124 <dt>
2125 <code>sound-srate-abs(<a name="index615"></a><i>srate</i>, <i>beh</i>)</code> [SAL]<br>
2126
2127 <code>(sound-srate-abs <i>srate</i> <i>beh</i>)</code> [LISP]</dt>
2128 <dd>Evaluate <i>beh</i> with <code>*sound-srate*<a name="index616"></a></code> set to sample rate <i>srate</i>. <b><i>Note:</i></b> there is no &ldquo;relative&rdquo; version of this function. <br><br>
2129 <dt><code>stretch(<a name="index617"></a><i>factor</i>, <i>beh</i>)</code> [SAL]<br>
2130
2131 <code>(stretch <i>factor</i> <i>beh</i>)</code> [LISP]</dt>
2132 <dd>Evaluates <i>beh</i> with
2133 <code>*warp*</code> scaled by <i>factor</i>. The effect is to &ldquo;stretch&rdquo; the result
2134 of <i>beh</i> (under the current environment) by <i>factor</i>. See Chapter
2135 <a href = "part5.html#38">Continuous Transformations and Time Warps</a> for more information. Use <code>get-duration(<i>dur</i>)</code> to
2136 get the nominal actual duration of a behavior that locally has a duration
2137 of <i>dur</i>. Here, &ldquo;nominal&rdquo; means what would be expected if the behavior
2138 obeys the shift, stretch, and warp components of the environment. (Any
2139 behavior is free to deviate from the nominal timing. For example, a percussion
2140 sound might have a fixed duration independent of the stretch factor.) Also,
2141 &ldquo;actual&rdquo; means global or absolute time, and &ldquo;locally&rdquo; means within the
2142 environment where <code>get-duration</code> is called. <code>get-duration</code> works
2143 by mapping the current time (local time 0) using <code>local-to-global</code> to
2144 obtain an actual start time, and mapping <i>dur</i> to obtain an actual end time.
2145 The difference is returned.<br><br>
2146 <dt><code>stretch-abs(<a name="index618"></a><i>factor</i>, <i>beh</i>)</code> [SAL]<br>
2147
2148 <code>(stretch-abs <i>factor</i> <i>beh</i>)</code> [LISP]</dt>
2149 <dd>Evaluates <i>beh</i> with <code>*warp*</code> set to a linear time transformation where each unit of logical time maps to <i>factor</i> units of real time. The effect is to stretch the nominal behavior of <i>beh</i> (under the default global environment) by <i>factor</i>. See Chapter <a href = "part5.html#38">Continuous Transformations and Time Warps</a> for more information.<br><br>
2150 <dt><code>sustain(<a name="index619"></a><a name="index620"></a><a name="index621"></a><a name="index622"></a><i>factor</i>, <i>beh</i>)</code> [SAL]<br>
2151
2152 <code>(sustain <i>factor</i> <i>beh</i>)</code> [LISP]</dt>
2153 <dd>Evaluates <i>beh</i> with <code>*sustain*</code> scaled by <i>factor</i>. The effect is to &ldquo;stretch&rdquo; the result of <i>beh</i> (under the current environment) by <i>factor</i>; however, the logical stop times are not stretched. Therefore, the overall duration of a sequence is not changed, and sounds will tend to overlap if <code>*sustain*</code> is greater than one (legato) and be separated by silence if <code>*sustain*</code> is less than one.<br><br>
2154 <dt><code>sustain-abs(<a name="index623"></a><i>factor</i>, <i>beh</i>)</code> [SAL]<br>
2155
2156 <code>(sustain-abs <i>factor</i> <i>beh</i>)</code> [LISP]</dt>
2157 <dd>Evaluates <i>beh</i> with <code>*sustain*</code> set to <i>factor</i>. (See <code>sustain</code>, above.)<br><br>
2158 <dt><code>transpose(<a name="index624"></a><i>amount</i>, <i>beh</i>)</code> [SAL]<br>
2159
2160 <code>(transpose <i>amount</i> <i>beh</i>)</code> [LISP]</dt>
2161 <dd>Evaluates <i>beh</i> with
2162 <code>*transpose*</code> shifted by <i>amount</i>. The effect is relative transposition by <i>amount</i> semitones.<br><br>
2163 <dt><code>transpose-abs(<a name="index625"></a><i>amount</i>, <i>beh</i>)</code> [SAL]<br>
2164
2165 <code>(transpose-abs <i>amount</i> <i>beh</i>)</code> [LISP]</dt>
2166 <dd>Evaluates <i>beh</i> with
2167 <code>*transpose*</code> set to <i>amount</i>. The effect is the transposition of the nominal pitches in <i>beh</i> (under the default global environment) by <i>amount</i>.<br><br>
2168 <dt><code>warp(<a name="index626"></a><i>fn</i>, <i>beh</i>)</code> [SAL]<br>
2169
2170 <code>(warp <i>fn</i> <i>beh</i>)</code> [LISP]</dt>
2171 <dd>Evaluates <i>beh</i> with <code>*warp*</code> modified by <i>fn</i>. The idea is that <i>beh</i> and <i>fn</i> are written in the same time system, and <i>fn</i> warps that time system to local time. The current environment already contains a mapping from local time to global (real) time. The value of <code>*warp*</code> in effect when <i>beh</i> is evaluated is the functional composition of the initial <code>*warp*</code> with <i>fn</i>.<br><br>
2172 <dt><code>warp-abs(<a name="index627"></a><i>fn</i>, <i>beh</i>)</code> [SAL]<br>
2173
2174 <code>(warp-abs <i>fn</i> <i>beh</i>)</code> [LISP]</dt>
2175 <dd>Evaluates <i>beh</i> with <code>*warp*</code> set to <i>fn</i>. In other words, the current <code>*warp*</code> is ignored and not composed with <i>fn</i> to form the new <code>*warp*</code>.
2176 </dd></dl><a name = "99"><h3>Combination and Time Structure</h3></a><a name="index628"></a><a name="index629"></a>
2177 <p>These behaviors combine component behaviors into structures, including
2178 sequences (melodies), simultaneous sounds (chords), and structures based
2179 on iteration. See also the <code>trigger</code> function, described in
2180 Section <a href = "part10.html#115">Starting and Stopping Sounds</a>, which uses a SOUND to trigger instances of a behavior.</p>
2181 <dl>
2182 <dt>
2183
2184 <code>seq(<a name="index630"></a><i>beh<sub>1</sub></i> [, <i>beh<sub>2</sub></i>, <span style="font-style:normal">...</span>])</code> [SAL]<br>
2185
2186 <code>(seq <i>beh<sub>1</sub></i> [<i>beh<sub>2</sub></i> <span style="font-style:normal">...</span>])</code> [LISP]</dt>
2187 <dd>Evaluates the first behavior
2188 <i>beh<sub>1</sub></i> according to the current time in the environment
2189 and each successive behavior at the
2190 <code>logical-stop</code> time of the previous one. The results are summed to form a
2191 sound whose <code>logical-stop</code> is
2192 the <code>logical-stop</code> of the last behavior in the sequence. Each behavior
2193 can result in a multichannel sound, in which case, the logical stop time is
2194 considered to be the maximum logical stop time of any channel. The number
2195 of channels in the result is the number of channels of the first behavior.
2196 If other behaviors return fewer channels, new channels are created containing
2197 constant zero signals until the required number of channels is obtained. If
2198 other behaviors return a simple sound rather than multichannel sounds, the
2199 sound is automatically assigned to the first channel of a multichannel sound
2200 that is then filled out with zero signals. If another behavior returns more
2201 channels than the first behavior, the error is reported and the computation
2202 is stopped. Sample rates are converted up or down to match the sample rate of the first sound in a sequence.
2203
2204 Nyquist programs should generally avoid storing sounds in global variables
2205 because that tends to cause sound samples to be retained in memory. A
2206 related problem can occur with <code>seq</code> and <code>seqrep</code>. With these
2207 functions, behaviors are not evaluated until needed, but what if the behaviors
2208 depend on local variables as parameters? Ordinarily, the variables would
2209 be long gone and garbage collected by the time the behavior is evaluated.
2210 So, <code>seq</code> and <code>seqrep</code> capture all local variables and their
2211 bindings (values) in <i>closures</i>. This solves the problem of retaining
2212 local variables and values until they are needed by the behaviors, but it
2213 has a problem similar to global variables in that <i>any sounds captured in
2214 the closure cannot be released until the last behavior in the sequence is
2215 evaluated.</i>
2216
2217 Here is an example:
2218
2219 <p></p>
2220 <pre>
2221 load "reverb"
2222
2223 function long-tone() return buzz(15, c4, lfo(5, 10))
2224
2225 function rev-with-tail(s, rt)
2226 return reverb(seq(s, s-rest(rt * 2)), rt)
2227
2228 play rev-with-tail(pluck(c4), 10)
2229 </pre>
2230
2231 <p> This SAL function uses <code>seq</code> to append
2232 <code>rt * 2</code> seconds of silence to sound <code>s</code> before passing it
2233 to <code>reverb</code> ensuring that the reverb tail will not be cut off
2234 immediately at the end of <code>s</code>. Behavior 2, <code>s-rest(rt * 2)</code>, is
2235 wrapped in a closure which also captures the binding of <code>s</code> to
2236 the input sound (returned from <code>long-tone()</code>) and that of <code>rt</code> to 10.
2237 If there were no closure, then
2238 when <code>rev-with-tail</code> returns a sound to <code>play</code>, the variable
2239 <code>s</code> would be freed by garbage collection, and the only remaining
2240 reference to <code>long-tone()</code> would be internal to the <code>reverb</code>
2241 sound computation. <code>reverb</code> disposes of samples as soon as they
2242 are computed and used, so the total memory requirements would be minimal.
2243 In this case, however, since <code>s</code> is captured in a closure,
2244 as <code>reverb</code> demands computation of samples from
2245 <code>long-tone()</code>, <code>reverb</code> releases its claim on the samples,
2246 but <code>s</code> does not, so all the samples are retained in memory
2247 until <code>s-rest(rt * 2)</code> is evaluated and the closure (and <code>s</code>)
2248 are freed.
2249
2250 For 10 seconds of sound (such as <code>long-tone(</code>)), this is not a big
2251 problem. In fact, if you use the default settings for autonorm, Nyquist
2252 will store about 20 seconds of sound in memory anyway just to do some
2253 look-ahead for normalization, but if <code>s</code> represents an hour-long
2254 stereo recording,
2255 or if there are many other sounds bound in local variables and captured
2256 in closures, the memory overhead can be too great. The solution is to
2257 override the default scopes and bindings to achieve the variable
2258 lifetimes we want. At any time, we can set a variable to <code>nil</code>,
2259 freeing the previous value to allow garbage collection. In LISP, we
2260 can write <code>(prog1 s (setf s nil))</code> to evaluate <code>s</code>, then
2261 free <code>s</code> by setting it to <code>nil</code>. The original value of <code>s</code>
2262 is returned from the <code>prog1</code> expression.
2263 In SAL, we can use the same trick, using
2264 <code>setf</code> rather than the typical SAL assignment operator
2265 (<code>=</code>).
2266
2267 To change the example to be memory efficient, we change the definition
2268 of <code>rev-with-tail</code> to:
2269 </p>
2270 <pre>
2271 function rev-with-tail(s, rt)
2272 return reverb(seq(prog1(s, setf(s, nil)), s-rest(rt * 2)), rt)
2273 </pre>
2274
2275 <p>
2276 Note in this example that the variable <code>s</code> loses its reference to the
2277 <code>long-tone()</code> sound right after it is evaluated by <code>prog1</code>,
2278 so now <code>reverb</code> has the only reference to this sound, and it can
2279 free samples from <code>long-tone()</code> as they are
2280 consumed. (In case you are wondering, the actual mechanism is that when
2281 <code>reverb</code> frees samples, their reference count goes to zero since no
2282 other reference exists to the possibly shared list of samples. There is
2283 no other reference because the reference previously bound to <code>s</code>
2284 is released by the garbage collector.)
2285
2286 It should be noted that the variable <code>rt</code> is retained in the
2287 closure and remains accessible there, so when <code>s</code>
2288 terminates, <code>s-rest(rt</code>)
2289 will evaluate as expected, using the value that <code>rt</code> acquired way
2290 back when <code>rev-with-tail</code> was called. This illustrates why
2291 the local variables must be saved in closures at the time <code>seq</code> is called.
2292 </p>
2293 <dt><code>seqrep(<a name="index631"></a><i>var</i>, <i>limit</i>, <i>beh</i>)</code> [SAL]<br>
2294
2295 <code>(seqrep (<i>var</i> <i>limit</i>) <i>beh</i>)</code> [LISP]</dt>
2296 <dd>Iteratively
2297 evaluates <i>beh</i> with the atom
2298 <i>var</i> set with values from 0 to <i>limit</i>-1, inclusive. These sounds
2299 are placed sequentially in time as if by <code>seq</code>. The symbol <i>var</i> is
2300 a <i>read-only</i> local variable to <i>beh</i>. Assignments are not restricted
2301 or detected, but may cause a run-time error or crash. In LISP, the syntax is
2302 <code>(seqrep (<i>var</i> <i>limit</i>) <i>beh</i>)</code>.<br><br>
2303 <dt>
2304
2305 <code>sim(<a name="index632"></a>[<i>beh<sub>1</sub></i>, <i>beh<sub>2</sub></i>, <span style="font-style:normal">...</span>])</code> [SAL]<br>
2306
2307 <code>(sim [<i>beh<sub>1</sub></i> <i>beh<sub>2</sub></i> <span style="font-style:normal">...</span>])</code> [LISP]</dt>
2308 <dd>Returns
2309 a sound which is the sum of the given behaviors evaluated with the current
2310 value of <code>*warp*</code>. If behaviors return multiple channel sounds,
2311 the corresponding channels are added. If the number of channels does
2312 not match, the result has as many channels as the argument with the
2313 most channels. For example, if a two-channel
2314 sound [L, R] is added to a four-channel sound [C1, C2, C3, C4], the
2315 result is [L + C1, R + C2, C3, C4]. Arguments to <code>sim</code> may also
2316 be numbers. If all arguments are numbers, <code>sim</code> is equivalent
2317 (although slower than) the LISP <code>+</code> function. If a number is added to
2318 a sound, <code>snd-offset</code> is used to add the number to each sample of
2319 the sound. The result of adding a number to two or more sounds with
2320 different durations is not defined. Use <code>const</code> to coerce a
2321 number to a sound of a specified duration. An important limitation of
2322 <code>sim</code> is that it cannot handle hundreds of behaviors due to a
2323 stack size limitation in XLISP. To compute hundreds of sounds
2324 (e.g. notes) at specified times, see <code>timed-seq</code>, below. See
2325 also <code>sum</code> below. Notce that <code>sim</code> is not transitive due to
2326 coercion rules: Using SAL syntax, <code>sim(a, sim(b, c))</code> may not produce the
2327 same result as <code>sim(sim(a, b), c)</code>.<br><br>
2328 <dt><code>simrep(<a name="index633"></a><i>var</i>, <i>limit</i>, <i>beh</i>)</code> [SAL]<br>
2329
2330 <code>(simrep <i>var</i> <i>limit</i> <i>beh</i>)</code> [LISP]</dt>
2331 <dd>Iteratively
2332 evaluates <i>beh</i> with the atom
2333 <i>var</i> set with values from 0 to <i>limit</i>-1, inclusive. These sounds
2334 are then placed simultaneously in time as if by <code>sim</code>.
2335 In LISP, the syntax is
2336 <code>(seqrep (<i>var</i> <i>limit</i>) <i>beh</i>)</code>.<br><br>
2337 <dt><code>set-logical-stop(<a name="index634"></a><i>beh</i>, <i>time</i>)</code> [SAL]<br>
2338
2339 <code>(set-logical-stop <i>beh</i> <i>time</i>)</code> [LISP]</dt>
2340 <dd>Returns a sound with <i>time</i> as
2341 the logical stop time.<br><br>
2342 <dt><code>sum(<a name="index635"></a><a name="index636"></a><i>a</i> [, <i>b</i>, <span style="font-style:normal">...</span>])</code>[SAL]<br>
2343
2344 <code>(sum <i>a</i> [<i>b</i> <span style="font-style:normal">...</span>])</code> [LISP]</dt>
2345 <dd>Returns
2346 the sum of <i>a</i>, <i>b</i>, ..., allowing mixed addition of sounds,
2347 multichannel sounds and numbers. Identical to <i>sim</i>. In SAL,
2348 use the infix &ldquo;+&rdquo; operator. See <code>sim</code> just above for more
2349 detail.<br><br>
2350 <dt><code>mult(<a name="index637"></a><a name="index638"></a><a name="index639"></a><i>a</i> [, <i>b</i>, <span style="font-style:normal">...</span>])</code> [SAL]<br>
2351
2352 <code>(mult <i>a</i> [<i>b</i> <span style="font-style:normal">...</span>])</code> [LISP]</dt>
2353 <dd>Returns the product of <i>a</i>, <i>b</i>, ..., allowing mixed multiplication of sounds, multichannel sounds and numbers.<br><br>
2354 <dt><code>diff(<a name="index640"></a><a name="index641"></a><i>a</i>, <i>b</i>)</code> [SAL]<br>
2355
2356 <code>(diff <i>a</i> <i>b</i>)</code> [LISP]</dt>
2357 <dd>Returns the difference between <i>a</i> and <i>b</i>. This function is defined as <code>(sum a (prod -1 b))</code>.<br><br>
2358 <dt>
2359 <code>timed-seq(<a name="index642"></a><a name="index643"></a><a name="index644"></a><i>score</i>)</code> [SAL]<br>
2360
2361 <code>(timed-seq <i>score</i>)</code> [LISP]</dt>
2362 <dd>Computes sounds from a note list or &ldquo;score.&rdquo; The <i>score</i>
2363 is of the form: <code>`((<i>time1</i> <i>stretch1</i> <i>beh1</i>) (<i>time2</i>
2364 <i>stretch2</i> <i>beh2</i>) <span style="font-style:normal">...</span>)</code>, where <i>timeN</i> is the starting time,
2365 <i>stretchN</i> is the stretch factor, and <i>behN</i> is the behavior. Note
2366 that <i>score</i> is normally a <i>quoted list</i>! The times must be in
2367 increasing order, and each <i>behN</i> is evaluated using lisp's <code>eval</code>,
2368 so the <i>behN</i> behaviors cannot refer to local parameters or local
2369 variables. The advantage of this form over <code>seq</code> is that the
2370 behaviors are evaluated one-at-a-time which can take much less stack
2371 space and overall memory. One special &ldquo;behavior&rdquo; expression is
2372 interpreted directly by <code>timed-seq</code>: <code>(SCORE-BEGIN-END)</code>
2373 is ignored, not evaluated as a function. Normally, this special
2374 behavior is placed at time 0 and has two parameters: the score
2375 start time and the score end time. These are used in Xmusic
2376 functions. If the behavior has a <code>:pitch</code> keyword parameter
2377 which is a list, the list represents a chord, and the expression is
2378 replaced by a set of behaviors, one for each note in the chord.
2379 It follows that if <code>:pitch</code> is <code>nil</code>, the behavior
2380 represents a rest and is ignored.
2381 </dd></dl><a name = "100"><h3>Sound File Input and Output</h3></a><a name="index645"></a><dl>
2382 <dt>
2383
2384 <code>play <a name="index646"></a><i>sound</i></code> [SAL]<br>
2385
2386 <code>(play <i>sound</i>)</code> [LISP]</dt>
2387 <dd>Play the sound
2388 through the DAC.
2389 In XLISP, it is a function. In SAL, you can invoke <code>play</code>
2390 as either a command or a function:
2391
2392 <p></p>
2393 <pre>
2394 play pluck(c4)
2395 ;; or call the function #play like this:
2396 exec #play(pluck(c4))
2397 </pre>
2398
2399 <p>
2400 The <code>play</code> command or function writes a file and plays it. The
2401 <i>sound</i> is any expression that evaluates to a SOUND. Typically, this
2402 should be function call, in which case the samples are computed
2403 incrementally and not retained in main memory (an advantage for large
2404 sounds). If the expression is a variable containing a SOUND (which may
2405 or may not be fully evaluated yet), the SOUND is fully evaluated and
2406 all samples are retained in the variable. The <code>play</code> function is
2407 defined in the file <code>system.lsp</code>. The variable
2408 <code>*default-sf-dir*</code><a name="index647"></a><a name="index648"></a><a name="index649"></a><a name="index650"></a><a name="index651"></a> names a directory into which to save a sound
2409 file, and <code>*default-sound-file*</code><a name="index652"></a><a name="index653"></a> names the file. If <code>*default-sound-file*</code> contains a slash (<code>/</code>), it is treated as an absolute path or path relative to the current directory, ignoring <code>*default-sf-dir*</code>. Be careful not to call <code>play</code> or <code>sound-play</code> within a
2410 function and then invoke that function from another <code>play</code>
2411 command. By default, Nyquist will try to
2412 normalize sounds using the method named by <code>*autonorm-type*</code>,
2413 which is <code>'lookahead</code> by default. The <i>lookahead</i> method
2414 precomputes and buffers <code>*autonorm-max-samples*</code> samples, finds
2415 the peak value, and normalizes accordingly. The <code>'previous</code>
2416 method bases the normalization of the current sound on the peak value
2417 of the (entire) previous sound. This might be good if you are working
2418 with long sounds that start rather softly. See Section
2419 <a href = "part6.html#46">Memory Space and Normalization</a> for more details.
2420
2421 If you want precise control over output levels, you should turn this feature off by typing (using SAL syntax):
2422 </p>
2423 <pre>
2424 autonorm-off()<a name="index654"></a>
2425 </pre>
2426
2427 <p>
2428 Reenable the automatic normalization feature by typing:
2429 </p>
2430 <pre>
2431 autonorm-on()<a name="index655"></a>
2432 </pre>
2433
2434 <p>
2435 Play normally produces real-time output. The default is to send audio data to the DAC as it is computed in addition to saving samples in a file. If computation is slower than real-time, output will be choppy, but since the samples end up in a file, you can type <code>(r)</code> to replay the stored sound. Real-time playback can be disabled by (using SAL syntax):
2436 </p>
2437 <pre>
2438 sound-off()<a name="index656"></a>
2439 </pre>
2440
2441 <p>
2442 and reenabled by:
2443 </p>
2444 <pre>
2445 sound-on()<a name="index657"></a>
2446 </pre>
2447
2448 <p>
2449 Disabling real-time playback has no effect on <code>(play-file)</code> or <code>(r)</code>.
2450 While sounds are playing, typing control-A<a name="index658"></a> to Nyquist (or clicking the Mark button in the NyquistIDE) will push the estimated
2451 elapsed<a name="index659"></a> audio time onto the head of the list
2452 stored in <code>*audio-markers*</code>.
2453 <a name="index660"></a><a name="index661"></a><a name="index662"></a>
2454 Because samples are computed in blocks and because there is latency
2455 between sample computation and sample playback, the elapsed time may not
2456 be too accurate, and the computed elapsed time may not advance after all
2457 samples have been computed but the sound is still playing.</p>
2458 <dt><code>play-file(<a name="index663"></a><i>filename</i>)</code> [SAL]<br>
2459
2460 <code>(play-file <i>filename</i>)</code> [LISP]</dt>
2461 <dd>Play the contents of a sound file named by <i>filename</i>. The <code>s-read</code> function is used to read the file, and unless
2462 <i>filename</i> specifies an absolute path or starts with &ldquo;.&rdquo;, it will be read from
2463 <code>*default-sf-dir*</code>.<br><br>
2464 <dt><code>autonorm-on(<a name="index664"></a>)</code> [SAL]<br>
2465
2466 <code>(autonorm-on)</code> [LISP]</dt>
2467 <dd>Enable automatic adjustment of a scale factor applied to sounds computed using the <code>play</code> command.<br><br>
2468 <dt><code>autonorm-off(<a name="index665"></a>)</code> [SAL]<br>
2469
2470 <code>(autonorm-off)</code> [LISP]</dt>
2471 <dd>Disable automatic adjustment of a scale factor applied to sounds computed using the <code>play</code> command.<br><br>
2472 <dt><code>sound-on(<a name="index666"></a>)</code> [SAL]<br>
2473
2474 <code>(sound-on)</code> [LISP]</dt>
2475 <dd>Enable real-time audio output when sound is computed by the the <code>play</code> command.<br><br>
2476 <dt><code>sound-off(<a name="index667"></a>)</code> [SAL]<br>
2477
2478 <code>(sound-off)</code> [LISP]</dt>
2479 <dd>Disable real-time audio output when sound is computed by the the <code>play</code> command.<br><br>
2480 <dt>
2481 <code>s-save(<a name="index668"></a><a name="index669"></a><a name="index670"></a><a name="index671"></a><i>expression</i>, [<i>maxlen</i>, <i>filename</i>, <i>progress</i>], format: <i>format</i>, mode: <i>mode</i>, bits: <i>bits</i>, swap: <i>flag</i>, play: <i>play</i>)</code> [SAL]<br>
2482
2483 <code>(s-save <i>expression</i> [<i>maxlen</i> <i>filename</i> <i>progress</i>] :format <i>format</i> :mode <i>mode</i> :bits <i>bits</i> :swap <i>flag</i> :play <i>play</i>)</code> [LISP]</dt>
2484 <dd>Evaluates the <i>expression</i>, which should result in a sound
2485 or an array of sounds, and writes the result to the given <i>filename</i>. (If
2486 omitted, <code>*default-sound-file*</code> is used instead.) A
2487 <code>FLONUM</code> is returned giving the maximum absolute value of all samples
2488 written. (This is useful for normalizing sounds and detecting sample
2489 overflow.) If <i>play</i> is not <code>NIL</code>, the sound will be output
2490 through the computer's audio output system. (<i>play:</i> [SAL]
2491 or <i>:play</i> [LISP] is not implemented on all systems; if it is implemented, and <i>filename</i> is <code>NIL</code>, then this will play the file without also writing a file.)
2492 The latency (length of audio buffering) used to play the sound is 0.3s by default, but see <code>snd-set-latency</code>.
2493 If
2494 a multichannel sound (array) is written, the channels are up-sampled to the
2495 highest rate in any channel so that all channels have the same sample rate.
2496 The maximum number of samples written per channel is optionally given by <i>maxlen</i>,
2497 which allows writing the initial part of a very long or infinite sound.
2498 Progress is indicated by printing the sample count after
2499 writing each 10 seconds of frames. If <i>progress</i> is specified and greater
2500 than 10,000, progress is printed at this specified frame count increment.
2501 A header is written according to <i>format</i>, samples are encoded according to
2502 <i>mode</i>, using <i>bits</i> bits/sample, and bytes are swapped if <i>flag</i> is not NIL. Defaults for these are
2503 <code>*default-sf-format*</code>, <code>*default-sf-mode*</code>, and
2504 <code>*default-sf-bits*</code>. The default for <i>flag</i> is NIL.
2505 The <i>bits</i> parameter may be 8, 16, or 32. The values for the <i>format</i> and <i>mode</i> options are described below:
2506 </dd></dl>
2507
2508 <b>Format</b>
2509 <dl>
2510 <dt>
2511 <code>snd-head-none</code></dt>
2512 <dd>The format is unknown and should be determined
2513 by reading the file.<br><br>
2514 <dt><code>snd-head-raw</code></dt>
2515 <dd>A raw format file has no header. <br><br>
2516 <dt><code>snd-head-AIFF</code></dt>
2517 <dd>AIFF format header.<br><br>
2518 <dt><code>snd-head-IRCAM</code></dt>
2519 <dd>IRCAM format header.<br><br>
2520 <dt><code>snd-head-NeXT</code></dt>
2521 <dd>1024-byte NeXT/SUN format header followed by IRCAM
2522 header ala CMIX. Note that the NeXT/SUN format has a header-length field,
2523 so it really is legal to have a large header, even though the normal minimal
2524 header is only 24 bytes. The additional space leaves room for maximum
2525 amplitudes, which can be used for normalizing floating-point soundfiles, and
2526 for other data. Nyquist follows the CMIX convention of placing an IRCAM
2527 format header immediately after the NeXT-style header.<br><br>
2528 <dt><code>snd-head-Wave</code></dt>
2529 <dd>Microsoft Wave format header.<br><br>
2530 <dt><code>snd-head-WaveX</code></dt>
2531 <dd>Microsoft Wave with WAVEFORMATEX format header.<br><br>
2532 <dt><code>snd-head-flac</code></dt>
2533 <dd>FLAC lossless compressed audio.<br><br>
2534 <dt><code>snd-head-ogg</code></dt>
2535 <dd>OGG-VORBIS compressed audio.<br><br>
2536 <dt><code>snd-head-*</code></dt>
2537 <dd>See sndfnint.lsp in the <code>nyquist/runtime</code> directory
2538 for more formats. The current list includes
2539 <code>paf</code>, <code>svx</code>, <code>nist</code>, <code>voc</code>, <code>w64</code>, <code>mat4</code>, <code>mat5</code>,
2540 <code>pvf</code>, <code>xi</code>, <code>htk</code>, <code>sds</code>, <code>avr</code>, <code>sd2</code>, and <code>caf</code>.
2541 </dd></dl><b>Mode</b>
2542 <dl>
2543 <dt>
2544 <code>snd-mode-adpcm</code></dt>
2545 <dd>ADPCM mode (not supported).<br><br>
2546 <dt><code>snd-mode-pcm</code></dt>
2547 <dd>signed binary PCM mode.<br><br>
2548 <dt><code>snd-mode-ulaw</code></dt>
2549 <dd>8-bit U-Law mode.<br><br>
2550 <dt><code>snd-mode-alaw</code></dt>
2551 <dd>8-bit A-Law mode (not supported).<br><br>
2552 <dt><code>snd-mode-float</code></dt>
2553 <dd>32-bit floating point mode.<br><br>
2554 <dt><code>snd-mode-upcm</code></dt>
2555 <dd>unsigned binary PCM mode.<br><br>
2556 <dt><code>snd-mode-*</code></dt>
2557 <dd>See sndfnint.lsp in the <code>nyquist/runtime</code> for more modes. The current list includes
2558 <code>double</code>, <code>gsm610</code>, <code>dwvw</code>, <code>dpcm</code>, and <code>msadpcm</code>.
2559 </dd></dl>
2560 <p>The defaults for format, mode, and bits are as follows:
2561 <dl>
2562 <dt>
2563 NeXT and Sun machines:</dt>
2564 <dd><code>snd-head-NeXT</code>, <code>snd-mode-pcm</code>,
2565 <code>16</code></p>
2566 <dt>SGI and Macintosh machines:</dt>
2567 <dd><code>snd-head-AIFF</code>, <code>snd-mode-pcm</code>, <code>16</code>
2568 </dd></dl><dl>
2569 <dt>
2570
2571 <code>s-read(<a name="index672"></a><a name="index673"></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>
2572
2573 <code>(s-read <i>filename</i> :time-offset <i>offset</i> :srate <i>sr</i>
2574 :dur <i>dur</i> :nchans <i>chans</i> :format <i>format</i> :mode <i>mode</i> :bits <i>n</i>
2575 :swap <i>flag</i>)</code> [LISP]</dt>
2576 <dd>Reads a sound from
2577 <i>filename</i>. The global <code>*default-sf-dir*</code> applies. If a header is
2578 detected, the header is used to determine the format
2579 of the file, and header information overrides format information provided by
2580 keywords (except for <code>time-offset:</code> and <code>dur:</code>).
2581
2582 <p></p>
2583 <pre>
2584 s-read("mysound.snd", srate: 44100)
2585 </pre>
2586
2587 <p>
2588 specifies a sample rate of 44100 hz, but if the file has a header specifying 22050 hz, the resulting sample rate will be 22050. The parameters are:
2589 <ul>
2590 <li>
2591 <i>offset</i> &ndash; the amount of time (in seconds) to skip from
2592 the beginning of the file. The default is 0.0.</li>
2593 <li><i>sr</i> &ndash; the sample rate of the samples in the file. Default is
2594 <code>*default-sf-srate*</code> <a name="index674"></a>, which is normally 44100.</li>
2595 <li><i>dur</i> &ndash; the maximum duration in seconds to read. Default is
2596 10000.</li>
2597 <li><i>chans</i> &ndash; the number of channels to read. It is assumed that
2598 samples from each channel are interleaved. Default is 1.</li>
2599 <li><i>format</i> &ndash; the header format. See <code>s-save</code> for details.
2600 Default is <code>*default-sf-format*</code>, although this parameter is currently
2601 ignored.</li>
2602 <li><i>mode</i> &ndash; the sample representation, e.g. PCM or float. See
2603 <code>s-save</code> for details. Default is <code>*default-sf-format*</code>.</li>
2604 <li><i>n</i> &ndash; the number of bits per sample. See <code>s-save</code> for
2605 details. Default is <code>*default-sf-bits*</code>.</li>
2606 <li><i>flag</i> &ndash; (T or NIL) swap byte order of each sample. Default is NIL.
2607 </li></ul>
2608 If there is an error, for example if <i>offset</i> is greater than the length
2609 of the file, then <code>NIL</code> is returned rather than a sound. Information
2610 about the sound is also returned by <code>s-read</code>
2611 through <code>*rslt*</code> <a href = "foot.html#foot4">(Footnote 4)</a> . The list assigned
2612 to <code>*rslt*</code> is of the form: (<i>format</i> <i>channels</i> <i>mode</i> <i>bits</i> <i>swap</i> <i>samplerate</i> <i>duration</i> <i>flags</i>), which are defined as follows:
2613 <ul>
2614 <li>
2615 <i>format</i> &ndash; the header format. See <code>s-save</code> for details. Access
2616 this element of <code>*rslt*</code> by calling <code>snd-read-format(*rslt*)</code>.</li>
2617 <li><i>channels</i> &ndash; the number of channels. Access
2618 this element of <code>*rslt*</code> by calling <code>snd-read-channels(*rslt*)</code>.</li>
2619 <li><i>mode</i> &ndash; the sample representation, e.g. PCM or float. Access
2620 this element of <code>*rslt*</code> by calling <code>snd-read-mode(*rslt*)</code>.
2621 See <code>s-save</code> for details.</li>
2622 <li><i>bits</i> &ndash; the number of bits per sample. Access
2623 this element of <code>*rslt*</code> by calling <code>snd-read-bits(*rslt*)</code>.</li>
2624 <li><i>swap</i> &ndash; 1 if byte-swapping is needed, 0 otherwise. Access
2625 this element of <code>*rslt*</code> by calling <code>snd-read-swap(*rslt*)</code>.</li>
2626 <li><i>samplerate</i> &ndash; the sample rate, expressed as a <code>FLONUM</code>. Access
2627 this element of <code>*rslt*</code> by calling <code>snd-read-srate(*rslt*)</code>.</li>
2628 <li><i>duration</i> &ndash; the duration of the sound, in seconds. Access
2629 this element of <code>*rslt*</code> by calling <code>snd-read-dur(*rslt*)</code>.</li>
2630 <li><i>flags</i> &ndash; The values
2631 for <i>format</i>, <i>channels</i>, <i>mode</i>, <i>bits</i>, <i>samplerate</i>,
2632 and <i>duration</i> are initially just the values passed in as
2633 parameters or default values to <code>s-read</code>. If a value is actually
2634 read from the sound file header, a flag is set. The flags
2635 are: <code>snd-head-type</code> (format), <code>snd-head-channels</code>, <code>snd-head-mode</code>, <code>snd-head-bits</code>, <code>snd-head-srate</code>, and <code>snd-head-dur</code>. For example,
2636 </p>
2637 <pre>
2638 (let ((flags (s-read-flags *rslt*)))
2639 (not (zerop (logand flags snd-head-srate))))
2640 </pre>
2641
2642 <p>
2643 tells whether the sample rate was specified in the file. See also <code>sf-info</code> below.
2644 Access this element of <code>*rslt*</code> by calling <code>snd-read-flags(*rslt*)</code>.
2645 </li></ul></p>
2646 <dt><code>s-add-to(<a name="index675"></a><a name="index676"></a><a name="index677"></a><i>expression</i>, <i>maxlen</i>, <i>filename</i> [, <i>offset</i>, <i>progress</i>])</code> [SAL]<br>
2647
2648 <code>(s-add-to <i>expression</i> <i>maxlen</i> <i>filename</i> [<i>offset</i> <i>progress</i>])</code> [LISP]</dt>
2649 <dd>Evaluates the <i>expression</i>, which should result in a sound
2650 or an array of sounds, and adds the result to the given <i>filename</i>.
2651 The global <code>*default-sf-dir*</code> applies. A <code>FLONUM</code> is returned,
2652 giving the maximum absolute value of all samples written. The
2653 sample rate(s) of <i>expression</i> must match those of the file.
2654 The maximum number of samples written per channel is given by <i>maxlen</i>,
2655 which allows writing the initial part of a very long or infinite sound.
2656 If <i>offset</i> is specified, the new sound is added to the file beginning at
2657 an <i>offset</i> from the beginning (in seconds).
2658 Progress is indicated by printing the sample count after
2659 writing each 10 seconds of frames. If <i>progress</i> is specified and greater
2660 than 10,000, progress is printed at this specified frame count increment.
2661 The file is extended if
2662 necessary to accommodate the new addition, but if <i>offset</i>
2663 falls outside of the original file, the file is not modified. (If necessary,
2664 use <code>s-add-to</code> to extend the file with zeros.)
2665 The file must be a recognized
2666 sound file with a header (not a raw sound file).<br><br>
2667 <dt><code>s-overwrite(<a name="index678"></a><a name="index679"></a><a name="index680"></a><i>expression</i>, <i>maxlen</i>, <i>filename</i> [, <i>offset</i>, <i>progress</i>])</code> [SAL]<br>
2668
2669 <code>(s-overwrite <i>expression</i> <i>maxlen</i> <i>filename</i> [<i>offset</i> <i>progress</i>])</code> [LISP]</dt>
2670 <dd>Evaluates
2671 the <i>expression</i>, which should result in a sound
2672 or an array of sounds, and replaces samples in the given <i>filename</i>.
2673 The global <code>*default-sf-dir*</code> applies.
2674 A <code>FLONUM</code> is returned, giving the maximum absolute value of all
2675 samples written. The
2676 sample rate(s) of <i>expression</i> must match those of the file.
2677 The maximum number of samples written per channel is given by <i>maxlen</i>,
2678 which allows writing the initial part of a very long or infinite sound.
2679 If <i>offset</i> is specified, the new sound is written to the file beginning at
2680 an <i>offset</i> from the beginning (in seconds). The file is extended if
2681 necessary to accommodate the new insert, but if <i>offset</i> falls outside of
2682 the original file, the file is not modified. (If necessary, use
2683 <code>s-add-to</code> to extend the file with zeros.)
2684 Progress is indicated by printing the sample count after
2685 writing each 10 seconds of frames. If <i>progress</i> is specified and greater
2686 than 10,000, progress is printed at this specified frame count increment.
2687 The file must be a recognized
2688 sound file with a header (not a raw sound file).<br><br>
2689 <dt><code>sf-info(<a name="index681"></a><a name="index682"></a><i>filename</i>)</code> [SAL]<br>
2690
2691 <code>(sf-info <i>filename</i>)</code> [LISP]</dt>
2692 <dd>Prints information about a sound file. The parameter <i>filename</i> is a string. The file is assumed to be in *default-sf-dir* (see <code>soundfilename</code> below) unless the filename begins with &ldquo;.&rdquo; or &ldquo;/&rdquo;. The source for this function is in the <code>runtime</code> and provides an example of how to determine sound file parameters. <br><br>
2693 <dt><code>soundfilename(<a name="index683"></a><i>name</i>)</code> [SAL]<br>
2694
2695 <code>(soundfilename <i>name</i>)</code> [LISP]</dt>
2696 <dd>Converts a string <i>name</i> to a soundfile name. If <i>name</i> begins with &ldquo;.&rdquo; or &ldquo;/&rdquo;, the name is returned without alteration. Otherwise, a path taken from <code>*default-sf-dir*</code> is prepended to <i>name</i>. The <code>s-plot</code>, <code>s-read</code>, and <code>s-save</code> functions all use <code>soundfilename</code> to translate filenames.<br><br>
2697 <dt>
2698 <code>s-plot(<a name="index684"></a><a name="index685"></a><i>sound</i>
2699 [, <i>dur</i>, <i>n</i>])</code> [SAL]<br>
2700
2701 <code>(s-plot <i>sound</i>
2702 [<i>dur</i> <i>n</i>])</code> [LISP]</dt>
2703 <dd>Plots sound in a window. This function was designed to run a <code>plot</code> program on a Unix workstation, but now is
2704 primarily used with <code>NyquistIDE</code>, which has self-contained plotting. Normally,
2705 time/value pairs in ascii are written to <code>points.dat</code> and system-dependent code
2706 (or the <code>NyquistIDE</code> program) takes it from there. If the <i>sound</i> is
2707 longer than the optional <i>dur</i> (default is 2 seconds), only the
2708 first <i>dur</i> seconds are plotted.
2709 If there are more than <i>n</i> samples to be plotted, the signal is interpolated
2710 to have <i>n</i> samples before plotting.
2711 The data file used is <code>*default-plot-file*</code>:<br><br>
2712 <dt><code>*default-plot-file*</code><a name="index686"></a></dt>
2713 <dd>The file containing the data points, defaults to "points.dat".<br><br>
2714 <dt><code>spec-plot(<a name="index687"></a><a name="index688"></a><a name="index689"></a><a name="index690"></a><i>sound</i> [, offset: <i>offset</i>, dur: <i>dur</i>, res: <i>res</i>, bw: <i>bw</i>, db: <i>db</i>])</code> [SAL]<br>
2715
2716 <code>(spec-plot <i>sound</i> [:offset <i>offset</i> :dur <i>dur</i> :res <i>res</i> :bw <i>bw</i> :db <i>db</i>])</code> [LISP]</dt>
2717 <dd>Computes
2718 and plots the short-time magnitude spectrum of sound (a SOUND or STRING).
2719 If sound is a filename (a STRING), a sound is read from the file.
2720 The bandwidth of each bin
2721 is given by the <i>res</i>
2722 (resolution) keyword parameter, which defaults to <code>*spec-plot-res*. Since one
2723 is often interested in lower frequencies, the <i>bw</i> (bandwidth</code> keyword parameter
2724 limits the range of bins which are plotted, and defaults to <code>*spec-plot-bw*</code>.
2725 The output can be presented on a dB scale by setting the <i>db</i> keyword parameter to
2726 <code>t</code> (true). The default is to use a linear scale.
2727 The <i>offset</i> (in seconds) skips initial samples before taking a frame of
2728 samples from <i>sound</i>. The <i>dur</i> keyword parameter (in seconds) limits the number of samples
2729 taken from sound. If <i>dur</i> is shorter than the FFT window size, the sound is zero-padded.
2730 If <i>dur</i> is longer than the FFT window size, the extra samples are ignored.
2731 The magnitude spectrum is sent to <code>s-plot</code> as a signal.
2732 The sample rate of the signal is set so that the plot labels on the horizontal axis
2733 represent Hz (not bin numbers.) To align bins with grid lines, one normally specifies
2734 <i>res</i> values in round numbers, e.g. 10 or 20. To achieve an arbitrary bin size,
2735 <code>spec-plot</code> resamples <i>sound</i> to a carefully computed sample rate that, after
2736 a power-of-2-sized FFT, yields the desired bin size.<br><br>
2737 <dt><code>spec-print(<a name="index691"></a><a name="index692"></a><a name="index693"></a><a name="index694"></a><i>file</i> <i>sound</i> [, offset: <i>offset</i>, dur: <i>dur</i>, res: <i>res</i>, bw: <i>bw</i>, threshold: <i>threshold</i>])</code> [SAL]<br>
2738
2739 <code>(spec-print <i>file</i> <i>sound</i> [:offset <i>offset</i> :dur <i>dur</i> :res <i>res</i> :bw <i>bw</i> :threshold <i>threshold</i>])</code> [LISP]</dt>
2740 <dd>Computes
2741 and prints an ASCII plot of the short-time magnitude spectrum of sound using <code>sa-print</code>
2742 (see <a href = "part11.html#122">Spectral Processing</a>).
2743 The <i>file</i> can be <code>T</code> to print to the console or a file open for writing. Other parameters
2744 are as in <code>spec-plot</code> (see above) except for <i>threshold</i>, which is passed to <code>sa-print</code>.
2745 Note that <i>bw</i> is passed to <code>sa-print</code> as <i>cutoff</i>. The global
2746 variables <code>*spec-plot-res*</code> and <code>*spec-plot-bw*</code> apply to <code>spec-print</code> as well
2747 as <code>spec-plot</code>. Important: The printed and plotted magnitudes are <i>normalized</i> to a peak
2748 value of 1 (see <code>sa-normalize</code>).<br><br>
2749 <dt><code>*spec-plot-res*</code><a name="index695"></a></dt>
2750 <dd>The default bin resolution
2751 (separation in Hz between adjacent bins) for <code>spec-plot</code>. Defaults to 20 Hz. You
2752 can override this by using a keyword parameter when you call <code>spec-plot</code> or <code>spec-print</code>,
2753 or for
2754 convenience, you can change this variable which will affect all future calls to
2755 <code>spec-plot</code> where the keyword parameter is omitted.<br><br>
2756 <dt><code>*spec-plot-bw*</code><a name="index696"></a></dt>
2757 <dd>The default highest frequency to
2758 include in <code>spec-plot</code>. Defaults to 8000 Hz. You
2759 can override this by using a keyword parameter when you call <code>spec-plot</code> or <code>spec-print</code>, or for
2760 convenience, you can change this variable which will affect all future calls to
2761 <code>spec-plot</code> where the keyword parameter is omitted.<br><br>
2762 <dt><code>*spec-plot-db*</code><a name="index697"></a></dt>
2763 <dd>The default output from
2764 <code>spec-plot</code> displays magnitude on a linear scale, but there is an option to
2765 display on a dB scale. You can change the default behavior by setting this variable to
2766 <code>t</code> (true), or you can override the default in any call to
2767 <code>spec-plot</code> using a keyword parameter.<br><br>
2768 <dt><code>s-print-tree(<a name="index698"></a><a name="index699"></a><i>sound</i>)</code> [SAL]<br>
2769
2770 <code>(s-print-tree <i>sound</i>)</code> [LISP]</dt>
2771 <dd>Prints an ascii
2772 representation of the internal data structures representing a sound. This
2773 is useful for debugging<a name="index700"></a> Nyquist. Identical
2774 to <code>snd-print-tree</code>.
2775 </dd></dl><a name = "101"><h3>Low-level Functions</h3></a>
2776 <p>Nyquist includes many low-level functions that are used to implement the functions and behaviors described in previous sections. For completeness, these functions are described here. Remember that
2777 these are low-level functions that are not intended for normal use. Unless
2778 you are trying to understand the inner workings of Nyquist, you can skip this section.</p>
2779 <a name = "102"><h4>Creating Sounds</h4></a>
2780 <p>The basic operations that create sounds are described here.
2781 <dl>
2782 <dt>
2783 <code>snd-const(<a name="index701"></a><i>value</i>, <i>t0</i>, <i>srate</i>,
2784 <i>duration</i>)</code> [SAL]<br>
2785
2786 <code>(snd-const <i>value</i> <i>t0</i> <i>srate</i> <i>duration</i>)</code> [LISP]</dt>
2787 <dd>Returns a sound with constant <i>value</i>, starting at <i>t0</i>
2788 with the given <i>duration</i>, at the sample rate <i>srate</i>. You might want
2789 to use <code>pwl</code> (see Section <a href = "#92">Piece-wise Approximations</a>) instead.</p>
2790 <dt><code>snd-read(<a name="index702"></a><i>filename</i>, <i>offset</i>, <i>t0</i>, <i>format</i>,
2791 <i>channels</i>, <i>mode</i>, <i>bits</i>, <i>swap</i>, <i>sr</i>,
2792 <i>dur</i>)</code> [SAL]<br>
2793
2794 <code>(snd-read <i>filename</i> <i>offset</i> <i>t0</i> <i>format</i> <i>channels</i> <i>mode</i> <i>bits</i> <i>swap</i> <i>sr</i> <i>dur</i>)</code> [LISP]</dt>
2795 <dd>Loads a sound from a file with name <i>filename</i>. Files are
2796 assumed to consist of a header followed by frames consisting of one sample
2797 from each channel. The <i>format</i> specifies the type of header, but this
2798 information is currently ignored. Nyquist looks for a number of header
2799 formats and automatically figures out which format to read. If a header can
2800 be identified, the header is first read from the file. Then, the file
2801 pointer is advanced by the indicated
2802 <i>offset</i> (in seconds). If there is an unrecognized header, Nyquist will
2803 assume the file has no header. If the header size is a multiple of the
2804 frame size (bytes/sample * number-of-channels), you can use <i>offset</i> to
2805 skip over the header. To skip N bytes, use an <i>offset</i> of:
2806
2807 <p></p>
2808 <pre>
2809 (/ (float N) <i>sr</i> (/ <i>bits</i> 8) <i>channels</i>)
2810 </pre>
2811
2812 <p>
2813 If the header is not a multiple of the frame size, either write a header or
2814 contact the author ([email protected]) for assistance. Nyquist will
2815 round <i>offset</i> to the nearest sample. The resulting sound will start at
2816 time <i>t0</i>. If a header is found, the file will be interpreted according
2817 to the header information. If no header was found, <i>channels</i> tells how
2818 many channels there are, the samples are encoded according to <i>mode</i>, the
2819 sample length is <i>bits</i>, and <i>sr</i> is the sample rate. The <i>swap</i> flag is 0 or 1, where 1 means to swap sample bytes. The duration to
2820 be read (in seconds) is given by <i>dur</i>. If <i>dur</i> is longer than the
2821 data in the file, then a shorter duration will be returned. If the file
2822 contains one channel, a sound is returned. If the file contains 2 or more
2823 channels, an array of sounds is returned. <b><i>Note:</i></b> you probably want to
2824 call <code>s-read</code> (see Section <a href = "#100">Sound File Input and Output</a>) instead of
2825 <code>snd-read</code>. Also, see Section <a href = "#100">Sound File Input and Output</a> for information on the
2826 <i>mode</i> and <i>format</i> parameters.</p>
2827 <dt><code>snd-save(<a name="index703"></a><i>expression</i>, <i>maxlen</i>,
2828 <i>filename</i>, <i>format</i>, <i>mode</i>, <i>bits</i>, <i>swap</i>, <i>play</i>, <i>progress</i>)</code> [SAL]<br>
2829
2830 <code>(snd-save <i>expression</i> <i>maxlen</i> <i>filename</i> <i>format</i> <i>mode</i> <i>bits</i> <i>swap</i> <i>play</i> <i>progress</i>)</code> [LISP]</dt>
2831 <dd>Evaluates
2832 the <i>expression</i>, which should result in a sound
2833 or an array of sounds, and writes the result to the given <i>filename</i>. If
2834 a multichannel sound (array) is written, the channels are up-sampled to the
2835 highest rate in any channel so that all channels have the same sample rate.
2836 The maximum number of samples written per channel is given by <i>maxlen</i>,
2837 which allows writing the initial part of a very long or infinite sound. A
2838 header is written according to <i>format</i>, samples are encoded according to
2839 <i>mode</i>, using <i>bits</i> bits/sample, and swapping bytes if <i>swap</i> is 1 (otherwise it should be 0).
2840 If <i>play</i> is not null, the audio is played in real time (to the extent possible) as it is computed.
2841 Progress is indicated by printing the sample count after
2842 writing each 10 seconds of frames. If <i>progress</i> is specified and greater
2843 than 10,000, progress is printed at this specified frame count increment.
2844 The peak value of the sound is returned. In addition,
2845 the symbol <code>*RSLT*</code> is bound to a list containing the sample rate,
2846 number of channels, and duration (in that order) of the saved sound.
2847 <b><i>Note:</i></b> you probably want to call
2848 <code>s-save</code> (see Section <a href = "#100">Sound File Input and Output</a>) instead. The <i>format</i> and
2849 <i>mode</i> parameters are described in Section <a href = "#100">Sound File Input and Output</a>.<br><br>
2850 <dt><code>snd-overwrite(<a name="index704"></a><i>expression</i>, <i>maxlen</i>, <i>filename</i>, <i>offset</i>, <i>progress</i>)</code> [SAL]<br>
2851
2852 <code>(snd-overwrite <i>expression</i> <i>maxlen</i> <i>filename</i> <i>offset</i> <i>progress</i>)</code> [LISP]</dt>
2853 <dd>Evaluates
2854 the <i>expression</i>, which should result in a sound
2855 or an array of sounds, and replaces samples in the given <i>filename</i>,
2856 writing the first frame at a time of <i>offset</i> seconds. The <i>offset</i> must
2857 be less than or equal to the duration of the existing file.
2858 Progress is indicated by printing the sample count after
2859 writing each 10 seconds of frames. If <i>progress</i> is specified and greater
2860 than 10,000, progress is printed at this specified frame count increment.
2861 The duration of the written samples may be greater than that of the file,
2862 in which case the file is extended as necessary. The
2863 sample rate(s) of <i>expression</i> and the number of channels
2864 must match those of the file.
2865 Up to a maximum of <i>maxlen</i>
2866 samples will be written per channel. The peak value of the sound is returned.
2867 In addition, the symbol <code>*RSLT*</code> is bound to a list containing the
2868 duration of the written sound (which may not be the duration of the sound
2869 file).
2870 Use <code>s-add-to</code> (in Section <a href = "#100">Sound File Input and Output</a> or
2871 <code>s-overwrite</code> (in Section <a href = "#100">Sound File Input and Output</a> instead of this function.<br><br>
2872 <dt><code>snd-coterm(<a name="index705"></a><a name="index706"></a><a name="index707"></a><i>s1</i>, <i>s2</i>)</code> [SAL]<br>
2873
2874 <code>(snd-coterm <i>s1</i> <i>s2</i>)</code> [LISP]</dt>
2875 <dd>Returns a copy of <i>s1</i>, except the start
2876 time is the maximum of the start times of <i>s1</i> and <i>s2</i>, and the
2877 termination time is the minimum of <i>s1</i> and <i>s2</i>. (After the termination
2878 time, the sound is zero as if <i>s1</i> is gated by <i>s2</i>.) Some rationale
2879 follows: In order to implement <code>s-add-to</code>, we need to read from the
2880 target sound file, add the sounds to a new sound, and overwrite the result
2881 back into the file. We only want to write as many samples into the file as
2882 there are samples in the new sound. However, if we are adding
2883 in samples read from
2884 the file, the result of a <code>snd-add</code> in Nyquist will have the maximum
2885 duration of either sound. Therefore, we may read to the end of the file.
2886 What we need is a way to truncate the read, but we cannot easily do that,
2887 because we do not know in advance how long the new sound will be. The
2888 solution is to use <code>snd-coterm</code>, which will allow us to truncate the
2889 sound that is read from the file (<i>s1</i>) according to the duration of the
2890 new sound (<i>s2</i>). When this truncated sound is added to the new sound,
2891 the result will have only the duration of the new sound, and this can be
2892 used to overwrite the file. This function is used in the implementation of
2893 <code>s-add-to</code>, which is defined in <code>runtime/fileio.lsp</code>.<br><br>
2894 <dt><code>(snd-from-array <span style="font-style:normal">...</span>)</code> [SAL]<br>
2895
2896 <code>(snd-from-array <span style="font-style:normal">...</span>)</code> [LISP]</dt>
2897 <dd>See <a href = "#86">Accessing and Creating Sound</a>.<br><br>
2898 <dt><code>snd-white(<a name="index708"></a><i>t0</i>, <i>sr</i>, <i>d</i>)</code> [SAL]<br>
2899
2900 <code>(snd-white <i>t0</i> <i>sr</i> <i>d</i>)</code> [LISP]</dt>
2901 <dd>Generate white noise, starting at
2902 <i>t0</i>, with sample rate <i>sr</i>, and duration <i>d</i>. You probably want to
2903 use <code>noise</code> (see Section <a href = "#97">More Behaviors</a>).<br><br>
2904 <dt><code>snd-zero(<a name="index709"></a><i>t0</i>, <i>srate</i>)</code> [SAL]<br>
2905
2906 <code>(snd-zero <i>t0</i> <i>srate</i>)</code> [LISP]</dt>
2907 <dd>Creates a sound that is
2908 zero everywhere, starts at <i>t0</i>, and has sample rate <i>srate</i>. The
2909 logical stop time is immediate, i.e. also at <i>t0</i>. You probably want
2910 to use <code>pwl</code> (see Section <a href = "#92">Piece-wise Approximations</a>) instead.
2911 </dd></dl><a name = "103"><h4>Signal Operations</h4></a>
2912 <p>This next set of functions take sounds as arguments, operate on them, and
2913 return a sound.</p>
2914 <dl>
2915 <dt>
2916 <code>snd-abs(<a name="index710"></a><a name="index711"></a><i>sound</i>)</code> [SAL]<br>
2917
2918 <code>(snd-abs <i>sound</i>)</code> [LISP]</dt>
2919 <dd>Computes a new
2920 sound where each sample is the absolute value of the corresponding sample in
2921 <i>sound</i>. You should probably use <code>s-abs</code> instead. (See Section <a href = "#97">More Behaviors</a>.)<br><br>
2922 <dt><code>snd-sqrt(<a name="index712"></a><a name="index713"></a><i>sound</i>)</code> [SAL]<br>
2923
2924 <code>(snd-sqrt <i>sound</i>)</code> [LISP]</dt>
2925 <dd>Computes a new
2926 sound where each sample is the square root of the corresponding sample in
2927 <i>sound</i>. If a sample is negative, it is taken to be zero to avoid raising a floating point error. You should probably use <code>s-sqrt</code> instead. (See Section <a href = "#97">More Behaviors</a>.)<br><br>
2928 <dt><code>snd-add(<a name="index714"></a><i>sound1</i>, <i>sound</i>)</code> [SAL]<br>
2929
2930 <code>(snd-add <i>sound1</i> <i>sound</i>)</code> [LISP]</dt>
2931 <dd>Adds two sounds. The
2932 resulting start time is the minimum of the two parameter start times, the
2933 logical stop time is the maximum of the two parameter stop times, and the
2934 sample rate is the maximum of the two parameter sample rates. Use
2935 <code>sim</code> or <code>sum</code> instead of <code>snd-add</code> (see Section <a href = "#99">Combination and Time Structure</a>).<br><br>
2936 <dt><code>snd-offset(<a name="index715"></a><a name="index716"></a><a name="index717"></a><i>sound</i>, <i>offset</i>)</code> [SAL]<br>
2937
2938 <code>(snd-offset <i>sound</i> <i>offset</i>)</code> [LISP]</dt>
2939 <dd>Add an offset to a sound. The
2940 resulting start time, logical stop time, stop time, and sample rate are
2941 those of <i>sound</i>. Use <code>sum</code> instead (see Section <a href = "#99">Combination and Time Structure</a>).<br><br>
2942 <dt><code>snd-avg(<a name="index718"></a><a name="index719"></a><a name="index720"></a><a name="index721"></a><i>sound</i>, <i>blocksize</i>, <i>stepsize</i>, <i>operation</i>)</code> [SAL]<br>
2943
2944 <code>(snd-avg <i>sound</i> <i>blocksize</i> <i>stepsize</i> <i>operation</i>)</code> [LISP]</dt>
2945 <dd>Use <code>s-avg</code> instead (see Section <a href = "#97">More Behaviors</a>). The <code>s-avg</code> function extends <code>snd-avg</code> to multichannel input sounds.<br><br>
2946 <dt><code>snd-clip(<a name="index722"></a><a name="index723"></a><i>sound</i>, <i>peak</i>)</code> [SAL]<br>
2947
2948 <code>(snd-clip <i>sound</i> <i>peak</i>)</code> [LISP]</dt>
2949 <dd>Hard limit <i>sound</i>
2950 to the given <i>peak</i>, a positive number. The samples of <i>sound</i> are constrained between an upper value
2951 of <i>peak</i> and a lower value of -<i>peak</i>. Use <code>clip</code> instead (see Section <a href = "#97">More Behaviors</a>).<br><br>
2952 <dt><code>snd-compose(<a name="index724"></a><a name="index725"></a><a name="index726"></a><i>f</i>, <i>g</i>)</code> [SAL]<br>
2953
2954 <code>(snd-compose <i>f</i> <i>g</i>)</code> [LISP]</dt>
2955 <dd>Compose two signals, i.e.
2956 compute <i>f</i>(<i>g</i>(<i>t</i>)), where <i>f</i> and <i>g</i> are sounds. This function
2957 is used primarily to implement time warping, but it can be used in other
2958 applications such as frequency modulation. For each sample <i>x</i> in <i>g</i>,
2959 <i>snd-compose</i> looks up the value of <i>f</i>(<i>x</i>) using linear
2960 interpolation. The resulting sample rate, start time, etc. are taken from
2961 <i>g</i>. The sound <i>f</i> is used in effect as a lookup table, but it is
2962 assumed that <i>g</i> is non-decreasing, so that <i>f</i> is accessed in time
2963 order. This allows samples of <i>f</i> to be computed and discarded
2964 incrementally. If in fact <i>g</i> decreases, the current sample of <i>g</i> is
2965 replaced by the previous one, forcing <i>g</i> into compliance with the
2966 non-decreasing restriction. See also <code>sref</code>, <code>shape</code>, and
2967 <code>snd-resample</code>.
2968
2969 For an extended example that uses <code>snd-compose</code> for variable pitch shifting,
2970 see <code>nyquist/demos/pitch_change.htm</code>.<a name="index727"></a><a name="index728"></a>
2971 <a name="index729"></a><a name="index730"></a><br><br>
2972 <dt>
2973 <code>snd-tapv(<a name="index731"></a><a name="index732"></a><a name="index733"></a><a name="index734"></a><a name="index735"></a><i>sound</i>, <i>offset</i>, <i>vardelay</i>, <i>maxdelay</i>)</code> [SAL]<br>
2974
2975 <code>(snd-tapv <i>sound</i> <i>offset</i> <i>vardelay</i> <i>maxdelay</i>)</code> [LISP]</dt>
2976 <dd>A
2977 variable delay: <i>sound</i> is delayed by the sum of <i>offset</i> (a <code>FIXNUM</code> or <code>FLONUM</code>)
2978 and <i>vardelay</i> (a <code>SOUND</code>). The specified delay is adjusted to lie in the range
2979 of zero to <i>maxdelay</i> seconds to yield the actual delay, and the delay is
2980 implemented using linear interpolation. This function was designed specifically
2981 for use in a chorus effect: the <i>offset</i> is set to half of <i>maxdelay</i>, and
2982 the <i>vardelay</i> input is a slow sinusoid. The maximum delay is limited to
2983 <i>maxdelay</i>, which determines the length of a fixed-sized buffer. The function
2984 <code>tapv</code> is equivalent and preferred (see Section <a href = "#93">Filter Behaviors</a>).<br><br>
2985 <dt><code>snd-tapf(<a name="index736"></a><a name="index737"></a><a name="index738"></a><i>sound</i>, <i>offset</i>, <i>vardelay</i>, <i>maxdelay</i>)</code> [SAL]<br>
2986
2987 <code>(snd-tapf <i>sound</i> <i>offset</i> <i>vardelay</i> <i>maxdelay</i>)</code> [LISP]</dt>
2988 <dd>A
2989 variable delay like <code>snd-tapv</code> except there is no linear interpolation. By
2990 eliminating interpolation, the output is an exact copy of the input with no filtering
2991 or distortion. On the other hand, delays jump by samples causing samples to double or
2992 skip even when the delay is changed smoothly.<br><br>
2993 <dt><code>snd-copy(<a name="index739"></a><i>sound</i>)</code> [SAL]<br>
2994
2995 <code>(snd-copy <i>sound</i>)</code> [LISP]</dt>
2996 <dd>Makes a copy of <i>sound</i>.
2997 Since operators always make (logical) copies of their sound parameters, this
2998 function should never be needed. This function is here for debugging<a name="index740"></a>.<br><br>
2999 <dt><code>snd-down(<a name="index741"></a><i>srate</i>, <i>sound</i>)</code> [SAL]<br>
3000
3001 <code>(snd-down <i>srate</i> <i>sound</i>)</code> [LISP]</dt>
3002 <dd>Linear interpolation
3003 of samples down to the given sample rate <i>srate</i>, which must be lower than
3004 the sample rate of <i>sound</i>. Do not call this function. Nyquist performs
3005 sample-rate conversion automatically as needed. If you want to force a
3006 conversion, call <code>force-srate</code> (see Section <a href = "#90">Sound Synthesis</a>).<br><br>
3007 <dt><code>snd-exp(<a name="index742"></a><i>sound</i>)</code> [SAL]<br>
3008
3009 <code>(snd-exp <i>sound</i>)</code> [LISP]</dt>
3010 <dd>Compute the exponential of each sample of <i>sound</i>. Use <code>s-exp</code> instead (see Section <a href = "#97">More Behaviors</a>).<br><br>
3011 <dt>
3012 <code>snd-follow(<a name="index743"></a><a name="index744"></a><a name="index745"></a><i>sound</i>, <i>floor</i>, <i>risetime</i>, <i>falltime</i>, <i>lookahead</i>)</code> [SAL]<br>
3013
3014 <code>(snd-follow <i>sound</i> <i>floor</i> <i>risetime</i> <i>falltime</i> <i>lookahead</i>)</code> [LISP]</dt>
3015 <dd>An envelope
3016 follower. The basic goal of this function is to generate a smooth signal
3017 that rides on the peaks of the input signal. The usual objective is to
3018 produce an amplitude envelope given a low-sample rate (control rate)
3019 signal representing local RMS measurements. The first argument is the
3020 input signal. The <i>floor</i> is the minimum output value. The <i>risetime</i> is the time (in seconds) it takes for the output to rise (exponentially) from <i>floor</i> to unity (1.0) and the <i>falltime</i> is the time it takes for the output to fall (exponentially) from unity to <i>floor</i>. The algorithm looks ahead for peaks and will begin to increase the output signal according to <i>risetime</i> in anticipation of a peak. The amount of anticipation (in samples) is given by <i>lookahead</i>. The algorithm is as follows: the output value is allowed to increase according to <i>risetime</i> or decrease according to <i>falltime</i>. If the next input sample is in this range, that sample is simply output as the next output sample. If the next input sample is too large, the algorithm goes back in time as far as necessary to compute an envelope that rises according to <i>risetime</i> to meet the new value. The algorithm will only work backward as far as <i>lookahead</i>. If that is not far enough, then there is a final forward pass computing a rising signal from the earliest output sample. In this case, the output signal will be at least momentarily less than the input signal and will continue to rise exponentially until it intersects the input signal. If the input signal falls faster than indicated by <i>falltime</i>, the output fall rate will be limited by <i>falltime</i>, and the fall in output will stop when the output reaches <i>floor</i>. This algorithm can make two passes througth the buffer on sharply rising inputs, so it is not particularly fast. With short buffers and low sample rates this should not matter. See <code>snd-avg</code> above for a function that can help to generate a low-sample-rate input for <code>snd-follow</code>. See <code>snd-chase</code> in Section <a href = "#104">Filters</a> for a related filter.<br><br>
3021 <dt><code>snd-gate(<a name="index746"></a><a name="index747"></a><a name="index748"></a><i>sound</i>, <i>lookahead</i>, <i>risetime</i>, <i>falltime</i>, <i>floor</i>, <i>threshold</i>)</code> [SAL]<br>
3022
3023 <code>(snd-gate <i>sound</i> <i>lookahead</i> <i>risetime</i> <i>falltime</i> <i>floor</i> <i>threshold</i>)</code> [LISP]</dt>
3024 <dd>This function generates an exponential
3025 rise and decay intended for noise gate implementation. The decay
3026 starts when the signal drops below threshold and stays there for
3027 longer than lookahead. Decay continues until the value reaches floor,
3028 at which point the decay stops and the output value is held
3029 constant. Either during the decay or after the floor is reached, if
3030 the signal goes above threshold, then the output value will rise to
3031 unity (1.0) at the point the signal crosses the threshold. Again,
3032 look-ahead is used, so the rise actually starts before the signal
3033 crosses the threshold. The rise is a constant-rate exponential and set
3034 so that a rise from <i>floor</i> to unity occurs in <i>risetime</i>.
3035 Similarly, the fall is a constant-rate exponential such that a fall
3036 from unity to <i>floor</i> takes <i>falltime</i>. The result is delayed by
3037 <i>lookahead</i>, so the output is not actually synchronized with the
3038 input. To compensate, you should drop the initial <i>lookahead</i> of
3039 samples. Thus, <code>snd-gate</code> is not recommended for direct use. Use
3040 <code>gate</code> instead (see Section <a href = "#87">Miscellaneous Functions</a>).<br><br>
3041 <dt><code>snd-inverse(<a name="index749"></a><a name="index750"></a><i>signal</i>, <i>start</i>, <i>srate</i>)</code> [SAL]<br>
3042
3043 <code>(snd-inverse <i>signal</i> <i>start</i> <i>srate</i>)</code> [LISP]</dt>
3044 <dd>Compute the function inverse of <i>signal</i>, that is, compute <i>g</i>(<i>t</i>) such that <i>signal</i>(<i>g</i>(<i>t</i>)) = <i>t</i>. This function assumes that <i>signal</i> is non-decreasing, it uses linear interpolation, the resulting sample rate is <i>srate</i>, and the result is shifted to have a starting time of <i>start</i>. If <i>signal</i> decreases, the true inverse may be undefined, so we define <code>snd-inverse</code> operationally as follows: for each output time point <i>t</i>, scan ahead in <i>signal</i> until the value of signal exceeds <i>t</i>. Interpolate to find an exact time point <i>x</i> from <i>signal</i> and output <i>x</i> at time <i>t</i>. This function is intended for internal system use in implementing time warps.<br><br>
3045 <dt><code>snd-log(<a name="index751"></a><i>sound</i>)</code> [SAL]<br>
3046
3047 <code>(snd-log <i>sound</i>)</code> [LISP]</dt>
3048 <dd>Compute the natural logorithm of each sample of <i>sound</i>. Use <code>s-log</code> instead (see Section <a href = "#97">More Behaviors</a>).<br><br>
3049 <dt>
3050 <code>peak(<a name="index752"></a><a name="index753"></a><i>expression</i>, <i>maxlen</i>)</code> [SAL]<br>
3051
3052 <code>(peak <i>expression</i> <i>maxlen</i>)</code> [LISP]</dt>
3053 <dd>Compute
3054 the maximum absolute value of the amplitude of a sound. The sound is
3055 created by evaluating <i>expression</i> (as in <code>s-save</code>). Only the
3056 first <i>maxlen</i> samples are evaluated. The <i>expression</i> is
3057 automatically quoted (<code>peak</code> is a macro), so do not quote this
3058 parameter. If <i>expression</i> is a variable, then the <i>global
3059 binding</i> of that variable will be used. Also, since the variable
3060 retains a reference to the sound, the sound will be evaluated and left
3061 in memory. See Section <a href = "part6.html#46">Memory Space and Normalization</a> on <a href = "part6.html#46">Memory Space and Normalization</a> for examples.<br><br>
3062 <dt>
3063 <code>snd-max(<a name="index754"></a><a name="index755"></a><i>expression</i>, <i>maxlen</i>)</code> [SAL]<br>
3064
3065 <code>(snd-max <i>expression</i> <i>maxlen</i>)</code> [LISP]</dt>
3066 <dd>Compute the maximum absolute value of the amplitude of a sound. The sound is created by evaluating <i>expression</i> (as in <code>snd-save</code>), which is therefore normally quoted by the caller. At most <i>maxlen</i> samples are computed. The result is the maximum of the absolute values of the samples. <b><i>Notes:</i></b> It is recommended to use <code>peak</code> (see above) instead. If you want to find the maximum of a sound bound to a local variable and it is acceptable to save the samples in memory, then this is probably the function to call. Otherwise, use <code>peak</code>.<br><br>
3067 <dt><code>snd-maxv(<a name="index756"></a><a name="index757"></a><i>sound1</i>, <i>sound2</i>)</code> [SAL]<br>
3068
3069 <code>(snd-maxv <i>sound1</i> <i>sound2</i>)</code> [LISP]</dt>
3070 <dd>Compute
3071 the maximum of <i>sound1</i> and <i>sound2</i> on a sample-by-sample
3072 basis. The resulting sound has its start time at the maximum of the
3073 input start times and a logical stop at the minimum logical stop of
3074 the inputs. The physical stop time is the minimum of the physical stop
3075 times of the two sounds. <i>Note that this violates the &ldquo;normal&rdquo;
3076 interpretation that sounds are zero outside their start and stop
3077 times. For example, even if</i> sound1 <i>extends beyond</i> sound2 <i>and
3078 is greater than zero, the result value in this extension will be zero
3079 because it will be after the physical stop time, whereas if we simply
3080 treated</i> sound2 <i>as zero in this region and took the maximum, we
3081 would get a non-zero result.</i> Use <code>s-max</code> instead (see Section
3082 <a href = "#97">More Behaviors</a>).<br><br>
3083 <dt><code>snd-normalize(<a name="index758"></a><i>sound</i>)</code> [SAL]<br>
3084
3085 <code>(snd-normalize <i>sound</i>)</code> [LISP]</dt>
3086 <dd>Internally, sounds
3087 are stored with a scale factor that applies to all samples of the sound.
3088 All operators that take sound arguments take this scale factor into account
3089 (although it is not always necessary to perform an actual multiply per
3090 sample), so you should never need to call this function. This function
3091 multiplies each sample of a sound by its scale factor, returning a sound
3092 that represents the same signal, but whose scale factor is 1.0. <br><br>
3093 <dt><code>snd-oneshot(<a name="index759"></a><a name="index760"></a><a name="index761"></a><i>sound</i>, <i>threshold</i>, <i>ontime</i>)</code> [SAL]<br>
3094
3095 <code>(snd-oneshot <i>sound</i> <i>threshold</i> <i>ontime</i>)</code> [LISP]</dt>
3096 <dd>Computes a new sound that is zero
3097 except where <i>sound</i> exceeds threshold. From these points, the result is
3098 1.0 until <i>sound</i> remains below <i>threshold</i> for <i>ontime</i> (in seconds).
3099 The result has the same sample rate, start time, logical stop time, and
3100 duration as <i>sound</i>.<br><br>
3101 <dt><code>snd-prod(<a name="index762"></a><a name="index763"></a><a name="index764"></a><i>sound1</i>, <i>sound2</i>)</code> [SAL]<br>
3102
3103 <code>(snd-prod <i>sound1</i> <i>sound2</i>)</code> [LISP]</dt>
3104 <dd>Computes the
3105 product of <i>sound1</i> and <i>sound2</i>. The resulting sound has its start
3106 time at the maximum of the input start times and a logical stop at the minimum
3107 logical stop of the inputs. Do not use this function. Use <code>mult</code> or
3108 <code>prod</code> instead (see Section <a href = "#90">Sound Synthesis</a>). Sample rate, start time, etc. are taken from <i>sound</i>.<br><br>
3109 <dt><code>snd-pwl(<a name="index765"></a><a name="index766"></a><i>t0</i>, <i>sr</i>,
3110 <i>lis</i>)</code> [SAL]<br>
3111
3112 <code>(snd-pwl <i>t0</i> <i>sr</i> <i>lis</i>)</code> [LISP]</dt>
3113 <dd>Computes a piece-wise linear function according to the breakpoints
3114 in <i>lis</i>. The starting time is <i>t0</i>, and the sample rate is <i>sr</i>.
3115 The breakpoints are passed in an XLISP list (of type <code>LVAL</code>) where the
3116 list alternates sample numbers (<code>FIXNUM</code>s, computed in samples
3117 from the beginning of the pwl function) and values (the value of the pwl
3118 function, given as a <code>FLONUM</code>). There is an implicit starting
3119 point of (0, 0). The list must contain an odd number of points, the omitted
3120 last
3121 value being implicitly zero (0). The list is assumed to be well-formed. Do
3122 not call this function. Use <code>pwl</code> instead (see Section <a href = "#92">Piece-wise Approximations</a>).<br><br>
3123 <dt><code>snd-quantize(<a name="index767"></a><i>sound</i>, <i>steps</i>)</code> [SAL]<br>
3124
3125 <code>(snd-quantize <i>sound</i> <i>steps</i>)</code> [LISP]</dt>
3126 <dd>Quantizes a sound. See Section
3127 <a href = "#97">More Behaviors</a> for details.<br><br>
3128 <dt><code>snd-recip(<a name="index768"></a><i>sound</i>)</code> [SAL]<br>
3129
3130 <code>(snd-recip <i>sound</i>)</code> [LISP]</dt>
3131 <dd>Compute the reciprocal of each sample of <i>sound</i>. Use <code>recip</code> instead (see Section <a href = "#97">More Behaviors</a>).<br><br>
3132 <dt><code>snd-resample(<a name="index769"></a><a name="index770"></a><i>f</i>,
3133 <i>rate</i>)</code> [SAL]<br>
3134
3135 <code>(snd-resample <i>f</i> <i>rate</i>)</code> [LISP]</dt>
3136 <dd>Resample sound <i>f</i> using high-quality interpolation, yielding
3137 a new sound with the specified <i>rate</i>. The result is scaled by 0.95 because often,
3138 in resampling, interpolated values exceed the original sample values, and this
3139 could lead to clipping.
3140 The resulting start time, etc. are taken from
3141 <i>f</i>. Use <code>resample</code> instead.<br><br>
3142 <dt><code>snd-resamplev(<a name="index771"></a><a name="index772"></a><a name="index773"></a><i>f</i>, <i>rate</i>, <i>g</i>)</code> [SAL]<br>
3143
3144 <code>(snd-resamplev <i>f</i> <i>rate</i> <i>g</i>)</code> [LISP]</dt>
3145 <dd>Compose two
3146 signals, i.e. compute <i>f</i>(<i>g</i>(<i>t</i>)), where <i>f</i> and <i>g</i> are
3147 sounds. The result has sample rate given by <i>rate</i>. At each time <i>t</i>
3148 (according to the <i>rate</i>), <i>g</i> is linearly interpolated to yield an
3149 increasing sequence of high-precision score-time values. <i>f</i> is then
3150 interpolated at each value to yield a result sample. If in fact <i>g</i>
3151 decreases, the current sample of <i>g</i> is replaced by the previous one,
3152 forcing <i>g</i> into compliance with the non-decreasing restriction.
3153 The result is scaled by 0.95 because often,
3154 in resampling, interpolated values exceed the original sample values, and this
3155 could lead to clipping. Note that
3156 if <i>g</i> has a high sample rate, this may introduce unwanted jitter into
3157 sample times. See <code>sound-warp</code> for a detailed discussion. See
3158 <code>snd-compose</code> for a fast, low-quality alternative to this function.
3159 Normally, you should use <code>sound-warp</code> instead of this function.<br><br>
3160 <dt><code>snd-scale(<a name="index774"></a><i>scale</i>, <i>sound</i>)</code> [SAL]<br>
3161
3162 <code>(snd-scale <i>scale</i> <i>sound</i>)</code> [LISP]</dt>
3163 <dd>Scales the amplitude of <i>sound</i> by the factor <i>scale</i>. Use <code>scale</code> instead (see Section
3164 <a href = "#90">Sound Synthesis</a>).<br><br>
3165 <dt><code>snd-shape(<a name="index775"></a><i>signal</i>, <i>table</i>, <i>origin</i>)</code> [SAL]<br>
3166
3167 <code>(snd-shape <i>signal</i> <i>table</i> <i>origin</i>)</code> [LISP]</dt>
3168 <dd>A waveshaping function. This is the primitive upon which <code>shape</code> is based. The <code>snd-shape</code> function is like <code>shape</code> except that <i>signal</i> and <i>table</i> must be (single-channel) sounds. Use <code>shape</code> instead (see Section <a href = "#93">Filter Behaviors</a>).<br><br>
3169 <dt><code>snd-up(<a name="index776"></a><i>srate</i>, <i>sound</i>)</code> [SAL]<br>
3170
3171 <code>(snd-up <i>srate</i> <i>sound</i>)</code> [LISP]</dt>
3172 <dd>Increases sample rate by linear
3173 interpolation. The <i>sound</i> is the signal to be up-sampled, and <i>srate</i>
3174 is the output sample rate. Do not call this function. Nyquist performs
3175 sample-rate conversion automatically as needed. If you want to force a
3176 conversion, call <code>force-srate</code> (see Section <a href = "#90">Sound Synthesis</a>).<br><br>
3177 <dt>
3178 <code>snd-xform(<a name="index777"></a><i>sound</i>, <i>sr</i>, <i>time</i>, <i>start</i>,
3179 <i>stop</i>, <i>scale</i>)</code> [SAL]<br>
3180
3181 <code>(snd-xform <i>sound</i> <i>sr</i> <i>time</i> <i>start</i> <i>stop</i> <i>scale</i>)</code> [LISP]</dt>
3182 <dd>Makes a copy of <i>sound</i> and then alters it in
3183 the following order: (1) the start time (<code>snd-t0</code>) of the sound is shifted to
3184 <i>time</i>, (2) the sound is stretched as a result of setting the sample rate
3185 to <i>sr</i> (the start time is unchanged by this), (3) the sound is clipped
3186 from <i>start</i> to <i>stop</i>, (4) if <i>start</i> is greater than <i>time</i>, the sound is shifted
3187 shifted by <i>time</i> - <i>start</i>, so that the start time is <i>time</i>, (5) the
3188 sound is scaled by <i>scale</i>. An empty (zero) sound at <i>time</i> will be
3189 returned if all samples are clipped. Normally, you should accomplish all
3190 this using transformations. A transformation applied to a sound has no
3191 effect, so use <code>cue</code> or <code>sound</code> to create a transformable sound (see Section
3192 <a href = "#89">Using Previously Created Sounds</a>).<br><br>
3193 <dt>
3194 <code>snd-yin(<a name="index778"></a><i>sound</i>, <i>minstep</i>, <i>maxstep</i>, <i>rate</i>)</code> [SAL]<br>
3195
3196 <code>(snd-yin <i>sound</i> <i>minstep</i> <i>maxstep</i> <i>rate</i>)</code> [LISP]</dt>
3197 <dd>Identical to
3198 <code>yin</code>. See Section <a href = "#97">More Behaviors</a>.
3199 </dd></dl><a name = "104"><h4>Filters</h4></a>
3200 <p>These are also &ldquo;Signal Operators,&rdquo; the subject of the previous section,
3201 but there are so many filter functions, they are
3202 documented in this special section.</p>
3203
3204 <p>Some filters allow time-varying filter parameters. In these functions,
3205 filter coefficients are calculated at the sample rate of the filter
3206 parameter, and coefficients are not interpolated.</p>
3207 <dl>
3208 <dt>
3209 <code>snd-alpass(<a name="index779"></a><i>sound</i>, <i>delay</i>, <i>feedback</i>)</code> [SAL]<br>
3210
3211 <code>(snd-alpass <i>sound</i> <i>delay</i> <i>feedback</i>)</code> [LISP]</dt>
3212 <dd>An all-pass filter. This produces a repeating echo effect without the resonances of <code>snd-delay</code>. The <i>feedback</i> should be less than one to avoid exponential amplitude blowup. Delay is rounded to the nearest sample. You should use <code>alpass</code> instead (see Section <a href = "#93">Filter Behaviors</a>).<br><br>
3213 <dt><code>snd-alpasscv(<a name="index780"></a><i>sound</i>, <i>delay</i>,
3214 <i>feedback</i>)</code> [SAL]<br>
3215
3216 <code>(snd-alpasscv <i>sound</i> <i>delay</i> <i>feedback</i>)</code> [LISP]</dt>
3217 <dd>An all-pass filter with variable <i>feedback</i>.
3218 This is just like <i>snd-alpass</i> except <i>feedback</i> is a sound.
3219 You should use <code>alpass</code> instead (see Section <a href = "#93">Filter Behaviors</a>).<br><br>
3220 <dt><code>snd-alpassvv(<a name="index781"></a><i>sound</i>, <i>delay</i>, <i>feedback</i>, <i>maxdelay</i>)</code> [SAL]<br>
3221
3222 <code>(snd-alpassvv <i>sound</i> <i>delay</i> <i>feedback</i> <i>maxdelay</i>)</code> [LISP]</dt>
3223 <dd>An all-pass filter with variable <i>feedback</i> and <i>delay</i>. This is just like <i>snd-alpass</i> except <i>feedback</i> and <i>delay</i> are sounds, and there is an additional <code>FLONUM</code> parameter, <i>maxdelay</i>, that gives an upper bound on the value of <i>delay</i>. <b><i>Note:</i></b> <i>delay</i> must remain between zero and <i>maxdelay</i>. If not, results are undefined, and Nyquist may crash. You should use <code>alpass</code> instead (see Section <a href = "#93">Filter Behaviors</a>).<br><br>
3224 <dt><code>snd-areson(<a name="index782"></a><i>sound</i>, <i>hz</i>, <i>bw</i>,
3225 <i>normalization</i>)</code> [SAL]<br>
3226
3227 <code>(snd-areson <i>sound</i> <i>hz</i> <i>bw</i> <i>normalization</i>)</code> [LISP]</dt>
3228 <dd>A notch filter modeled after the <code>areson</code>
3229 unit generator in Csound. The <code>snd-areson</code> filter is an exact
3230 complement of <code>snd-reson</code> such that if both are applied to the
3231 same signal with the same parameters, the sum of the results yeilds
3232 the original signal. Note that because of this complementary design,
3233 the power is not normalized as in <code>snd-reson</code>. See <code>snd-reson</code>
3234 for details on <i>normalization</i>. You should use <code>areson</code> instead (see
3235 Section <a href = "#93">Filter Behaviors</a>).<br><br>
3236 <dt><code>snd-aresoncv(<a name="index783"></a><i>sound</i>, <i>hz</i>, <i>bw</i>,
3237 <i>normalization</i>)</code> [SAL]<br>
3238
3239 <code>(snd-aresoncv <i>sound</i> <i>hz</i> <i>bw</i> <i>normalization</i>)</code> [LISP]</dt>
3240 <dd>This function is identical to <code>snd-areson</code> except
3241 the <i>bw</i> (bandwidth) parameter is a sound. Filter coefficients are
3242 updated at the sample rate of <i>bw</i>. The &ldquo;<code>cv</code>&rdquo; suffix stands for Constant,
3243 Variable, indicating that <i>hz</i> and <i>bw</i> are constant (a number) and
3244 variable (a sound), respectively. This naming convention is used throughout.
3245 You should use <code>areson</code> instead (see
3246 Section <a href = "#93">Filter Behaviors</a>).<br><br>
3247 <dt><code>snd-aresonvc(<a name="index784"></a><i>sound</i>, <i>hz</i>, <i>bw</i>,
3248 <i>normalization</i>)</code> [SAL]<br>
3249
3250 <code>(snd-aresonvc <i>sound</i> <i>hz</i> <i>bw</i> <i>normalization</i>)</code> [LISP]</dt>
3251 <dd>This function is identical to <code>snd-areson</code> except
3252 the <i>hz</i> (center frequency) parameter is a sound. Filter coefficients are
3253 updated at the sample rate of <i>hz</i>.
3254 You should use <code>areson</code> instead (see
3255 Section <a href = "#93">Filter Behaviors</a>).<br><br>
3256 <dt><code>snd-aresonvv(<a name="index785"></a><i>sound</i>, <i>hz</i>, <i>bw</i>,
3257 <i>normalization</i>)</code> [SAL]<br>
3258
3259 <code>(snd-aresonvv <i>sound</i> <i>hz</i> <i>bw</i> <i>normalization</i>)</code> [LISP]</dt>
3260 <dd>This function is identical to <code>snd-areson</code> except
3261 both <i>hz</i> (center frequency) and <i>bw</i> (bandwidth) are sounds. Filter
3262 coefficients are updated at the next sample of either <i>hz</i> or <i>bw</i>.
3263 You should use <code>areson</code> instead (see
3264 Section <a href = "#93">Filter Behaviors</a>).<br><br>
3265 <dt><code>snd-atone(<a name="index786"></a><i>sound</i>, <i>hz</i>)</code> [SAL]<br>
3266
3267 <code>(snd-atone <i>sound</i> <i>hz</i>)</code> [LISP]</dt>
3268 <dd>A high-pass filter
3269 modeled after the <code>atone</code> unit generator in Csound. The <code>snd-atone</code> filter is an exact
3270 complement of <code>snd-tone</code> such that if both are applied to the
3271 same signal with the same parameters, the sum of the results yeilds
3272 the original signal. You should use <code>hp</code> instead (see
3273 Section <a href = "#93">Filter Behaviors</a>).<br><br>
3274 <dt><code>snd-atonev(<a name="index787"></a><i>sound</i>, <i>hz</i>)</code> [SAL]<br>
3275
3276 <code>(snd-atonev <i>sound</i> <i>hz</i>)</code> [LISP]</dt>
3277 <dd>This is just like
3278 <code>snd-atone</code> except that the <i>hz</i> cutoff frequency is a sound. Filter
3279 coefficients are updated at the sample rate of <i>hz</i>. You should use
3280 <code>hp</code> instead (see Section <a href = "#93">Filter Behaviors</a>).<br><br>
3281 <dt><code>snd-biquad(<a name="index788"></a><i>sound</i>, <i>b0</i>, <i>b1</i>, <i>b2</i>, <i>a1</i>, <i>a2</i>, <i>z1init</i>, <i>z2init</i>)</code> [SAL]<br>
3282
3283 <code>(snd-biquad <i>sound</i> <i>b0</i> <i>b1</i> <i>b2</i> <i>a1</i> <i>a2</i> <i>z1init</i> <i>z2init</i>)</code> [LISP]</dt>
3284 <dd>A general second order IIR filter, where <i>a0</i> is assumed to be unity. For <i>a1</i> and <i>a2</i>, the sign convention is opposite to that of Matlab. All parameters except the input <i>sound</i> are of type <code>FLONUM</code>. You should probably use one of <code>lowpass2</code>, <code>highpass2</code>, <code>bandpass2</code>, <code>notch2</code>, <code>allpass2</code>, <code>eq-lowshelf</code>, <code>eq-highshelf</code>, <code>eq-band</code>, <code>lowpass4</code>, <code>lowpass6</code>, <code>lowpass8</code>, <code>highpass4</code>, <code>highpass6</code>, or <code>highpass8</code>, which are all based on <code>snd-biquad</code> and described in Section <a href = "#93">Filter Behaviors</a>. For completeness, you will also find <code>biquad</code> and <code>biquad-m</code> described in that section.<br><br>
3285 <dt>
3286 <code>snd-chase(<a name="index789"></a><i>sound</i>, <i>risetime</i>, <i>falltime</i>)</code> [SAL]<br>
3287
3288 <code>(snd-chase <i>sound</i> <i>risetime</i> <i>falltime</i>)</code> [LISP]</dt>
3289 <dd>A slew rate limiter. The output &ldquo;chases&rdquo; the input at rates determined by <i>risetime</i> and <i>falltime</i>. If the input changes too fast, the output will lag behind the input. This is a form of lowpass filter, but it was created to turn hard-switching square waves into smoother control signals that could be used for linear crossfades. If the input switches from 0 to 1, the output will linearly rise to 1 in <i>risetime</i> seconds. If the input switches from 1 to 0, the output will linearly fall to 0 in <i>falltime</i> seconds. The generated slope is constant; the transition is linear; this is not an exponential rise or fall. The <i>risetime</i> and <i>falltime</i> must be scalar constants; complain to the author if this is not adequate. The <code>snd-chase</code> function is safe for ordinary use. See <code>snd-follow</code> in Section <a href = "#103">Signal Operations</a> for a related function. <br><br>
3290 <dt><code>snd-congen(<a name="index790"></a><i>gate</i>, <i>risetime</i>, <i>falltime</i>)</code> [SAL]<br>
3291
3292 <code>(snd-congen <i>gate</i> <i>risetime</i> <i>falltime</i>)</code> [LISP]</dt>
3293 <dd>A simple &ldquo;contour generator&rdquo; based
3294 on analog synthesizers. The <i>gate</i> is a sound that normally steps from 0.0 to 1.0 at the start of an envelop and goes from
3295 1.0 back to 0.0 at the beginning of the release. At each sample, the output converges to the input exponentially. If <i>gate</i> is greater than the output, e.g. the attack, then the output converges half-way to the output in <i>risetime</i>. If the <i>gate</i> is less than the output, the half-time is <i>falltime</i>. The sample rate, starting time, logical-stop-time, and terminate time are taken from <i>gate</i>. You should use <code>congen</code> instead (see Section <a href = "#93">Filter Behaviors</a>.<br><br>
3296 <dt><code>snd-convolve(<a name="index791"></a><i>sound</i>, <i>response</i>)</code> [SAL]<br>
3297
3298 <code>(snd-convolve <i>sound</i> <i>response</i>)</code> [LISP]</dt>
3299 <dd>Convolves
3300 <i>sound</i> by <i>response</i> using a fast convolution algorithm. The <i>sound</i>
3301 can be any length, but the <i>response</i> is computed and stored in in memory.
3302 The required compuation time per sample and total space are proportional to
3303 the length of <i>response</i>. Use <code>convolve</code> instead (see Section
3304 <a href = "#93">Filter Behaviors</a>).<br><br>
3305 <dt><code>snd-delay(<a name="index792"></a><i>sound</i>, <i>delay</i>, <i>feedback</i>)</code> [SAL]<br>
3306
3307 <code>(snd-delay <i>sound</i> <i>delay</i> <i>feedback</i>)</code> [LISP]</dt>
3308 <dd>Feedback
3309 delay. The output, initially <i>sound</i>, is recursively delayed by <i>delay</i>, scaled by <i>feedback</i>, and added to itself, producing an repeating echo effect. The <i>feedback</i> should be less than one to avoid exponential amplitude blowup. Delay is rounded to the nearest sample. You should use <code>feedback-delay</code> instead (see Section <a href = "#93">Filter Behaviors</a>)<br><br>
3310 <dt><code>snd-delaycv(<a name="index793"></a><i>sound</i>, <i>delay</i>,
3311 <i>feedback</i>)</code> [SAL]<br>
3312
3313 <code>(snd-delaycv <i>sound</i> <i>delay</i> <i>feedback</i>)</code> [LISP]</dt>
3314 <dd>Feedback delay with variable <i>feedback</i>. This is just like
3315 <i>snd-delay</i> except <i>feedback</i> is a sound. You should use
3316 <code>feedback-delay</code> instead (see Section <a href = "#93">Filter Behaviors</a>).<br><br>
3317 <dt><code>snd-reson(<a name="index794"></a><i>sound</i>, <i>hz</i>, <i>bw</i>, <i>normalization</i>)</code> [SAL]<br>
3318
3319 <code>(snd-reson <i>sound</i> <i>hz</i> <i>bw</i> <i>normalization</i>)</code> [LISP]</dt>
3320 <dd>A
3321 second-order resonating (bandpass) filter with center frequency <i>hz</i> and
3322 bandwidth <i>bw</i>, modeled after the <code>reson</code> unit generator in Csound.
3323 The <i>normalization</i> parameter must be an integer and (like in Csound)
3324 specifies a scaling factor. A value of 1 specifies a peak amplitude
3325 response of 1.0; all frequencies other than <i>hz</i> are attenuated. A
3326 value of 2 specifies the overall RMS value of the amplitude response
3327 is 1.0; thus filtered white noise would retain the same power. A value of
3328 zero specifies no scaling. The result sample rate, start time, etc. are takend from <i>sound</i>.
3329 You should use <code>reson</code> instead (see Section
3330 <a href = "#93">Filter Behaviors</a>).<br><br>
3331 <dt><code>snd-resoncv(<a name="index795"></a><i>sound</i>, <i>hz</i>, <i>bw</i>,
3332 <i>normalization</i>)</code> [SAL]<br>
3333
3334 <code>(snd-resoncv <i>sound</i> <i>hz</i> <i>bw</i> <i>normalization</i>)</code> [LISP]</dt>
3335 <dd>This function is identical to <code>snd-reson</code> except
3336 <i>bw</i> (bandwidth) is a sound. Filter coefficients are updated at the
3337 sample rate of <i>bw</i>. You should use <code>reson</code> instead (see Section
3338 <a href = "#93">Filter Behaviors</a>).<br><br>
3339 <dt><code>snd-resonvc(<a name="index796"></a><i>sound</i>, <i>hz</i>, <i>bw</i>,
3340 <i>normalization</i>)</code> [SAL]<br>
3341
3342 <code>(snd-resonvc <i>sound</i> <i>hz</i> <i>bw</i> <i>normalization</i>)</code> [LISP]</dt>
3343 <dd>This function is identical to <code>snd-reson</code> except
3344 <i>hz</i> (center frequency) is a sound. Filter coefficients are updated at the
3345 sample rate of <i>hz</i>. You should use <code>reson</code> instead (see Section
3346 <a href = "#93">Filter Behaviors</a>).<br><br>
3347 <dt><code>snd-resonvv(<a name="index797"></a><i>sound</i>, <i>hz</i>, <i>bw</i>,
3348 <i>normalization</i>)</code> [SAL]<br>
3349
3350 <code>(snd-resonvv <i>sound</i> <i>hz</i> <i>bw</i> <i>normalization</i>)</code> [LISP]</dt>
3351 <dd>This function is identical to <code>snd-reson</code> except
3352 botth <i>hz</i> (center frequency) and <i>bw</i> (bandwidth) are sounds. Filter
3353 coefficients are updated at the next sample from either <i>hz</i> or <i>bw</i>. You should use <code>reson</code> instead (see Section
3354 <a href = "#93">Filter Behaviors</a>).<br><br>
3355 <dt><code>snd-stkchorus(<a name="index798"></a><a name="index799"></a><a name="index800"></a><a name="index801"></a><i>sound</i>, <i>delay</i>, <i>depth</i>, <i>freq</i>, <i>mix</i>)</code> [SAL]<br>
3356
3357 <code>(snd-stkchorus <i>sound</i> <i>delay</i> <i>depth</i> <i>freq</i> <i>mix</i>)</code> [LISP]</dt>
3358 <dd>A chorus implemented in STK. The parameter <i>delay</i> is a <code>FIXNUM</code>
3359 representing the median desired delay length in samples. A typical
3360 value is 6000. The <code>FLONUM</code> parameters <i>depth</i> and <i>freq</i> set the modulation
3361 depth (from 0 to 1) and modulation frequency (in Hz), <i>mix</i> sets the mixture
3362 of input sound and chorused sound, where a value of 0.0 means input sound
3363 only (dry) and a value of 1.0 means chorused sound only (wet).
3364 You should use <code>stkchorus</code> instead
3365 (see Section <a href = "#94">Effects</a>).<br><br>
3366 <dt><code>snd-stkpitshift(<a name="index802"></a><a name="index803"></a><a name="index804"></a><a name="index805"></a><i>sound</i>, <i>shift</i>, <i>mix</i>)</code> [SAL]<br>
3367
3368 <code>(snd-stkpitshift <i>sound</i> <i>shift</i> <i>mix</i>)</code> [LISP]</dt>
3369 <dd>A
3370 pitch shifter implemented in STK. The <i>sound</i> is shifted in pitch by
3371 <i>shift</i>, a <code>FLONUM</code> representing the shift factor. A value of 1.0 means
3372 no shift. The parameter <i>mix</i> sets the mixture of input and shifted sounds.
3373 A value of 0.0 means input only (dry) and a value of 1.0 means shifted
3374 sound only (wet). You should use <code>pitshift</code> instead
3375 (see Section <a href = "#94">Effects</a>).<br><br>
3376 <dt><code>snd-stkrev(<a name="index806"></a><a name="index807"></a><a name="index808"></a><a name="index809"></a><i>rev-type</i>, <i>sound</i>, <i>decay</i>, <i>mix</i>)</code> [SAL]<br>
3377
3378 <code>(snd-stkrev <i>rev-type</i> <i>sound</i> <i>decay</i> <i>mix</i>)</code> [LISP]</dt>
3379 <dd>A reverb implemented in STK. The parameter rev-type is a
3380 <code>FIXNUM</code> ranging from zero to
3381 two and selects the type of reverb. Zero selects NRev type, one selects JCRev,
3382 and two selects PRCRev. The input <i>sound</i> is processed by the reverb with
3383 a <i>decay</i> time in seconds (a <code>FLONUM</code>). The <i>mix</i>, a <code>FLONUM</code>,
3384 sets the
3385 mixture of dry input and reverb output. A value of 0.0 means input only (dry)
3386 and a value of 1.0 means reverb only (wet). The sample rate
3387 is that of <i>sound</i>. You
3388 should use <code>nrev</code>, <code>jcrev</code> or <code>prcrev</code> instead (see
3389 Section <a href = "#94">Effects</a>).<br><br>
3390 <dt><code>snd-tone(<a name="index810"></a><a name="index811"></a><i>sound</i>, <i>hz</i>)</code> [SAL]<br>
3391
3392 <code>(snd-tone <i>sound</i> <i>hz</i>)</code> [LISP]</dt>
3393 <dd>A
3394 first-order recursive low-pass filter, based on the <i>tone</i> unit generator
3395 of Csound. The <i>hz</i> parameter is the cutoff frequency, the response
3396 curve's half-power point. The result sample rate, start time, etc. are takend from <i>sound</i>.
3397 You should use <code>lp</code> instead (see Section
3398 <a href = "#93">Filter Behaviors</a>).<br><br>
3399 <dt><code>snd-tonev(<a name="index812"></a><i>sound</i>, <i>hz</i>)</code> [SAL]<br>
3400
3401 <code>(snd-tonev <i>sound</i> <i>hz</i>)</code> [LISP]</dt>
3402 <dd>This function is
3403 identical to <code>snd-tone</code> except <i>hz</i> (cutoff frequency) is a sound.
3404 The filter coefficients are updated at the sample rate of <i>hz</i>. You
3405 should use <code>lp</code> instead (see Section
3406 <a href = "#93">Filter Behaviors</a>).
3407 </dd></dl><a name = "105"><h4>Table-Lookup Oscillator Functions</h4></a>
3408 <p>These functions all use a sound to describe one period of a periodic
3409 waveform. In the current implementation, the sound samples are copied to an
3410 array (the waveform table) when the function is called. To make a
3411 table-lookup oscillator generate a specific pitch, we need to have several
3412 pieces of information:
3413 <ul>
3414 <li>
3415 A waveform to put into the table. This comes from the <i>sound</i> parameter.</li>
3416 <li>The length (in samples) of the waveform. This is obtained by reading
3417 samples (starting at the sound's start time, not necessarily at time zero)
3418 until the physical stop time of the sound. (If you read the waveform from a
3419 file or generate it with functions like <code>sim</code> and <code>sine</code>, then the
3420 physical and logical stop times will be the same and will correspond to the
3421 duration you specified, rounded to the nearest sample.) </li>
3422 <li>The intrinsic sample rate of the waveform. This sample rate is simply the
3423 sample rate property of <i>sound</i>.</li>
3424 <li>The pitch of the waveform. This is supplied by the <i>step</i> parameter and
3425 indicates the pitch (in steps) of <i>sound</i>. You might expect that the
3426 pitch would be related to the period (length) of <i>sound</i>, but there is the
3427 interesting case that synthesis based on sampling often loops over multiple
3428 periods. This means that the fundamental frequency of a generated tone may
3429 be some multiple of the looping rate. In Nyquist, you always specify the
3430 perceived pitch of the looped <i>sound</i> if the sound is played at the
3431 <i>sound</i>'s own sample rate.</li>
3432 <li>The desired pitch. This is specified by the <i>hz</i> parameter
3433 in Hertz (cycles per second) in these low-level functions. Note that this
3434 is not necessarily the &ldquo;loop&rdquo; rate at which the table is scanned.
3435 Instead, Nyquist figures what sample rate conversion would be necessary to
3436 &ldquo;transpose&rdquo; from the <i>step</i> which specifies the original pitch of
3437 <i>sound</i> to <i>hz</i>, which gives the desired pitch. The mixed use of steps
3438 and Hertz came about because it seemed that sample tables would be tagged
3439 with steps (&ldquo;I sampled a middle-C&rdquo;), whereas frequency deviation in the
3440 <code>fmosc</code> function is linear, thus calling for a specification in Hertz.</li>
3441 <li>The desired sample rate. This is given by the <i>sr</i> parameter in Hertz.
3442 </li></ul></p>
3443
3444 <p>Other parameters common to all of these oscillator functions are:
3445 <ul>
3446 <li>
3447 <i>t0</i>, the starting time, and</li>
3448 <li><i>phase</i>, the starting phase in degrees. Note that if the <i>step</i>
3449 parameter indicates that the table holds more than one fundamental period, then a starting phase of 360 will be different than a starting phase of 0.
3450 </li></ul></p>
3451 <dl>
3452 <dt>
3453 <code>snd-amosc(<a name="index813"></a><i>sound</i>, <i>step</i>, <i>sr</i>, <i>hz</i>, <i>t0</i>,
3454 <i>am</i>, <i>phase</i>)</code> [SAL]<br>
3455
3456 <code>(snd-amosc <i>sound</i> <i>step</i> <i>sr</i> <i>hz</i> <i>t0</i> <i>am</i> <i>phase</i>)</code> [LISP]</dt>
3457 <dd>An oscillator with amplitude modulation. The sound
3458 <i>am</i> specifies the amplitude and the logical stop time. The physical stop
3459 time is also that of <i>am</i>. You should use <code>amosc</code> instead (see
3460 Section <a href = "#91">Oscillators</a>).<br><br>
3461 <dt><code>snd-fmosc(<a name="index814"></a><i>s</i>, <i>step</i>, <i>sr</i>, <i>hz</i>, <i>t0</i>, <i>fm</i>,
3462 <i>phase</i>)</code> [SAL]<br>
3463
3464 <code>(snd-fmosc <i>s</i> <i>step</i> <i>sr</i> <i>hz</i> <i>t0</i> <i>fm</i> <i>phase</i>)</code> [LISP]</dt>
3465 <dd>A Frequency Modulation oscillator. The sound <i>fm</i> specifies
3466 frequency deviation (in Hertz) from <i>hz</i>. You should use <code>fmosc</code>
3467 instead (see Section <a href = "#91">Oscillators</a>).<br><br>
3468 <dt><code>snd-fmfb(<a name="index815"></a><i>t0</i>, <i>hz</i>, <i>sr</i>, <i>index</i>, <i>dur</i>)</code> [SAL]<br>
3469
3470 <code>(snd-fmfb <i>t0</i> <i>hz</i> <i>sr</i> <i>index</i> <i>dur</i>)</code> [LISP]</dt>
3471 <dd>A Feedback FM oscillator. The resulting sound starts
3472 at <i>t0</i>, has a fundamental frequency of <i>hz</i>, a sample rate of <i>sr</i>,
3473 and a duration of <i>dur</i> seconds. The <i>index</i> is a <code>FLONUM</code> that
3474 specifies the amount of feedback. You should use <code>fmfb</code> instead (see
3475 Section <a href = "#91">Oscillators</a>).<br><br>
3476 <dt><code>snd-fmfbv(<a name="index816"></a><i>t0</i>, <i>hz</i>, <i>sr</i>, <i>index</i>)</code><br>
3477
3478 <code>(snd-fmfv <i>t0</i> <i>hz</i> <i>sr</i> <i>index</i>)</code> [LISP]</dt>
3479 <dd>A
3480 Feedback FM oscillator. The resulting sound starts
3481 at <i>t0</i>, has a fundamental frequency of <i>hz</i>, and
3482 a sample rate of <i>sr</i>. The <i>index</i> is a <code>SOUND</code> that
3483 specifies the amount of feedback and determines the duration.
3484 You should use <code>fmfb</code> instead (see Section <a href = "#91">Oscillators</a>).<br><br>
3485 <dt><code>snd-buzz(<a name="index817"></a><i>n</i>, <i>sr</i>, <i>hz</i>, <i>t0</i>, <i>fm</i>)</code> [SAL]<br>
3486
3487 <code>(snd-buzz <i>n</i> <i>sr</i> <i>hz</i> <i>t0</i> <i>fm</i>)</code> [LISP]</dt>
3488 <dd>A
3489 buzz oscillator, which generates <i>n</i> harmonics of equal amplitude.
3490 The <i>fm</i> specifies
3491 frequency deviation (in Hertz) from <i>hz</i>. You should use <code>buzz</code>
3492 instead (see Section <a href = "#91">Oscillators</a>).<br><br>
3493 <dt><code>snd-pluck(<a name="index818"></a><i>sr</i>, <i>hz</i>, <i>t0</i>, <i>d</i>,
3494 <i>final-amp</i>)</code> [SAL]<br>
3495
3496 <code>(snd-pluck <i>sr</i> <i>hz</i> <i>t0</i> <i>d</i> <i>final-amp</i>)</code> [LISP]</dt>
3497 <dd>A Karplus-Strong plucked string oscillator with sample rate
3498 <i>sr</i>, fundamental frequency <i>hz</i>, starting time <i>t0</i>, duration <i>d</i>,
3499 initial amplitude approximately 1.0 (not exact because the string is
3500 initialized with random values) and final amplitude approximately
3501 <i>final-amp</i>. You should use <code>pluck</code> instead (see Section
3502 <a href = "#91">Oscillators</a>).<br><br>
3503 <dt><code>snd-osc(<a name="index819"></a><i>s</i>, <i>step</i>, <i>sr</i>, <i>hz</i>, <i>t0</i>, <i>d</i>, <i>phase</i>)</code> [SAL]<br>
3504
3505 <code>(snd-osc <i>s</i> <i>step</i> <i>sr</i> <i>hz</i> <i>t0</i> <i>d</i> <i>phase</i>)</code> [LISP]</dt>
3506 <dd>A simple table lookup oscillator with fixed frequency. The duration
3507 is <i>d</i> seconds. You should use <code>osc</code> instead (see Section
3508 <a href = "#91">Oscillators</a>).<br><br>
3509 <dt><code>snd-partial(<a name="index820"></a><i>sr</i>, <i>hz</i>, <i>t0</i>, <i>env</i>)</code> [SAL]<br>
3510
3511 <code>(snd-partial <i>sr</i> <i>hz</i> <i>t0</i> <i>env</i>)</code> [LISP]</dt>
3512 <dd>This is a
3513 special case of <code>snd-amosc</code> that generates a sinusoid starting at phase
3514 0 degrees. The <i>env</i> parameter gives the envelope or any other amplitude
3515 modulation. You should use <code>partial</code> instead (see Section
3516 <a href = "#91">Oscillators</a>).<br><br>
3517 <dt><code>snd-sine(<a name="index821"></a><i>t0</i>, <i>hz</i>, <i>sr</i>, <i>d</i>)</code> [SAL]<br>
3518
3519 <code>(snd-sine <i>t0</i> <i>hz</i> <i>sr</i> <i>d</i>)</code> [LISP]</dt>
3520 <dd>This is a
3521 special case of <code>snd-osc</code> that always generates a sinusoid with initial
3522 phase of 0 degrees. You should use <code>sine</code> instead (see Section
3523 <a href = "#91">Oscillators</a>).<br><br>
3524 <dt><code>snd-sampler(<a name="index822"></a><i>s</i>, <i>step</i>,
3525 <i>start</i>, <i>sr</i>, <i>hz</i>, <i>t0</i>, <i>fm</i>, <i>npoints</i>)</code> [SAL]<br>
3526
3527 <code>(snd-sampler <i>s</i> <i>step</i> <i>start</i> <i>sr</i> <i>hz</i>
3528 <i>t0</i> <i>fm</i> <i>npoints</i>)</code> [LISP]</dt>
3529 <dd>Returns a sound constructed
3530 by reading a sample from beginning to end and then splicing on copies
3531 of the same sound from a loop point to the end.
3532 The sound <i>s</i> is the source sound to be looped, and <i>step</i> (a
3533 FLONUM) is the nominal fundamental frequency (in steps, not Hz) of
3534 <i>s</i>. The <i>start</i> (a FLONUM) is the time in seconds at which to
3535 start the loop, <i>sr</i> (a FLONUM) is the desired sample rate of the
3536 output, <i>hz</i> is the nominal fundamental frequency of the output,
3537 <i>t0</i> (a FLONUM) is the starting time of the output, and <i>fm</i> (a
3538 SOUND) is frequency modulation that is added to <i>hz</i> to determine
3539 the output fundamental frequency. The parameter <i>npoints</i> (a FIXNUM)
3540 specifies how many points should be used for sample
3541 interpolation. Currently this parameter defaults to 2 and only 2-point
3542 (linear) interpolation is implemented. It is an error to modulate
3543 such that the frequency is negative. Note also that the loop point may
3544 be fractional. This function implements a typical sampling synthesis
3545 algorithm, looping and resampling the input according to the ratio
3546 between the desired fundamental frequency (which is the sum of <i>hz</i>
3547 and <i>fm</i>) and the nominal fundamental of the looped sound (which is
3548 assumed to be given by <i>step</i>). You should use <code>sampler</code>
3549 instead (see Section <a href = "#91">Oscillators</a>).<br><br>
3550 <dt><code>snd-siosc(<a name="index823"></a><i>tables</i>, <i>sr</i>, <i>hz</i>, <i>t0</i>,
3551 <i>fm</i>)</code> [SAL]<br>
3552
3553 <code>(snd-siosc <i>tables</i> <i>sr</i> <i>hz</i> <i>t0</i> <i>fm</i>)</code> [LISP]</dt>
3554 <dd>A Spectral Interpolation Oscillator with frequency modulation. The
3555 <i>tables</i> is a list of sounds and sample counts as follows: (<i>table0</i>
3556 <i>count1</i> <i>table1</i> ... <i>countN</i> <i>tableN</i>). The initial waveform is given by <i>table0</i>, which is interpolated linearly to <i>table1</i> over the first
3557 <i>count1</i> samples. From <i>count1</i> to <i>count2</i> samples, the waveform is
3558 interpolated from <i>table1</i> to <i>table2</i>, and so on. If more than
3559 <i>countN</i> samples are generated, <i>tableN</i> is used for the remainder of
3560 the sound. The duration and logical stop time of the sound is taken from
3561 <i>fm</i>, which specified frequency modulation (deviation) in Hertz. You
3562 should use <code>siosc</code> instead (see Section <a href = "#91">Oscillators</a>).
3563 </dd></dl><a name = "106"><h4>Phase Vocoder Functions</h4></a><dl>
3564 <dt>
3565 <code>snd-phasevocoder(<a name="index824"></a><a name="index825"></a><i>s</i>,
3566 <i>map</i>, <i>fftsize</i>, <i>hopsize</i> <i>mode</i>)</code> [SAL]<br>
3567
3568 code{(snd-phasevocoder <i>s</i> <i>map</i> <i>fftsize</i>
3569 <i>hopsize</i> <i>mode</i>) [LISP]}</dt>
3570 <dd>Phase vocoder: Identical
3571 to <code>phasevocoder</code>
3572 except that <i>fftsize</i>, <i>hopsize</i> and <i>mode</i> are not optional.
3573 Specify -1 to get
3574 the default values for <i>fftsize</i> and <i>hopsize</i>. Specify 0 for the
3575 default value of <i>mode</i>. You should use <code>phasevocoder</code> instead
3576 (see Section <a href = "#96">Phase Vocoder</a>).
3577 </dd></dl><a name = "107"><h4>Physical Model Functions</h4></a>
3578 <p>These functions perform some sort of physically-based modeling synthesis.
3579 <dl>
3580 <dt>
3581 <code>snd-bandedwg(<a name="index826"></a><a name="index827"></a><i>freq</i>, <i>bowpress-env</i>, <i>preset</i>, <i>sr</i>)</code> [SAL]<br>
3582
3583 <code>(snd-bandedwg <i>freq</i> <i>bowpress-env</i> <i>preset</i> <i>sr</i>)</code> [LISP]</dt>
3584 <dd>A Banded Wave Guide
3585 Percussion instrument implemented in STK. The parameter <i>freq</i> is a
3586 <code>FLONUM</code> in Hz, <i>bowpress-env</i> is
3587 a <code>SOUND</code> that ranges from zero to one, <i>preset</i> is a <code>FIXNUM</code>,
3588 and <i>sr</i> is the desired sample rate in Hz. Currently, there are four
3589 presets: uniform-bar (0), tuned-bar (1), glass-harmonica (2), and
3590 tibetan-bowl (3). You should use <code>wg-uniform-bar</code>, <code>wg-tuned-bar</code>,
3591 <code>wg-glass-harm</code>, or <code>wg-tibetan-bowl</code> instead (see Section
3592 <a href = "#95">Physical Models</a>).</p>
3593 <dt><code>snd-bowed(<a name="index828"></a><a name="index829"></a><i>freq</i>,
3594 <i>bowpress-env</i>, <i>sr</i>)</code> [SAL]<br>
3595
3596 <code>(snd-bowed <i>freq</i> <i>bowpress-env</i> <i>sr</i>)</code> [LISP]</dt>
3597 <dd>A bowed string instrument implemented in
3598 STK. The freq is a <code>FLONUM</code> in Hertz, bowpress-env is a
3599 <code>SOUND</code> that ranges from z
3600 ero to one, and sr is the desired sample rate (a <code>FLONUM</code>).
3601 You should use bowed instead (see Section <a href = "#95">Physical Models</a>).<br><br>
3602 <dt><code>snd-bowed-freq(<a name="index830"></a><a name="index831"></a><i>freq</i>, <i>bowpress-env</i>, <i>freq-env</i>, <i>sr</i>)</code> [SAL]<br>
3603
3604 <code>(snd-bowed-freq <i>freq</i> <i>bowpress-env</i> <i>freq-env</i> <i>sr</i>)</code> [LISP]</dt>
3605 <dd>A bowed model just like <code>snd-bowed</code> but with
3606 an additional parameter for continuous frequency control. You should use
3607 <code>bowed-freq</code> instead (see Section <a href = "#95">Physical Models</a>).<br><br>
3608 <dt><code>snd-clarinet(<a name="index832"></a><a name="index833"></a><i>freq</i>, <i>breath-env</i>, <i>sr</i>)</code> [SAL]<br>
3609
3610 <code>(snd-clarinet <i>freq</i> <i>breath-env</i> <i>sr</i>)</code> [LISP]</dt>
3611 <dd>A clarinet
3612 model implemented in STK. The <i>freq</i> is a <code>FLONUM</code> in Hertz,
3613 <i>breath-env</i> is
3614 a <code>SOUND</code> that ranges from zero to one, and <i>sr</i> is the
3615 desired sample
3616 rate (a <code>FLONUM</code>). You should use <code>clarinet</code> instead
3617 (see Section
3618 <a href = "#95">Physical Models</a>).<br><br>
3619 <dt><code>snd-clarinet-freq(<a name="index834"></a><a name="index835"></a><i>freq</i>, <i>breath-env</i>, <i>freq-env</i>, <i>sr</i>)</code> [SAL]<br>
3620
3621 <code>(snd-clarinet-freq <i>freq</i> <i>breath-env</i> <i>freq-env</i> <i>sr</i>)</code> [LISP]</dt>
3622 <dd>A clarinet model just like <code>snd-clarinet</code> but with
3623 an additional parameter for continuous frequency control. You should use
3624 <code>clarinet-freq</code> instead (see Section <a href = "#95">Physical Models</a>).<br><br>
3625 <dt><code>snd-clarinet-all(<a name="index836"></a><i>freq</i>, <i>vibrato-freq</i>,
3626 <i>vibrato-gain</i>, <i>freq-env</i>, <i>breath-env</i>, <i>reed-stiffness</i>, <i>noise</i>, <i>sr</i>)</code> [SAL]<br>
3627
3628 <code>(snd-clarinet-all <i>freq</i> <i>vibrato-freq</i> <i>vibrato-gain</i> <i>freq-env</i> <i>breath-env</i> <i>reed-stiffness</i> <i>noise</i> <i>sr</i>)</code> [LISP]</dt>
3629 <dd>A clarinet model just like
3630 <code>snd-clarinet-freq</code> but with
3631 additional parameters for vibrato generation and continuous control of
3632 reed stiffness and breath noise. You should use
3633 <code>clarinet-all</code> instead (see Section <a href = "#95">Physical Models</a>).<br><br>
3634 <dt><code>snd-flute(<a name="index837"></a><a name="index838"></a><i>freq</i>,
3635 <i>breath-env</i>, <i>sr</i>)</code> [SAL]<br>
3636
3637 <code>(snd-flute <i>freq</i> <i>breath-env</i> <i>sr</i>)</code> [LISP]</dt>
3638 <dd>A flute implemented in STK. The <i>freq</i> is a
3639 <code>FLONUM</code> in Hertz, <i>breath-env</i> is a <code>SOUND</code>
3640 that ranges from zero to one, and <i>sr</i> is
3641 the desired sample rate (a <code>FLONUM</code>). You should use <code>flute</code>
3642 instead (see Section <a href = "#95">Physical Models</a>).<br><br>
3643 <dt><code>snd-flute-freq(<a name="index839"></a><a name="index840"></a><i>freq</i>, <i>breath-env</i>,
3644 <i>freq-env</i>, <i>sr</i>)</code> [SAL]<br>
3645
3646 <code>(snd-flute-freq <i>freq</i> <i>breath-env</i> <i>freq-env</i> <i>sr</i>)</code> [LISP]</dt>
3647 <dd>A flute model just like <code>snd-flute</code> but with
3648 an additional parameter for continuous frequency control. You should use
3649 <code>flute-freq</code> instead (see Section <a href = "#95">Physical Models</a>).<br><br>
3650 <dt><code>snd-flute-all(<a name="index841"></a><a name="index842"></a><i>freq</i>, <i>vibrato-freq</i>, <i>vibrato-gain</i>, <i>freq-env</i>, <i>breath-env</i>, <i>jet-delay</i>, <i>noise</i>, <i>sr</i>)</code> [SAL]<br>
3651
3652 <code>(snd-flute-all <i>freq</i> <i>vibrato-freq</i> <i>vibrato-gain</i> <i>freq-env</i> <i>breath-env</i> <i>jet-delay</i> <i>noise</i> <i>sr</i>)</code> [LISP]</dt>
3653 <dd>A flute model just like
3654 <code>snd-flute-freq</code> but with
3655 additional parameters for vibrato generation and continuous control of
3656 breath noise. You should use
3657 <code>flute-all</code> instead (see Section <a href = "#95">Physical Models</a>).<br><br>
3658 <dt><code>snd-mandolin(<a name="index843"></a><a name="index844"></a><i>t0</i>, <i>freq</i>, <i>dur</i>, <i>body-size</i>, <i>detune</i>, <i>sr</i>)</code> [SAL]<br>
3659
3660 <code>(snd-mandolin <i>t0</i> <i>freq</i> <i>dur</i> <i>body-size</i> <i>detune</i> <i>sr</i>)</code> [LISP]</dt>
3661 <dd>A plucked
3662 double-string instrument model implemented in STK. The <i>t0</i> parameter
3663 is the starting time (in seconds), <i>freq</i> is a <code>FLONUM</code> in
3664 Hz, <i>body-size</i> and <i>detune</i> are <code>FLONUM</code>s, and <code>sr</code>
3665 is the desired sample
3666 rate. You should use <code>mandolin</code> instead (see Section <a href = "#95">Physical Models</a>).<br><br>
3667 <dt><code>snd-modalbar(<a name="index845"></a><a name="index846"></a><i>t0</i>, <i>freq</i>, <i>preset</i>, <i>dur</i>, <i>sr</i>)</code> [SAL]<br>
3668
3669 <code>(snd-modalbar <i>t0</i> <i>freq</i> <i>preset</i> <i>dur</i> <i>sr</i>)</code> [LISP]</dt>
3670 <dd>Struck bar instrument
3671 model implemented in STK. The parameter <i>t0</i> is the starting
3672 time (in seconds), <i>freq</i> is a <code>FLONUM</code> in Hz,
3673 <code>preset</code> is a <code>FIXNUM</code> ranging from 0 to 8, <i>dur</i> is a
3674 <code>FLONUM</code> that
3675 sets the duration (in seconds) and <i>sr</i> is the desired sample rate. You
3676 should use <code>modalbar</code> instead (see Section <a href = "#95">Physical Models</a>).<br><br>
3677 <dt><code>snd-sax(<a name="index847"></a><a name="index848"></a><i>freq</i>, <i>breath-env</i>, <i>sr</i>)</code> [SAL]<br>
3678
3679 <code>(snd-sax <i>freq</i> <i>breath-env</i> <i>sr</i>)</code> [LISP]</dt>
3680 <dd>A sax
3681 model implemented in STK. The <i>freq</i> is a <code>FLONUM</code> in Hertz, <i>breath-env</i> is
3682 a <code>SOUND</code> that ranges from zero to one, and <i>sr</i> is the desired sample
3683 rate (a <code>FLONUM</code>). You should use <code>sax</code> instead (see Section
3684 <a href = "#95">Physical Models</a>).<br><br>
3685 <dt><code>snd-sax-freq(<a name="index849"></a><i>freq</i>, <i>freq-env</i>, <i>breath-env</i>,
3686 <i>sr</i>)</code> [SAL]<br>
3687
3688 <code>(snd-sax-freq <i>freq</i> <i>freq-env</i> <i>breath-env</i> <i>sr</i>)</code> [LISP]</dt>
3689 <dd>A sax model just like <code>snd-sax</code> but with
3690 an additional parameter for continuous frequency control. You should use
3691 <code>sax-freq</code> instead (see Section <a href = "#95">Physical Models</a>).<br><br>
3692 <dt><code>snd-sax-all(<a name="index850"></a><i>freq</i>, <i>vibrato-freq</i>,
3693 <i>vibrato-gain</i>, <i>freq-env</i>, <i>breath-env</i>, <i>reed-stiffness</i>, <i>noise</i>, <i>blow-pos</i>, <i>reed-table-offset</i>, <i>sr</i>)</code> [SAL]<br>
3694
3695 <code>(snd-sax-all <i>freq</i> <i>vibrato-freq</i> <i>vibrato-gain</i> <i>freq-env</i> <i>breath-env</i> <i>reed-stiffness</i> <i>noise</i> <i>blow-pos</i> <i>reed-table-offset</i> <i>sr</i>)</code> [LISP]</dt>
3696 <dd>A
3697 sax model just like
3698 <code>snd-sax-freq</code> but with
3699 additional parameters for vibrato generation and continuous control of
3700 reed stiffness, breath noise, excitation position, and reed table offset.
3701 You should use
3702 <code>sax-all</code> instead (see Section <a href = "#95">Physical Models</a>).<br><br>
3703 <dt><code>snd-sitar(<a name="index851"></a><a name="index852"></a><i>t0</i>,
3704 <i>freq</i>, <i>dur</i>, <i>sr</i>)</code> [SAL]<br>
3705
3706 <code>(snd-sitar <i>t0</i> <i>freq</i> <i>dur</i> <i>sr</i>)</code> [LISP]</dt>
3707 <dd>A sitar model implemented in STK. The parameter
3708 <i>t0</i> is the starting time, <i>freq</i> is a <code>FLONUM</code> (in Hz), E
3709 <i>dur</i> sets the duration and <i>sr</i> is the sample rate (in Hz)
3710 of the resulting sound. You should use <code>sitar</code> instead (see Section
3711 <a href = "#95">Physical Models</a>).
3712 </dd></dl><a name = "108"><h4>Sequence Support Functions</h4></a>
3713 <p>The next two functions are used to implement Nyquist's <code>seq</code> construct.</p>
3714 <dl>
3715 <dt>
3716 <code>snd-seq(<a name="index853"></a><i>sound</i>, <i>closure</i>)</code> [SAL]<br>
3717
3718 <code>(snd-seq <i>sound</i> <i>closure</i>)</code> [LISP]</dt>
3719 <dd>This
3720 function returns <i>sound</i> until the logical stop time of <i>sound</i>.
3721 Then, the XLISP <i>closure</i> is evaluated, passing it the logical stop
3722 time of <i>sound</i> as a parameter. The closure must return a sound,
3723 which is then added to <i>sound</i>. (An add is used so that <i>sound</i>
3724 can continue past its logical stop if desired.)
3725 Do not call this function directly.
3726 <br><br>
3727 <dt><code>snd-multiseq(<a name="index854"></a><i>array</i>, <i>closure</i>)</code> [SAL]<br>
3728
3729 <code>(snd-multiseq <i>array</i> <i>closure</i>)</code> [LISP]</dt>
3730 <dd>This
3731 function is similar to <code>snd-seq</code> except the first parameter is a
3732 multichannel sound rather than a single sound. A multichannel sound is
3733 simply an XLISP array of sounds. An array of sounds is returned which is
3734 the sum of <i>array</i> and another array of sounds returned by <i>closure</i>.
3735 The <i>closure</i> is passed the logical stop time of the multichannel sound,
3736 which is the maximum logical stop time of any element of <i>array</i>.
3737 The sample rates and number of channels returned from the closure must
3738 match the first multi-channel sound in the sequence.
3739 Do not call this function directly.
3740
3741 </dd></dl><hr>
3742 <a href = "part7.html">Previous Section</a> | <a href = "part9.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>
3743 </body></html>