Debian Codegraph @

doc/part2.html

raw
1 <!DOCTYPE html>
2 <html><head><title>Introduction and Overview</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 = "part1.html">Previous Section</a> | <a href = "part3.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 = "2"><h2>Introduction and Overview</h2></a>
11 <p>Nyquist is a language for sound synthesis and music composition. Unlike score
12 languages that tend to deal only with events, or signal processing languages
13 that tend to deal only with signals and synthesis, Nyquist handles both in a
14 single integrated system. Nyquist is also flexible and easy to use because it
15 is based on an interactive Lisp interpreter.</p>
16
17 <p>With Nyquist, you can design instruments by combining functions (much as you
18 would using the orchestra languages of Music V, cmusic, or Csound). You can
19 call upon these instruments and generate a sound just by typing a simple
20 expression. You can combine simple expressions into complex ones to create
21 a whole composition.</p>
22
23 <p>Nyquist runs under Linux, Apple macOS, Microsoft Windows NT,
24 2000, XP, and Vista,
25 and it produces sound files or directly generates audio.
26 Recent versions have also run on AIX, NeXT, SGI, DEC pmax, and Sun Sparc
27 machines. (Makefiles for many of these are included, but out-of-date).
28 Let me know if you have problems with
29 any of these machines.</p>
30
31 <p>The core language of Nyquist is Lisp. Nyquist extends Lisp for
32 sound synthesis and processing.
33 Starting with Version 3, Nyquist supports a variant of
34 SAL syntax. SAL is a language distinct from Lisp, but it can be
35 translated to Lisp and SAL and Lisp programs can be combined.
36 SAL was introduced in Rick
37 Taube's Common Music system. Since there are some differences between
38 Nyquist and Common Music, one should generally call this
39 implementation &ldquo;Nyquist SAL;&rdquo; however, in this manual, I will just
40 call it &ldquo;SAL.&rdquo; SAL offers most of the capabilities of Lisp, but it
41 uses an Algol-like syntax that may be more familiar to programmers
42 with experience in Java, C, Basic, etc. An introduction to SAL is in
43 Mary Simoni and Roger B. Dannenberg, <i>Algorithmic Composition: A
44 Guide to Composing Music with Nyquist</i> <a href = "http://www.algocompbook.com/">(Simoni and Dannenberg 2013)</a>.
45 To learn about Lisp, an
46 excellent text by Touretzky is recommended <a href = "musicbib.html#touretzky">(Touretzky 1984)</a>. Appendix
47 <a href = "part19.html#224">Appendix 3: XLISP: An Object-oriented Lisp</a> is the reference manual for XLISP, of which Nyquist is
48 a superset. </p>
49 <a name = "3"><h3>Installation</h3></a><a name="index5"></a><a name="index6"></a><a name="index7"></a>
50 <p>Nyquist is a C++ program intended to run under various operating systems
51 including Unix, macOS, and Windows. Nyquist is based on Lisp, but it
52 includes its own Lisp interpreter (a modified version of XLISP), so you
53 do not need to install some other Lisp to run Nyquist. Other
54 Lisp systems are not compatible with Nyquist.</p>
55
56 <p>Most Nyquist users run Nyquist under the Nyquist IDE, which is written in Java
57 and depends on the Java runtime system. Most systems already have Java, but if
58 you do not, you will need to install it. Java from Oracle is recommended, e.g.
59 Java SE Development Kit 17. When you install the Nyquist IDE,
60 you will automatically get Nyquist and a set of runtime libraries.</p>
61
62 <p>There are generally two ways to install Nyquist:
63 <ul>
64 <li>
65 Get a pre-compiled version of the Nyquist IDE for Windows or macOS. The
66 Windows version comes packaged in an installer that installs and
67 configures the Nyquist IDE. The macOS version
68 unpacks to a complete OS X application.</li>
69 <li>Compile from sources. There is one set of sources for Mac, Windows, and Unix.
70 Instructions for building applications from the sources are provided in
71 the files <code>sys/win/README.txt</code>, <code>sys/mac/README.txt</code>, and
72 <code>sys/unix/README.txt</code>.
73 </li></ul></p>
74
75 <p>You can download source code and precompiled versions from the Nyquist project
76 on SourceForge (<code>http://sourceforge.net/projects/nyquist</code>). The latest
77 source code can be obtained via Subversion (svn) using the following:
78 </p>
79 <pre>
80 svn co svn://svn.code.sf.net/p/nyquist/code/trunk/nyquist nyquist
81 </pre>
82
83 <p>
84 or by checking out nyquist using a graphical interface svn client such as
85 TortoiseSVN for Windows.</p>
86 <a name = "4"><h4>Troubleshooting</h4></a>
87 <p>All versions of Nyquist includes a Readme.txt file in the top-level
88 <code>nyquist</code> directory with general information.
89 Additional information and instructions on installation
90 can be found in: <ul>
91 <li> <tt>nyquist/doc/readme-win.txt</tt></li>
92 <li><tt>nyquist/doc/readme-mac.txt</tt></li>
93 <li><tt>nyquist/doc/readme-linux.txt</tt>
94 </li></ul></p>
95 <a name = "5"><h3>Using NyquistIDE</h3></a><a name="index8"></a><a name="index9"></a><a name="index10"></a>
96 <p>The program named NyquistIDE is an &ldquo;integrated development
97 environment&rdquo; for Nyquist. When you run NyquistIDE, it starts the
98 Nyquist program and displays all Nyquist output in a
99 window. NyquistIDE helps you by providing a Lisp and SAL editor, hints
100 for command completion and function parameters, some graphical
101 interfaces for editing envelopes and graphical equalizers, and a panel
102 of buttons for common operations. A more complete description of
103 NyquistIDE is in Chapter <a href = "part3.html#18">The NyquistIDE Program</a>.</p>
104
105 <p>For now, all you really need to know is that you can enter Nyquist
106 commands by typing into the upper left window. When you type return,
107 the expression you typed is sent to Nyquist, and the results appear in
108 the window below. You can edit files by clicking on the New File or
109 Open File buttons. After editing some text, you can load the text into
110 Nyquist by clicking the Load button. NyquistIDE always saves the file
111 first; then it tells Nyquist to load the file. You will be prompted
112 for a file name the first time you load a new file.</p>
113 <a name = "6"><h3>Using SAL</h3></a>
114 <p>SAL mode means that Nyquist reads and evaluates SAL commands rather
115 than Lisp. The SAL mode prompt is "<code>SAL&gt; </code>" while the Lisp mode
116 prompt is "<code>&gt; </code>". When Nyquist starts it normally enters SAL
117 mode automatically, but certain errors may exit SAL mode. You can
118 reenter SAL mode by typing the Lisp expression <code>(sal)</code>.</p>
119
120 <p>In SAL mode, you type commands in the SAL programming
121 language. Nyquist reads the commands, compiles them into Lisp, and
122 evaluates the commands. Commands can be entered manually by typing
123 into the upper left text box in NyquistIDE.</p>
124 <a name = "7"><h3>Command Line</h3></a><a name="index11"></a><a name="index12"></a><a name="index13"></a>
125 <p>When run from the command line, Nyquist (usually the command is <tt>ny</tt>) looks
126 for some options and some files to load. There are several options.</p>
127
128 <p>The <a name="index14"></a><a name="index15"></a><tt>-R</tt><i>paths</i>
129 option gives Nyquist a list of paths (separated by semicolons) to
130 directories where Nyquist is allowed to read files. Files in any
131 subdirectories of the listed directories can also be read, along with
132 the directories themselves. This option can be used to restrict access
133 to files.</p>
134
135 <p>The <tt>-W</tt><i>paths</i> option gives Nyquist a list of paths (separated by
136 semicolons) to directories where Nyquist is allowed to write files
137 (including sound files). If <tt>-W</tt> is used, Nyquist will not open
138 audio output to play sounds and will not allow access to Open Sound
139 Control. This option can be used to protect files from accidentally
140 malicious code. (If you are truly worried about Nyquist code, you
141 should run Nyquist in a virtual machine or other isolated machine. It
142 is unlikely that Nyquist is secure from all attacks.)</p>
143 <a name="index16"></a><a name="index17"></a>The
144 <tt>-L</tt><i>run-time-limit</i> option gives Nyquist a run time limit. If the
145 limit is exceeded, Nyquist prints an error message and exits. The time
146 is based on Lisp expression evaluations rather than CPU seconds or
147 wall time or even execution time involved in printing or signal processing.
148 One unit
149 of run time is on the order of 10ms of CPU time (for a medium speed
150 computer in 2019), but depending on what you are computing, a unit
151 of run time can vary from 60ms to 1.5ms.
152 You can use the <code>GET-RUN-TIME</code> function to
153 read the internal run-time counter to see how much computation you
154 have done in the same units.<a name="index18"></a><a name="index19"></a><a name="index20"></a>The
155 <tt>-M</tt><i>memory-limit</i> option gives Nyquist a memory limit. If the
156 limit (in megabytes) is exceeded, Nyquist prints an error message and
157 exits. The limit includes all XLISP data (cons cells, strings, etc.)
158 plus sample blocks and tables allocated for signal processing.
159 <p>The <tt>-T</tt><i>transcript-file-name</i> option copies console output to a transcript
160 file.</p>
161
162 <p>The <tt>-V</tt> option sets verbose mode. If set, any files specified on
163 the command line to be loaded are loaded with the verbose option.</p>
164
165 <p>Additionally, the command line can name files to be loaded. Nyquist begins by
166 loading <tt>init.lsp</tt>, which by default is in the <tt>nyquist/runtime</tt> directory.
167 This file loads all the standard Nyquist functions. After that, Nyquist will
168 load any other files named on the command line.</p>
169
170 <p>Finally, Nyquist expects to find search paths in the <tt>XLISPPATH</tt> environment
171 variable (or for Windows, see installation instructions; the path is saved
172 in the Windows Registry). Normally, you must set <tt>XLISPPATH</tt> for Nyquist to
173 find <tt>init.lsp</tt> and the definitions of most Nyquist functions.
174 Be sure you have <tt>system.lsp</tt> in <tt>nyquist/runtime</tt>. Part of the installation
175 process copies the appropriate <tt>system.lsp</tt> from <tt>nyquist/sys/*</tt> to
176 <tt>nyquist/runtime</tt> where it can be found and loaded by <tt>init.lsp</tt>.</p>
177 <a name = "8"><h3>Helpful Hints</h3></a>
178 <p>Under Win95 and Win98, the console sometimes locks up. Activating
179 another window and then reactivating the Nyquist window should unlock
180 the output. (We suggest you use NyquistIDE, the interactive
181 development environment rather than a console window.)</p>
182
183 <p>You can cut and paste text into Nyquist, but for serious work, you
184 will want to use the Lisp <code>load</code> command. To save even more time,
185 write a function to load your working file, e.g. <code>(defun l ()
186 (load "myfile.lsp"))</code>. Then you can type <code>(l)</code> to (re)load your
187 file.</p>
188
189 <p>Using SAL, you can type
190 </p>
191 <pre>
192 define function l () load "myfile.lsp"
193 </pre>
194
195 <p>
196 and then
197 </p>
198 <pre>
199 exec l()
200 </pre>
201
202 <p>
203 to (re)load the file.</p>
204
205 <p>The Emacs editor is free GNU software and will help you balance
206 parentheses if you use Lisp mode. In fact, you can run nyquist
207 (without the IDE) as a subprocess to Emacs. A helful discussion is
208 at //http://www.audacity-forum.de/download/edgar/nyquist/nyquist-doc/examples/emacs/main.html. If
209 you use Emacs, there is also a SAL mode (the file is
210 <code>sal-mode.el</code>) included with the Common Music distribution, which
211 you can find on the Web at <code>sourceforge.net</code>.</p>
212
213 <p>The NyquistIDE also runs Nyquist as a subprocess and has built-in Lisp
214 and SAL editors. If your editor does not help you balance parentheses,
215 you may find yourself counting parens and searching for unbalanced
216 expressions. If you are confused or desperate and using Lisp syntax,
217 try the <code>:print t</code> option of the <code>load</code> function. By looking
218 at the expressions printed, you should be able to tell where the last
219 unbalanced expression starts. Alternatively, type
220 <code>(file-sexprs)</code> and type the lisp file name at the prompt. This
221 function will read and print expressions from the file, reporting an
222 error when an extra paren or end-of-file is reached unexpectedly.</p>
223 <a name = "9"><h3>Using Lisp</h3></a>
224 <p>Lisp mode means that Nyquist reads and evaluates Nyquist expressions in
225 Lisp syntax. Since Nyquist is build on a Lisp interpreter, this is the
226 &ldquo;native&rdquo; or machine language of Nyquist, and certain errors and functions
227 may break out of the SAL interpreter, leaving you with a prompt for a Lisp
228 expression. Alternatively, you can exit SAL simply by typing <code>exit</code> to
229 get a Lisp prompt (<code>&gt; </code>). Commands can be entered manually by typing
230 into the upper left text box in NyquistIDE.</p>
231 <a name = "10"><h3>Examples</h3></a>
232 <p>We will begin with some simple Nyquist programs. Throughout the manual,
233 we will assume SAL mode and give examples in SAL, but it should be
234 emphasized that all of these examples can be performed using Lisp
235 syntax. See Section <a href = "part7.html#78">Interoperability of SAL and XLISP</a> on the relationship between
236 SAL and Lisp.</p>
237
238 <p>Detailed explanations of the functions used in these examples will be
239 presented in later chapters, so at this point, you should just read these
240 examples to get a sense of how Nyquist is used and what it can do. The
241 details will come later. Most of these examples can be found in the
242 file <code>nyquist/lib/examples.sal</code>. Corresponding Lisp syntax
243 examples are in the file <code>nyquist/lib/examples.lsp</code>.</p>
244
245 <p>Our first example makes and plays a sound:<a name="index21"></a><a name="index22"></a>
246 </p>
247 <pre>
248 <i>;; Making a sound.</i>
249 play osc(60) ; generate a loud sine wave
250 </pre>
251
252 <p></p>
253
254 <p>This example is about the simplest way to create a sound with Nyquist.
255 The <code>osc</code> function generates a sound using a table-lookup
256 oscillator. There are a number of optional parameters, but the
257 default is to compute a sinusoid with an amplitude of 1.0. The
258 parameter <code>60</code> designates a pitch of middle C. (Pitch
259 specification will be described in greater detail later.) The result
260 of the <code>osc</code> function is a sound. To hear a sound, you must use
261 the <code>play</code> command, which plays the file through the machine's
262 D/A converters. It also writes a soundfile in case the computation
263 cannot keep up with real time. You can then (re)play the file by
264 typing:
265 </p>
266 <pre>
267 exec r()
268 </pre>
269
270 <p>
271 This <code>(r)</code> function is a general way to &ldquo;replay&rdquo; the last thing written by <code>play</code>.</p>
272
273 <p>Note: when Nyquist plays a sound, it scales the signal by
274 2<sup>15</sup>-1 and (by default)
275 converts to a 16-bit integer format. A signal like <code>(osc 60)</code>,
276 which ranges from +1 to -1, will play as a full-scale 16-bit audio
277 signal.</p>
278 <a name = "11"><h4>Non-Sinusoidal Waveforms</h4></a>
279 <p>Our next example will be presented in several steps. The goal is to create a
280 sound using a
281 wavetable consisting of several harmonics as opposed to a simple sinusoid.
282 In order to build a table, we will use a function that computes a single
283 harmonic and add harmonics to form a wavetable. An special function,
284 <code>build-harmonic</code> is used to compute the harmonics, but it is just a
285 convenient wrapper for the primitive function <code>snd-sine</code>.</p>
286
287 <p>The function
288 <code>mkwave<a name="index23"></a></code> calls upon
289 <code>build-harmonic<a name="index24"></a></code> to generate a total of four
290 harmonics with amplitudes 0.5, 0.25, 0.125, and 0.0625.
291 These are scaled and added (using <code>+<a name="index25"></a></code>) to
292 create a waveform which is bound to local variable <code>wave</code>. </p>
293
294 <p>A complete Nyquist wavetable specification
295 is a list consisting of a sound, a pitch,
296 and <code>T</code>, indicating a periodic waveform. The pitch gives the
297 nominal pitch of the sound. (This is implicit in a single cycle wave
298 table, but a sampled sound may have many periods of the fundamental.)
299 Pitch is expressed in half-steps, where middle C is 60 steps, as in MIDI
300 pitch numbers.
301 The list of sound, pitch, and <code>T</code> is formed in the last line of
302 <code>mkwave</code>: since <code>build-harmonic</code> computes signals with a duration
303 of one second, the fundamental is 1 Hz, and the <code>hz-to-step</code> function
304 converts to pitch (in units of steps) as required.</p>
305
306
307 <p></p>
308 <pre>
309 define function mkwave()
310 begin
311 with wave = 0.5 * build-harmonic(1, 2048) +
312 0.25 * build-harmonic(2, 2048) +
313 0.125 * build-harmonic(3, 2048) +
314 0.0625 * build-harmonic(4, 2048)
315 set *mytable* = list(wave, hz-to-step(1.0), #t)
316 end
317 </pre>
318
319 <p></p>
320
321 <p>Now that we have defined a function, the next step of this example is
322 to build the wavetable. The following code calls <code>mkwave</code> the first
323 time the code is executed (loaded from a file). The second time, the
324 variable <code>*mkwave*</code> will be set, so <code>mkwave</code> will not be
325 invoked:
326 </p>
327 <pre>
328 if ! boundp(quote(*mkwave*)) then
329 begin
330 exec mkwave()
331 set *mkwave* = #t
332 end
333 </pre>
334
335 <p></p>
336 <a name = "12"><h4>Using Wavetables</h4></a><a name="index26"></a><a name="index27"></a><a name="index28"></a><a name="index29"></a>
337 <p>When Nyquist starts, several waveforms are created and stored in
338 global variables for convenience. They are: <code>*sine-table*</code>,
339 <code>*saw-table*</code>, and <code>*tri-table*</code>, implementing sinusoid,
340 sawtooth, and triangle waves, respectively. The variable
341 <code>*table*</code> is initialized to <code>*sine-table*</code>, and it is
342 <code>*table*</code> that forms the default wavetable for many Nyquist
343 oscillator behaviors. If you want a proper, band-limited waveform, you
344 should construct it yourself, but if you do not understand this
345 sentence and/or you do not mind a bit of aliasing, give
346 <code>*saw-table*</code> and <code>*tri-table*</code> a try.</p>
347
348 <p>Note that in Lisp and SAL, global variables often start and end with
349 asterisks (*). These are not special syntax, they just happen to be
350 legal characters for names, and their use is purely a convention.</p>
351 <a name = "13"><h4>Sequences</h4></a><a name="index30"></a>
352 <p>Finally, we define <code>my-note<a name="index31"></a></code> to use the waveform,
353 and play several notes in a simple score. Note that the function
354 <code>my-note</code> has only one command (a <code>return</code> command), so it
355 is not necessary to use <code>begin</code> and <code>end</code>. These are only
356 necessary when the function body consists of a sequence of statements:
357 </p>
358 <pre>
359 define function my-note(pitch, dur)
360 return osc(pitch, dur, *mytable*)
361
362 play seq(my-note(c4, i), my-note(d4, i), my-note(f4, i),
363 my-note(g4, i), my-note(d4, q))
364 </pre>
365
366 <p></p>
367
368 <p>Here, <code>my-note</code> is defined to take pitch and duration as parameters;
369 it calls <code>osc</code> to do the work of generating a waveform, using
370 <code>*mytable*</code> as a wave table. In earlier examples, we saw
371 <code>osc</code> with only two parameters. In that case, <code>*table*</code> is
372 used, but here we specify our new table <code>*mytable*</code>.</p>
373
374 <p>The <code>seq</code> function is used to invoke a sequence of behaviors. Each
375 note is started at the time the previous note finishes. The parameters to
376 <code>my-note</code> are predefined in Nyquist: <code>c4</code> is middle C, <code>i</code> (for
377 eIghth note) is 0.5, and <code>q</code> (for Quarter note) is 1.0. See Section
378 <a href = "#16">Predefined Constants</a> for a complete description. The result is the sum of
379 all the computed sounds.</p>
380
381 <p>Sequences can also be constructed using the <code>at</code> transformation to
382 specify time offsets.</p>
383 <a name = "14"><h4>Envelopes</h4></a><a name="index32"></a>
384 <p>The next example will illustrate the use of envelopes. In Nyquist,
385 envelopes are just ordinary sounds (although they normally have a low sample
386 rate). An envelope<a name="index33"></a> is applied to another sound by
387 multiplication using the <code>mult<a name="index34"></a></code> function. The code shows
388 the definition of <code>env-note<a name="index35"></a></code>, defined in terms of the
389 <code>note</code> function in the previous example. In <code>env-note</code>, a 4-phase
390 envelope is generated using the <code>env<a name="index36"></a></code> function, which is
391 illustrated in Figure <a href = "#14">1</a>.</p>
392 <hr>
393 <blockquote>
394 </blockquote>
395 <img src="fig1.gif"><br><br>
396
397 <p><b>Figure 1: </b>An envelope generated by the <code>env</code> function.
398
399 </p>
400 <hr>
401 <p></p>
402 <pre>
403 <i>; env-note produces an enveloped note. The duration
404 ; defaults to 1.0, but stretch can be used to change
405 ; the duration.
406 ; Uses my-note, defined above.
407 ;</i>
408 define function env-note(p)
409 return my-note(p, 1.0) *
410 env(0.05, 0.1, 0.5, 1.0, 0.5, 0.4)
411
412 <i>; try it out:
413 ;</i>
414 play env-note(c4)
415 </pre>
416
417 <p></p>
418
419 <p>While this example shows a smooth envelope multiplied by an audio signal,
420 you can also multiply audio signals to achieve
421 what is often called <i>ring modulation</i><a name="index37"></a>. </p>
422
423 <p>In the next example, The <i>stretch</i> operator (<code>~</code>)<a name="index38"></a>
424 is used to modify durations:
425 </p>
426 <pre>
427 <i>; now use stretch to play different durations
428 ;</i>
429 play seq(seq(env-note(c4), env-note(d4)) ~ 0.25,
430 seq(env-note(f4), env-note(g4)) ~ 0.5,
431 env-note(c4))
432 </pre>
433
434 <p></p>
435
436 <p>In addition to <i>stretch</i>, there are a number of transformations supported
437 by Nyquist,
438 and transformations of abstract behaviors is perhaps <i>the</i> fundamental
439 idea behind Nyquist. Chapter <a href = "part4.html#27">Behavioral Abstraction</a> is devoted to
440 explaining this concept, and further elaboration can be found elsewhere
441 <a href = "http://www.cs.cmu.edu/~rbd/bib-arctic.html#icmcfugue">(Dannenberg and Frayley 1989)</a>.</p>
442 <a name = "15"><h4>Piece-wise Linear Functions</h4></a>
443 <p>It is often convenient to construct signals in Nyquist using a list of
444 (time, value) breakpoints which are linearly interpolated to form a smooth
445 signal. Envelopes created by <code>env</code> are a special case of the more
446 general piece-wise linear functions created by <code>pwl</code>. Since <code>pwl</code>
447 is used in some examples later on, we will take a look at <code>pwl</code>
448 now. The <code>pwl</code> function takes a list of parameters which denote (time,
449 value) pairs. There is an implicit initial (time, value) pair of (0, 0),
450 and an implicit final value of 0. There should always be an odd number of
451 parameters, since the final value (but not the final time) is implicit.
452 Here are some examples:
453 </p>
454 <pre>
455 <i>; symmetric rise to 10 (at time 1) and fall back to 0 (at time 2):
456 ;</i>
457 pwl(1, 10, 2)
458 </pre>
459
460 <p>
461 </p>
462 <pre>
463 <i>; a square pulse of height 10 and duration 5.
464 ; Note that the first pair (0, 10) overrides the default initial
465 ; point of (0, 0). Also, there are two points specified at time 5:
466 ; (5, 10) and (5, 0). (The last 0 is implicit). The conflict is
467 ; automatically resolved by pushing the (5, 10) breakpoint back to
468 ; the previous sample, so the actual time will be 5 - 1/sr, where
469 ; sr is the sample rate.
470 ;</i>
471 pwl(0, 10, 5, 10, 5)
472 </pre>
473
474 <p>
475 </p>
476 <pre>
477 <i>; a constant function with the value zero over the time interval
478 ; 0 to 3.5. This is a very degenerate form of pwl. Recall that there
479 ; is an implicit initial point at (0, 0) and a final implicit value of
480 ; 0, so this is really specifying two breakpoints: (0, 0) and (3.5, 0):
481 ;</i>
482 pwl(3.5)
483 </pre>
484
485 <p>
486 </p>
487 <pre>
488 <i>; a linear ramp from 0 to 10 and duration 1.
489 ; Note the ramp returns to zero at time 1. As with the square pulse
490 ; above, the breakpoint (1, 10) is pushed back to the previous sample.
491 ;</i>
492 pwl(1, 10, 1)
493 </pre>
494
495 <p>
496 </p>
497 <pre>
498 <i>; If you really want a linear ramp to reach its final value at the
499 ; specified time, you need to make a signal that is one sample longer.
500 ; The RAMP function does this:
501 ;</i>
502 ramp(10) <i>; ramp from 0 to 10 with duration 1 + one sample period
503 ;
504 ; RAMP is based on PWL; it is defined in <b><i>nyquist.lsp</i></b>.
505 ;</i>
506 </pre>
507
508 <p></p>
509 <a name = "16"><h3>Predefined Constants</h3></a>
510 <p>For convenience and readability, Nyquist pre-defines some constants, mostly
511 based on the notation of the Adagio score language, as follows:
512 <ul>
513 <li>
514 <b>Dynamics</b>
515 Note: these dynamics values are subject to change.
516 <blockquote>
517 <tt>lppp<a name="index39"></a></tt> = -12.0 (dB)<br>
518
519 <tt>lpp<a name="index40"></a></tt> = -9.0<br>
520
521 <tt>lp<a name="index41"></a></tt> = -6.0<br>
522
523 <tt>lmp<a name="index42"></a></tt> = -3.0<br>
524
525 <tt>lmf<a name="index43"></a></tt> = 3.0<br>
526
527 <tt>lf<a name="index44"></a></tt> = 6.0<br>
528
529 <tt>lff<a name="index45"></a></tt> = 9.0<br>
530
531 <tt>lfff<a name="index46"></a></tt> = 12.0<br>
532
533 <tt>dB0<a name="index47"></a></tt> = 1.00<br>
534
535 <tt>dB1<a name="index48"></a></tt> = 1.122<br>
536
537 <tt>dB10<a name="index49"></a></tt> = 3.1623<br>
538
539 </blockquote></li>
540 <li><b>Durations<a name="index50"></a></b>
541 <blockquote>
542 <tt>s<a name="index51"></a></tt> = Sixteenth<a name="index52"></a> = 0.25<br>
543
544 <tt>i<a name="index53"></a></tt> = eIghth<a name="index54"></a> = 0.5<br>
545
546 <tt>q<a name="index55"></a></tt> = Quarter<a name="index56"></a> = 1.0<br>
547
548 <tt>h<a name="index57"></a></tt> = Half<a name="index58"></a> = 2.0<br>
549
550 <tt>w<a name="index59"></a></tt> = Whole<a name="index60"></a> = 4.0<br>
551
552 <tt>sd<a name="index61"></a>, id<a name="index62"></a>, qd<a name="index63"></a>, hd<a name="index64"></a>, wd<a name="index65"></a></tt> = dotted durations<a name="index66"></a>.<br>
553
554 <tt>st<a name="index67"></a>, it<a name="index68"></a>, qt<a name="index69"></a>, ht<a name="index70"></a>, wt<a name="index71"></a></tt> = triplet<a name="index72"></a> durations.<br>
555
556 </blockquote></li>
557 <li><b>Pitches<a name="index73"></a></b>
558 <a name="index74"></a><a name="index75"></a><a name="index76"></a>
559 Pitches are based on an A4 of 440Hz. To achieve a different tuning,
560 set <code>*A4-Hertz*</code> to the desired frequency for A4, and call
561 <code>(set-pitch-names)</code>. This will recompute the names listed below with a
562 different tuning. In all cases, the pitch value 69.0 corresponds exactly to
563 440Hz, but fractional values are allowed, so for example, if you set
564 <code>*A4-Hertz*</code> to 444 (Hz), then the symbol <code>A4</code> will be bound to
565 69.1567, and <code>C4</code> (middle C), which is normally 60.0, will be 60.1567.
566 <blockquote>
567 <tt>c0</tt> = 12.0<br>
568
569 <tt>cs0, df0</tt> = 13.0<br>
570
571 <tt>d0</tt> = 14.0<br>
572
573 <tt>ds0, ef0</tt> = 15.0<br>
574
575 <tt>e0</tt> = 16.0<br>
576
577 <tt>f0</tt> = 17.0<br>
578
579 <tt>fs0, gf0</tt> = 18.0<br>
580
581 <tt>g0</tt> = 19.0<br>
582
583 <tt>gs0, af0</tt> = 20.0<br>
584
585 <tt>a0</tt> = 21.0<br>
586
587 <tt>as0, bf0</tt> = 22.0<br>
588
589 <tt>b0</tt> = 23.0<br>
590
591 <tt>c1</tt> ... <tt>b1</tt> = 24.0 ... 35.0<br>
592
593 <tt>c2</tt> ... <tt>b2</tt> = 36.0 ... 47.0<br>
594
595 <tt>c3</tt> ... <tt>b3</tt> = 48.0 ... 59.0<br>
596
597 <tt>c4</tt> ... <tt>b4</tt> = 60.0 ... 71.0<br>
598
599 <tt>c5</tt> ... <tt>b5</tt> = 72.0 ... 83.0<br>
600
601 <tt>c6</tt> ... <tt>b6</tt> = 84.0 ... 95.0<br>
602
603 <tt>c7</tt> ... <tt>b7</tt> = 96.0 ... 107.0<br>
604
605 <tt>c8</tt> ... <tt>b8</tt> = 108.0 ... 119.0<br>
606
607 </blockquote></li>
608 <li><b>Miscellaneous</b>
609 <blockquote>
610 <code>ny:all</code><a name="index77"></a> = &ldquo;all the samples&rdquo; (i.e. a big number) = 1000000000<br>
611
612 </blockquote>
613 </li></ul></p>
614 <a name = "17"><h3>More Examples</h3></a>
615 <p>More examples can be found in a set of extensions, which are not
616 included in the Nyquist download files. Instead, the NyquistIDE has a
617 Window : Extension Manager menu item. Selecting this will open the
618 Extension Manager, which enables you to download and install or update
619 selected extensions to the <code>nyquist/lib</code> directory. The Extension
620 Manager will also allow you to browse documentation for each extension.
621 Here are some highlights of what is available:
622 <ul>
623 <li> Code to create atonal melodies
624 (<code>nyquist/lib/atonal/atonal-melodies.sal</code>).</li>
625 <li>How to make arpeggios (<code>nyquist/lib/arpeggiator/arpeggiator.htm</code> and<br>
626
627 <code>nyquist/lib/arpeggiator/arp.sal</code>)<a name="index78"></a></li>
628 <li>Gong sounds by additive synthesis<a name="index79"></a>
629 (<code>nyquist/lib/pmorales/b1.lsp</code> and<br>
630
631 <code>nyquist/lib/pmoralies/mateos/gong.lsp</code>)<a name="index80"></a><a name="index81"></a></li>
632 <li>Risset's spectral analysis of a chord
633 (<code>nyquist/lib/pmorales/b2.lsp</code>)<a name="index82"></a><a name="index83"></a></li>
634 <li>Bell sounds (<code>nyquist/lib/pmorales/b3.lsp</code>,
635 <code>nyquist/lib/pmorales/e2.lsp</code>,<br>
636
637 <code>nyquist/lib/pmorales/partial.lsp</code>, and
638 <code>nyquist/lib/mateos/bell.lsp</code>)<a name="index84"></a><a name="index85"></a></li>
639 <li>Drum sounds by Risset (<code>nyquist/lib/pmorales/b8.lsp</code><a name="index86"></a><a name="index87"></a></li>
640 <li>Shepard tones (<code>nyquist/lib/shepard/shepard.lsp</code> and
641 <code>nyquist/lib/pmorales/b9.lsp</code>)<a name="index88"></a><a name="index89"></a></li>
642 <li>Random signals (<code>nyquist/lib/pmorales/c1.lsp</code>)</li>
643 <li>Buzz with formant filters
644 (<code>nyquist/lib/pmorales/buzz.lsp</code>)<a name="index90"></a><a name="index91"></a></li>
645 <li>Computing samples directly in Lisp (using Karplus-Strong and physical
646 modelling as examples) (<code>nyquist/lib/pmorales/d1.lsp</code>)<a name="index92"></a><a name="index93"></a><a name="index94"></a><a name="index95"></a><a name="index96"></a><a name="index97"></a></li>
647 <li>FM Synthesis examples, including FM voices<br>
648
649 (<code>nyquist/lib/fm-voices-chowning/fm-voices-chowning.sal</code>) designed by John
650 Chowning<a name="index98"></a><a name="index99"></a>, tuba sound
651 (<code>nyquist/lib/mateos/tuba.lsp</code>)<a name="index100"></a>, and see
652 <code>nyquist/lib/pmorales/e2.lsp</code> for examples of FM bell<a name="index101"></a>, wood drum<a name="index102"></a>, brass sounds<a name="index103"></a>, and clarinet sounds.<a name="index104"></a><a name="index105"></a></li>
653 <li>Rhythmic patterns
654 (<code>nyquist/lib/rhythm/rhythm_tutorial.html</code>)<a name="index106"></a></li>
655 <li>Drum Samples and Drum Machine
656 (<code>nyquist/lib/plight/drum.lsp</code>)<a name="index107"></a><a name="index108"></a><a name="index109"></a>. (See Section <a href = "part16.html#206">Drum Machine</a>).
657 </li></ul></p>
658 <hr>
659 <a href = "part1.html">Previous Section</a> | <a href = "part3.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>
660 </body></html>