Behavioral Abstraction

o 440Hz, but fre finishes. The parameters to note are predefined in Nyquist: c4 is middle C, i (for eIghth note) is 0.5, and q (for Quarter note) is 1.0. See Section ``Predefined Constants'' for a complete description. The result is the sum of all the computed sounds.

Envelopes

The next example will illustrate the use of envelopes. In Nyquist, envelopes are just ordinary sounds (although they normally have a low sample rate). An envelope is applied to another sound by multiplication using the mult function. The code shows the definition of env-note, defined in terms of the note function in the previous example. In env-note, a 4-phase envelope is generated using the env function, which is illustrated in Figure 1.




Figure 1: An envelope generated by the env function.


; env-note produces an enveloped note.  The duration
;   defaults to 1.0, but stretch can be used to change
;   the duration.
;
(defun env-note (p)
  (mult (note p 1.0)
	(env 0.05 0.1 0.5 1.0 0.5 0.4)))

; try it out: ; (play (env-note c4))

; now use stretch to play different durations ; (play (seq (stretch 0.25 (seq (env-note c4) (env-note d4))) (stretch 0.5 (seq (env-note f4) (env-note g4))) (env-note c4)))

The end of this example shows the use of stretch to modify durations. There are several transformations supported by Nyquist, and transformations of abstract behaviors is perhaps the fundamental idea behind Nyquist. Chapter ``Behavioral Abstraction'' is devoted to explaining this concept, and further elaboration can be found elsewhere (Dannenberg and Frayley 1989).

Piece-wise Linear Functions

It is often convenient to construct signals in Nyquist using a list of (time, value) breakpoints which are linearly interpolated to form a smooth signal. Envelopes created by env are a special case of the more general piece-wise linear functions created by pwl. Since pwl is used in some examples later on, we will take a look at pwl now. The pwl function takes a list of parameters which denote (time, value) pairs. There is an implicit initial (time, value) pair of (0, 0), and an implicit final value of 0. There should always be an odd number of parameters, since the final time is not implicit. Here are some examples:
; symetric rise to 10 (at time 1) and fall back to 0 (at time 2):
;
(pwl 1 10 2)

; a square pulse of height 10 and duration 5. ; Note that the first pair (0, 10) overrides the default initial ; point of (0, 0). Also, there are two points specified at time 5: ; (5, 10) and (5, 0). (The last 0 is implicit). The conflict is ; automatically resolved by pushing the (5, 10) breakpoint back to ; the previous sample, so the actual time will be 5 - 1/sr, where ; sr is the sample rate. ; (pwl 0 10 5 10 5)

; a constant function with the value zero over the time interval ; 0 to 3.5. This is a very degenerate form of pwl. Recall that there ; is an implicit initial point at (0, 0) and a final implicit value of ; 0, so this is really specifying two breakpoints: (0, 0) and (3.5, 0): ; (pwl 3.5)

; a linear ramp from 0 to 10 and duration 1. ; Note the ramp returns to zero at time 1. As with the square pulse ; above, the breakpoint (1, 10) is pushed back to the previous sample. ; (pwl 1 10 1)

; If you really want a linear ramp to reach its final value at the ; specified time, you need to make a signal that is one sample longer. ; The RAMP function does this: ; (ramp 10) ; ramp from 0 to 10 with duration 1 + one sample period ; ; RAMP is based on PWL; it is defined in nyquist.lsp. ;

Predefined Constants

For convenience and readability, Nyquist pre-defines some constants, mostly based on the notation of the Adagio score language, as follows:


Previous Section | Next Section | Table of Contents | Index | Title Page ./usr/share/doc/nyquist/doc/part3.html0000644000000000000000000004007507567156143020055 0ustar rootroot00000000000000Behavioral Abstraction

Behavioral Abstraction

o 440Hz, but fre finishes. The parameters to note are predefined in Nyquist: c4 is middle C, i (for eIghth note) is 0.5, and q (for Quarter note) is 1.0. See Section ``Predefined Constants'' for a complete description. The result is the sum of all the computed sounds.

Envelopes

The next example will illustrate the use of envelopes. In Nyquist, envelopes are just ordinary sounds (although they normally have a low sample rate). An envelope is applied to another sound by multiplication using the mult function. The code shows the definition of env-note, defined in terms of the note function in the previous example. In env-note, a 4-phase envelope is generated using the env function, which is illustrated in Figure 1.




Figure 1: An envelope generated by the env function.


; env-note produces an enveloped note.  The duration
;   defaults to 1.0, but stretch can be used to change
;   the duration.
;
(defun env-note (p)
  (mult (note p 1.0)
	(env 0.05 0.1 0.5 1.0 0.5 0.4)))

; try it out: ; (play (env-note c4))

; now use stretch to play different durations ; (play (seq (stretch 0.25 (seq (env-note c4) (env-note d4))) (stretch 0.5 (seq (env-note f4) (env-note g4))) (env-note c4)))

The end of this example shows the use of stretch to modify durations. There are several transformations supported by Nyquist, and transformations of abstract behaviors is perhaps the fundamental idea behind Nyquist. Chapter ``Behavioral Abstraction'' is devoted to explaining this concept, and further elaboration can be found elsewhere (Dannenberg and Frayley 1989).

Piece-wise Linear Functions

It is often convenient to construct signals in Nyquist using a list of (time, value) breakpoints which are linearly interpolated to form a smooth signal. Envelopes created by env are a special case of the more general piece-wise linear functions created by pwl. Since pwl is used in some examples later on, we will take a look at pwl now. The pwl function takes a list of parameters which denote (time, value) pairs. There is an implicit initial (time, value) pair of (0, 0), and an implicit final value of 0. There should always be an odd number of parameters, since the final time is not implicit. Here are some examples:
; symetric rise to 10 (at time 1) and fall back to 0 (at time 2):
;
(pwl 1 10 2)

; a square pulse of height 10 and duration 5. ; Note that the first pair (0, 10) overrides the default initial ; point of (0, 0). Also, there are two points specified at time 5: ; (5, 10) and (5, 0). (The last 0 is implicit). The conflict is ; automatically resolved by pushing the (5, 10) breakpoint back to ; the previous sample, so the actual time will be 5 - 1/sr, where ; sr is the sample rate. ; (pwl 0 10 5 10 5)

; a constant function with the value zero over the time interval ; 0 to 3.5. This is a very degenerate form of pwl. Recall that there ; is an implicit initial point at (0, 0) and a final implicit value of ; 0, so this is really specifying two breakpoints: (0, 0) and (3.5, 0): ; (pwl 3.5)

; a linear ramp from 0 to 10 and duration 1. ; Note the ramp returns to zero at time 1. As with the square pulse ; above, the breakpoint (1, 10) is pushed back to the previous sample. ; (pwl 1 10 1)

; If you really want a linear ramp to reach its final value at the ; specified time, you need to make a signal that is one sample longer. ; The RAMP function does this: ; (ramp 10) ; ramp from 0 to 10 with duration 1 + one sample period ; ; RAMP is based on PWL; it is defined in nyquist.lsp. ;

Predefined Constants

For convenience and readability, Nyquist pre-defines some constants, mostly based on the notation of the Adagio score language, as follows:


Previous Section | Next Section | Table of Contents | Index | Title Page ./usr/share/doc/nyquist/doc/part3.html0000644000000000000000000004007507567156143020055 0ustar rootroot00000000000000Behavioral Abstraction