I’m not convinced that it does “avoid confusion”.
Many “Loudness” meters handle mono audio incorrectly. Personally I think that creating yet another tool that handles mono incorrectly will add to the problem rather than avoid confusion.
I’m sure that you do understand the issue (we’ve discussed it previously), but for the benefit of other readers:
If you have a mono recording as a single channel audio file, and the same mono recording as a 2 channel audio file (both channels containing the exact same audio), then both files will sound identical. The problem is that many Loudness meters will say that the single channel version is 3 LU quieter than the 2 channel version, which is clearly nonsense as they sound identical.
The macro that I posted was only intended as a demonstration. It could easily be modified to support integer format track by simply changing the Loudness Normalization step to normalize to a lower level, then modify the Nyquist code to compensate, but that makes the code less easy to understand.
(I did however notice that there is a bug in Audacity’s “Loudness Normalization” effect. If the audio level is > 0 LUFS, the effect silently fails. I’ll log this on the Audacity bug tracker if it’s not already logged.)
I would also strongly urge all Audacity users to always use 32-bit float format in all of their projects.
There is nothing “unsafe” about using the value of *scratch* directly provided that the code does not make assumptions about the value of *scratch*.
In the case of LUFS.txt, the macro sets the value of *scratch*, then reads the value back, then clears the value (leaving *scratch* unbound at the end). There is no need in this case to complicate the code with property lists rather than simply binding the symbol to a value.
This is very tricky. From a quick look I suspect that the problem lies with using the PEAK function. Setting *track* to NIL does not help in this case because RAM can’t be released while there a reference to the data exists. The solution that comes to mind would be to write your own DSP function using OOP so that it consumes the samples as it searches for the peak. Unfortunately that would be both difficult and much slower than using PEAK.
(Also a similar issue with SND-LENGTH).
An alternative “solution” is to enforce a maximum length (possibly by checking the max length as well as the min length in the ERROR-CHECK function).
There’s an associated problem with the .ny code, which is that it doesn’t restore SND-SET-MAX-AUDIO-MEM back to the original value. This will affect the global environment until Audacity is restarted.
A minimal example of how to restore SND-SET-MAX-AUDIO-MEM:
(setf old (SND-SET-MAX-AUDIO-MEM 1000))
You will also need to take care that SND-SET-MAX-AUDIO-MEM is not left in a non-default state if the ERROR-CHECK function throws.