Audacity Bug Summary
••• Introduction •••
••• Keywords •••
    Audacity 3.0.3 development began 19th April 2021

Audacity Bugzilla



Bug 631 - SND-SEQ.sets global "S" to NIL
SND-SEQ.sets global "S" to NIL
Status: CLOSED NOT-A-BUG
Product: Audacity
Classification: Unclassified
Component: Nyquist
unspecified
PC All
: P4 RepeatableAll
Assigned To: Default Assignee for New Bugs
: nyquist
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-03-29 11:50 UTC by Steve Daulton
Modified: 2018-08-20 11:51 UTC (History)
7 users (show)

See Also:
Steps To Reproduce:
(setf s1 s) (snd-seq (osc 60) #'(lambda (t0) (at-abs t0 (cue s1)))) produces the expected result, but (snd-seq (osc 60) #'(lambda (t0) (at-abs t0 (cue s)))) fails with the error: error: bad argument type - NIL Function: #<Subr-SND-SRATE: #c604130> Arguments: NIL Function: #<Closure-CUE-SOUND: #c51d08c> Arguments: NIL
Release Note:
First Git SHA:
Group: ---
Workaround:
Closed: 2018-08-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Daulton 2013-03-29 11:50:23 UTC
SEQ fails if the second or subsequent sound is "S" (the global used by Audacity to pass sound from the selection to Nyquist.

This failure is due to SND-SEQ setting "S" to NIL (which should not happen).
Comment 1 Steve Daulton 2017-08-11 14:34:37 UTC
Closed as Invalid as the Nyquist manual clearly states:
"Do not call this function. See seq in Section "Combination and Time Structure"."
http://www.audacity-forum.de/download/edgar/nyquist/nyquist-doc/manual/part6.html#index587
Comment 2 Roger Dannenberg 2017-08-11 23:21:21 UTC
I think I know what's going on here:
1) Audacity sets S to the input sound
2) (snd-seq (osc 60) #'(lambda (t0) (at-abs t0 (cue s)))) is evaluated, returning a sound to Audacity. The sound is "lazy" with structure containing (A) a pointer to the sound returned by (osc 60), and (B) the unevaluated list (FUNCTION (LAMBDA (T0) (AT-ABS T0 (CUE S)))))
3) Audacity sets S to NIL to remove the second reference to the sound it is about to obtain samples from (failing to do this would cause the computed sound to be retained in the LISP heap instead of going into Audacity files.)
4) Audacity extracts samples from the sound. First 1s of audio is generated from (osc 60). Then, it's time for the second part of SND-SEQ, so it evaluates the list, passing 1.0 as parameter t0. AT-ABS is a macro that eventually evaluates (CUE S), but S in NIL, so "error: bad argument type - NIL" is generated.

Is this a bug? I'd say it is an unintended consequence of the original interface in which the input sound is specified by setting a global. I think the argument at the time was that this would be simpler than requiring a function definition, but it was a compromise at best.

Is there a workaround? I think the best approach would be:
;; simulate a functional-style interface:
(defun myfn (input) (snd-seq (osc 60) #'(lambda (t0) (at-abs 0 (cue input)))))
(myfn s)

[I have not tested this.]

I missed this the first time around, but just for the record, SND-SEQ does NOT set S to NIL.
Comment 3 James Crook 2017-08-12 06:02:43 UTC
REOPENED so that Audacity documentation (at least) can be updated.  Then perhaps we close this again.
Comment 4 Steve Daulton 2017-08-12 09:33:25 UTC
(In reply to Roger Dannenberg from comment #2)
> ;; simulate a functional-style interface:
> (defun myfn (input) (snd-seq (osc 60) #'(lambda (t0) (at-abs 0 (cue input)))))
> (myfn s)
> 
> [I have not tested this.]

I have, and it works as expected.

Another workaround:

(let ((s s))
(seq (osc 60) (cue s)))

or

(sim (osc 60) (at 1 (cue s)))


> I'd say it is an unintended consequence of the original interface in which
> the input sound is specified by setting a global
...
> SND-SEQ does NOT set S to NIL

Those were also my conclusions, which I think make this invalid as a "bug".



James wrote:
> so that Audacity documentation (at least) can be updated.

What exactly needs to be updated?
The Nyquist manual is not 'our' documentation, and this behaviour does not apply to standalone Nyquist. We could add a note here: http://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference but I'm not clear what needs to be said.
Comment 5 James Crook 2017-08-12 10:55:14 UTC
Steve wrote:
> What exactly needs to be updated?
> The Nyquist manual is not 'our' documentation...  I'm not clear what 
> needs to be said.

I'm not clear either!

It's your call Steve...  S (and the NILing of it) is peculiar to Audacity, and I'd have thought should be mentioned on our wiki page, along with the workaround.  But I see S is not used that way in V4....  

I'd mistakenly thought I all-too-hastily closed this bug in my Spring Cleaning, and was fixing my mistake.  Restored to INVALID. If users already know not to use SND-SEQ then we're fine.