I’ve added code tags and line indentations to the code that you posted making it easier to read.
(To add code tags, click on the “Code” button above the message composing box then insert your code between the code tags like this:
[code]
... code goes here ...
[/code]
The code is a “Loop”. It is described in the XLisp manual here: http://www.audacity-forum.de/download/edgar/nyquist/nyquist-doc/xlisp/xlisp-ref/xlisp-ref-093.htm
After the “DO” command, there are 4 local variables set. “Local” means that they only exist within this block of code.
“C” is set to an initial value of 0.0
“l” to NIL
“p” to “true” [note that “T” or “t” is a special symbol that has the boolean value “true”]
“v” is set to the value of a sample which is read with (snd-fetch s2), where “s2” must be a “sound”. http://www.cs.cmu.edu/~rbd/doc/nyquist/part8.html#index260
The next line is a test to see if the loop should continue: (not v)
and then the return value “l”.
Note that it is NOT generally good practice to use single characters as variable names. It may be OK where the variable is only used within a very limited context, but code is usually easier to read, easier to maintain and easier to bug fix if concise but meaningful names are used. “l” (lower case “L”) is a particularly bad name to use as in some fonts it looks like the number “1”.
So the loop initially sets these values, and then continues looping until “not v”, which means until “v” is NIL. “v” will be NIL when there are no more samples to fetch.
Next comes the body of the loop:
(if (and p (> v thres))
(setq l (cons (list c "B") l)))
If “p” is “true” (not NIL) and “v” is less than “thresh”
then
set “L” to (cons (list c “B”) l))
(cons (list c “B”) l)) adds a list containing the value of “c” and the string value “B” to the list “L”
This could be written a lot more clearly.
If we used variable names:
“time” instead of “c”
“below-thresh” instead of “p”
“Label-list” instead of “l”
“val” instead of “v”
(if (and below-thresh (> val thres))
(push (list time "B") label-list))
“push” is described here: http://www.cs.cmu.edu/~rbd/doc/nyquist/part13.html#index1000
The last part of the body sets new values for p, c and v.
For what its worth, I’d probably have written it something like this:
(do ((label-list ())
(below-thresh T)
(time 0.0 (+ time 0.001))
(val (snd-fetch s2) (snd-fetch s2)))
((not val) label-list)
(if (and below-thresh
(> val thres))
(push (list time "B") label-list))
(setq below-thresh (< val thres)))
Which with lost of comments:
(do ((label-list ()) ; Initialise empty list.
(below-thresh T) ; Initialise flag as 'true'.
; Initialise 'time = 0'. Add 0.001 on each loop.
(time 0.0 (+ time 0.001))
; Get sample values.
(val (snd-fetch s2) (snd-fetch s2)))
; Until 'val = NIL'. Reurn label-list.
((not val) label-list)
; If crossing from below to above threshold
(if (and below-thresh
(> val thres))
; Add label to list.
(push (list time "B") label-list))
; is val below threshold?
(setq below-thresh (< val thres)))