Nyquist "to-mono" function

Hi Steve,

I know I’m being daft, just cant figure out where.
I’m trying to use the “to-mono” function, but it keeps giving the following error:
Screen Shot 2021-11-02 at 6.32.55 PM.png
I have tried:

(setf lev-all 
    (linear-to-db 
        (peak 
           (lowpass8 
              (to-mono *track*) 
           20000) 
        10000000)
    )
)

And even:

(setf lev-all 
    (linear-to-db 
        (peak 
           (to-mono 
             (lowpass8 *track* 20000) 
           )
        10000000)
     )
)

Then even simplified the code down to:

(to-mono *track*)

In all cases, same error.

The manual states:


I read the above as, if sound is an array (as in stereo - which it is in my case), then
“sum” them together.
If it’s not an array, (mono), then return unchanged.

Can you please give me any pointers as to where I’m going wrong.
Thanks.

Funny, I’ve never noticed that function. I suspect that it is new.
Which version of Audacity are you using?

Ver 2.3.1 on Mac.

Steve wrote:

Funny, I’ve never noticed that function. I suspect that it is new.

I suspect that you are correct.
I have been working off the new manual:
Screen Shot 2021-11-02 at 7.46.57 PM.png
Just checked the older manual dated 2007, and sure enough it’s not there.

Is it perhaps a macro?
In which case I could add it in my extras.lsp which will be loaded along with Nyquist.

That’s probably too old.

Try adding this to your script before you use TO-MONO

(defun to-mono (sig)
  (let ((s sig))
    (when (arrayp sig)
      (setf s (aref sig 0))
      (dotimes (i (1- (length sig)))
        (setf s (sim s (aref sig (1+ i))))))
    s))

The actual code in the later version of Nyquist (below) is a bit more complex, but does the same as the above function.
Here’s the version in Audacity 3.1.0:

(defun to-mono (sound)
  (ny:typecheck (not (or (soundp sound) (multichannel-soundp sound)))
    (ny:error "TO-MONO" 1 '((SOUND) NIL) sound t))
  (let ((s sound))
    (cond ((arrayp sound)
           (setf s (aref sound 0))  ;; ANY channel opens the gate
            (dotimes (i (1- (length sound)))
             (setf s (nyq:add-2-sounds s (aref sound (1+ i)))))))
    s))

It’s a function. Yes you could add it to your “extras.lsp” (assuming that you have configured Nyquist to load that file).

Your version of Nyquist probably does not have “ny:typecheck”, in which case use the shorter / simpler version from my previous post.

Perfect, thank you very much.
Your shorter function worked perfectly.

I can see it works as no error msg and the level went up by 6 dB.
Might be tempted to scale down the result by the same amount in the function.

I like to load “new” functions into my “extras.lsp” file to keep the actual scripts short.
The downside is that they are no longer standard.

Yes, I have referenced my extras.lsp in nyinit.lsp so it gets loaded at run time.

Note that the +6dB occurs only when the waveforms are in phase (peaks and troughs coincide in both channels). Example: If the left channel is an inverted copy of the right channel, then the sum will be silence.

Also note that the code can handle multiple (more than 2) channels, even though Audacity currently only supports mono or stereo.

Are you using an old Mac, or do you have another reason to use an old version of Audacity?
Have you tried Audacity 2.4.2? In my opinion, that was the pinnacle of the 2.x series.

Steve wrote:

Note that the +6dB occurs only when the waveforms are in phase

Correct and it’s part of the reason for wanting to use the function, to check the phase of left vs right channels.

Are you using an old Mac, or do you have another reason to use an old version of Audacity?
Have you tried Audacity 2.4.2? In my opinion, that was the pinnacle of the 2.x series.

I’m using a Macbook Pro (mid 2012) with Mac 10.12.6
Also have a Win8 laptop somewhere, also has 2.3.1 on it.
My nix boxes all have 2.2.1 on Debian 10.

At the studio, have several Macbooks, iMacs and “dustbins” of varying ages and OS versions.
I just found that 2.3.1 has been very stable and has served me well both at home and at work.

For now at least, I think the 3.x series needs to mature a bit more before I will consider upgrading.

As for 2.4.2, I’m willing to consider it, especially as you rate it very highly.

Would it be a simple case of just downloading it and installing it? (Is it compatible with Mac 10.12 ?).
Would all my plugins (ny, VST, AU and some LADSPA) still work including any presets?

I’m not using 3.x for production work either (for the same reason).

Linux is a good platform for testing new releases now that AppImages are available (no need to uninstall your regular version, though to be on the safe side I’d recommend backing up the ~/.audacity-data folder (I just rename it as ~/audacity-data-bak, then change it back after testing the AppImage).


I believe so.

Up to and including 2.4.2, just install in the usual way.
Personally I like to reset preferences when I upgrade, though this is often not necessary.

Thanks Steve.

This is how I’m going to approach it…
(It’s probably the safest way, although the most laborious, but like to err on the side of caution).

The Win8 laptop, will try on that first with 2.4.2
I rarely use Windows so if anything goes wrong, no catastrophe.

For Mac, will try on the oldest Macbook Pro at work and use it for a while
to see how things behave.
There is one in one of the edit suites that is just used for emails, etc.
Perfect candidate.
Will patch it in to one of the inputs on the desk and play for a while.

As for Linux, I read somewhere that the AppImage does not support Jack audio.
Is that correct, or am I mistaken?

I use Jack audio as the default on all my nix boxes.

That was correct the last time that I checked.
The AppImage versions have been improving with each release, but not yet mature enough for production use in my opinion (though 3.1.0 may be good enough for anyone that does not require Jack).

OK, thanks for the confirmation.

So as it stands, I am going to try 2.4.2 on Windows and Mac.
For Linux, will hold off upgrading from 2.2.1 until the AppImage has Jack support.

EDIT:

Maybe for Linux, module-jack-sink and source could be a “work-around” to use Jack?

This is Audacity 3.1.0 AppImage using PulseAudio Jack source / Sink

jack.png

Great to see that 3.1 works with Jack sink and source.
I use the same arrangement with 2.2.1