Sorry for the late response, but it took quite a while until I had the time to grep through the Audacity sources.
The result is that Robert is right and the Nyquist ABS-ENV macro produces wrong results if the Audacity track sample rate is not 44100 Hertz because SOUND-SRATE is bound to DEFAULT-SOUND-SRATE in the scope of ABS-ENV, where the Nyquist DEFAULT-SOUND-SRATE in Audacity is wrongly initialized with constantly 44100 Hertz instead to the value of the Audacity track sample rate.
Also the Nyquist CONTROL-SRATE and DEFAULT-CONTROL-SRATE variables are wrongly initialized with constantly 2205 Hertz instead to the value of the Audacity track sample rate dividied by twenty.
Also Robert is theoretically right that DEFAULT-SOUND-SRATE should be set to the Audacity project sample rate, but only theoretically, because Nyquist in Audacity is doomed to work within the scope of a single Audacity track, where Nyquist does not have the capability to change the Audacity track sample rate. This has to the consequence that a Nyquist sound object, returned by Nyquist with a sample rate different than the Audacity track sample rate, will be treatened wrong by the Audacity Nyquist interface.
Examples for known side-effects of mismatching sample rates:
[1] If a Nyquist envelope of e.g. 100 samples, computed by Nyquist with a sample rate of CONTROL-SRATE, is be directly returned to Audacity, then the envelope is inserted into the Audacity audio track as a sound of 100 samples with a sample rate of SOUND-SRATE, not CONTROL-SRATE.
[2] If the sound of an Audacity selection is resampled by a Nyquist function to a different sample rate, and the resampled sound is returned to Audacity, then the sound is inserted into the Audacity audio track with s rample rate of SOUND-SRATE, not with its new sample rate.
These side-effects come from Nyquist’s incapability to change the Audacity track sample rate. But fixing this is not as easy as it sounds because:
[1] The Audacity selection often is only a part of an audio track, and it’s very questionable if it would make sense to suddenly change the sample rate in the middle of an Audacity audio track, only because the returned Nyquist sound has a different sample rate.
[2] It’s also not a really clever idea to automatically resample a returned Nyquist sound to the Audacity track sample rate, because this would make the behaviour of the Audacity Nyquist interface even more complicated than it already is.
As long as Nyquist can only work within the scope of a single audio track it makes not much sense for Nyquist to know the Audacity project sample rate, because there is nothing Nyquist could do with this information. Or does anybody know a specific use-case for this? Maybe I haven’t realized where this information could be useful.
Things that can be done with a realistic chance to become true:
I will try to find a ways how to initialize the DEFAULT-SOUND-SRATE to the Audacity track sample rate, and also initialize CONTROL-SRATE and DEFAULT-CONTROL-SRATE to the correct values directly in the Audacity Nyquist interface. This is not too hard and has a reasonably low risk to introduce other unwanted side-effects.
Preliminary workarounds:
Setting all four variables to their correct values in a Nyquist plugin can be done by writing the following lines at the beginning of the plugin code:
(setf *default-sound-srate* *sound-srate*)
(setf *default-control-srate* (/ *sound-srate* 20.0))
(setf *control-srate* *default-control-srate*)
There is no need to call NYQ:ENVIRONMENT-INIT afterwards, because all other environment values do not depend on the values of these variables.
I have found no places other than ABS-ENV where DEFAULT-SOUND-SRATE is used, but we must take into account that ABS-ENV is called by other Nyquist functions like ENV and GATE, and also used by the Nyquist XMUSIC library.