I’ve just been caught out (again) by this one, but having solved the problem I think this is a good example so I’m posting it.
As stated in the Nyquist Manual, “sounds are not behaviors!” Behavioral Abstraction
sounds are not behaviors! > Behaviors are computations that generate sounds according to the transformation environment. Once a sound has been generated, it can be stored, copied, added to other sounds, and used in many other operations, but sounds are not subject to transformations.
Here’s the example:
(setq tone (hzosc 440))
(hzosc ) generates a sine tone at frequency .
This is a “behaviour” and it produces a “sound”.
The variable “tone” is set to (hzosc 440), so “tone” is a “sound”. (hzosc 440) is evaluated and the sound that it produces is given the variable name “tone”.
What I wanted to do was to make this sound last for 12 seconds. I can do this with the function (stretch-abs)
Note that the syntax for stretch-abs is:
(stretch-abs factor beh)
“stretch” and “stretch-abs” are transformations and they operate on behaviours and not on sounds.
So this code will produce a 440 Hz tone for 12 seconds duration:
(stretch-abs 12.0 (hzosc 440))
But this code will produce a 440 Hz tone for 1 second duration:
(setq tone (hzosc 440)) (stretch-abs 12.0 tone)
“stretch-abs” is NOT applied to “tone” because “tone” is a sound and not a behaviour.
So what happens if we have a lot of behaviours that we want to stretch to the same length?
This does not work because it is attempting to stretch sounds
(setq tone (scale 0.4 (hzosc 440))) (setq mynoise (scale 0.5 (osc 60))) (defun stretch12 (s-in) (stretch-abs 12 s-in)) (sim (stretch12 tone) (stretch12 mynoise) )
But this does work because it is applying “stretch” to the behaviours
(defun tone () (stretch-abs 12.0 (scale 0.4 (hzosc 440)))) (defun mynoise () (stretch-abs 12.0 (scale 0.5 (osc 60)))) (sim (tone)(mynoise))
And so does this:
(setq tone (stretch-abs 12.0 (scale 0.4 (hzosc 440)))) (setq mynoise (stretch-abs 12.0 (scale 0.5 (osc 60)))) (sim tone mynoise)
and so does this:
(defun tone () (scale 0.4 (hzosc 440))) (defun mynoise () (scale 0.5 (osc 60))) (stretch-abs 12.0 (sim (tone)(mynoise)))