when you evaluate a behavior is important...

Using Nyquist scripts in Audacity.
Post and download new plug-ins.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
fearless_fool
Posts: 30
Joined: Wed May 29, 2013 6:44 pm
Operating System: Please select

when you evaluate a behavior is important...

Post by fearless_fool » Mon Aug 12, 2013 2:21 am

This is a little note for anyone just getting started in Nyquist. Like me. Perhaps this will save somebody some confusion and astonishment.

Consider the following code evaluated in Nyquist:

Code: Select all

(setq envelope-var (pwl 1 1 1))
(display "envelope-var" (snd-extent (stretch 4.0 envelope-var) 1000000))

(defun envelope-fun () (pwl 1 1 1))
(display "envelope-fun" (snd-extent (stretch 4.0 (envelope-fun)) 1000000))
You might expect snd-extent to produce the same results for the two cases: we're starting with the same envelope function (pwl 1 1 1) and stretching it by the same amount (stretch 4.0 <expression>). Let's see what happens:

Code: Select all

envelope-var : (SND-EXTENT (STRETCH 4 ENVELOPE-VAR) 1000000) = (0 1)  
envelope-fun : (SND-EXTENT (STRETCH 4 (ENVELOPE-FUN)) 1000000) = (0 4)  
T
Oho! The extent of envelope-var ends at 1, the extent of (envelope-fun) ends at 4.

An expert should correct me if I'm wrong about this, but the crucial difference is when (pwl 1 1 1) is evaluated. For envelope-var, the pwl function is evaluated BEFORE stretch is called. In envelope-fun, pwl is evaluated within the context of the stretch. Behind the scenes, pwl looks at the global *warp* variable to determine its start and stop times (more accurately, the mapping between local and global times). So when pwl is evaluated to set envelope-var, stretch is not in effect, so the result isn't subjected to stretching. On the other hand, when (envelope-fun) calls pwl, stretching is already in effect, so the result *is* properly stretched.

Moral: make sure you don't evaluate a behavior until you're in the correct evaluation context.

(uh, did I get that right?)

steve
Site Admin
Posts: 80679
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: when you evaluate a behavior is important...

Post by steve » Mon Aug 12, 2013 6:49 am

More generally, be careful when modifying the transformation environment. This is probably the trickiest aspect of Nyquist. The manual includes several examples of how to use transformations successfully, but I still find it easy to do it wrong :D
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Paul L
Posts: 1782
Joined: Mon Mar 11, 2013 7:37 pm
Operating System: Please select

Re: when you evaluate a behavior is important...

Post by Paul L » Sun Nov 24, 2013 1:59 am

stretch and at and similar are NOT functions but macros written in terms of the Lisp progv form! Learn what that means. It confused me when I began. I think the version of the documentation that I read misleadingly called some of the macros functions.

Post Reply