Nyquist Basics: The Audacity Nyquist Prompt

From Audacity Wiki
Revision as of 20:05, 18 September 2009 by Onlinetimc (talk | contribs) (The Nyquist Prompt)
Jump to: navigation, search
With the Audacity Nyquist Prompt you can test small snippets of Nyquist code you are working on, or run a Nyquist effect in any way you wish (as opposed to how that plug-in works as built into Audacity). On this page the basic usage of the Nyquist Prompt is explained.
Related article(s):
Please note: The notation in the current Nyquist Reference Manual from the Nyquist homepage at the Carnegie Mellon Universtiy is incompatible to Nyquist in Audacity. Please use the Nyquist 2.37 Manual from the link above if you're working with Nyquist in Audacity.

Setting up

The Audacity Nyquist prompt appears in Audacity's "Effect" menu. This menu can be only be activated if an Audacity audio track exists and at least some audio in it is selected.

For testing generate commands in Nyquist, you can add Nyquist Generate Prompt to the Audacity Plug-Ins folder.

Load a Sound File

If you have a mono or stereo sound file available you can import it into Audacity via:

File > Import > Audio or the shortcut CTRL + SHIFT + I

If you have no sound files available you can build your own mono or stereo tracks via the Audacity "Generate" menu.

Create a Mono Track

Click Generate > Tone. Leave everything as-is, just click "OK", a mono track will appear in the Audacity window:

Audacity mono track

Create a Stereo Track

1. Create an empty stereo track.

  • In Audacity 1.2.x click Project > New Stereo Track.
  • In Audacity 1.3.x-beta click Track > Add New... > Stereo Track.

In both cases an empty stereo track will apperar in the Audacity window.

2. Now click Generate > Tone. Leave everything as-is, just click "OK", the empty stereo track will get filled with the generated sound.

Audacity stereo track

The Nyquist Prompt

Click Effect > Nyquist Prompt. If the Effect Menu is greyed out because no part of the audio is selected, press CTRL + A on the keyboard. A window like the following will appear:

Audacity Nyquist prompt window

The Nyquist Interpreter

In the "Nyquist Prompt" window, type into the text field a string "hello" with quotes:

Audacity Nyquist prompt window with quoted hello

If you click "OK", you should get a window displaying the word hello:

Window displaying the word hello

Click "OK" in the "hello" window to make it disappear again.

Congratulations, you just have learned how to send text messages to the user.

The Nyquist Debugger

After clicking "OK" in the "hello" window, click Effect > Nyquist Prompt again, but this time type the word hello without the quotes:

Audacity Nyquist prompt window with unquoted hello

Important: Now click "Debug" instead of "OK".

You should first get a window displaying a "Nyquist did not return audio" or similar message:

Window displaying Nyquist did not return audio

After clicking "OK" in the window above, a second window appears, displaying the detailed Nyquist error messages:

Window displaying Nyquist error: unbound variable

NOTE: The "Nyquist output" window only appears if you click "Debug" in the "Nyquist Prompt" window. If you click "OK", then, even with a Nyquist error, only the first window will appear.

Basic Nyquist Commands

The Nyquist manual relevant to audacity is available here Nyquist Reference Manual.

Audacity uses the 's' variable to reference the current audio file/selection. Thus you can use basic commands such as 'mult' or 'sum' with 's' and the Nyquist prompt will replace the file/selection with the result (or as Audacity calls it 'returned audio').

Simple Examples

NOTE: These examples are focused upon using Audacity to manipulate digital signals (clearly Audacity is better suited to audio, but features such as Nyquist can open other uses). For those interested, the signal used is a IR sample from a remote control.

Applying a DC offset to a signal:

Original Signal Original Signal before command.