Nyquist code for Normalize, Generate Tone

Effects, Recipes, Interfacing with other software, etc.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
seanybob
Posts: 12
Joined: Thu Apr 30, 2009 2:20 am
Operating System: Please select

Nyquist code for Normalize, Generate Tone

Post by seanybob » Wed May 06, 2009 6:08 pm

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?

Thanks,
Seanybob



Edit:
Just found code for normalizing:

Code: Select all

; 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))

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Nyquist code for Normalize, Generate Tone

Post by steve » Wed May 06, 2009 7:22 pm

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-saw(hz)
osc-tri(hz)
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.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply