Nyquist code for Normalize, Generate Tone

Hey there,
Just had a quick question. Anybody know if the Nyquist code is available somewhere for the Effect ‘Normalize’ (or a similar effect) and the function Generate ‘Tone’?

I’m trying to automate a process for editting an audio file (my other thread has details on that) and these are the last steps before the process is fully automated.

Also curious, is there a way to combine two audio tracks into a stereo track with Nyquist?


Just found code for normalizing:

; normalize function
(defun normalize (signal)
(setf x (if (arrayp signal)
(s-max (peak (aref signal 0) ny:all) (peak (aref signal 1) ny:all))
(peak signal ny:all)))
(scale (/ 0.95 x) signal))

You need to take a bit of care with that Normalize code. NY:ALL is 1 giga-samples, as suggested in the manual, you may want a smaller constant if you have less than 4GB of memory.

To generate a sine tone you can just use “osc” as the default table is a sine. Alternatively there are:
sine(pitch, [duration])
osc-pulse(hz, bias, [compare-shape])
for different types of tone.

Note that in Audacity the default duration is the length of the selection and not 1 second.

Nyquist in Audacity can only access one sound (track), although this may be mono or stereo. It does this through a special variable “s”, which takes the value of the selected sound.

It may be possible to read and write sounds directly from disk, but I don’t think that this is implemented in the current release version of Audacity. For processing sounds outside of Audacity it would be easier, and make more sense to use the standalone version of Nyquist.