Audacity Dev
Githubaudacityteam.org
en - English (main)
en - English (main)
  • Audacity Dev resources
  • Getting started
    • BUILDING.md
    • Introduction to Audacity development
    • Codebase overview
    • Coding standards
      • Making Audacity Doxygenable
    • Strings & translatable code
  • Scripting
    • Developing your own plugins and scripts
    • Scripting reference
    • Creating your own Nyquist Plugins
      • Headers Reference
      • Plugin Reference
      • Widgets Reference
      • Basics
        • Delay Basics
        • Independent Stereo Volume Basics
        • Prompt Basics
        • Volume Basics
      • Tutorials
        • File Button Tutorial
        • Macro Tutorial
        • Property List Tutorial
        • Stereo Tracks Tutorial
        • The *SCRATCH* Symbol Tutorial
    • Creating custom themes
  • Refactoring
    • 4 steps to make an effect stateless
Powered by GitBook
On this page
Edit on GitHub
Export as PDF
  1. Scripting
  2. Creating your own Nyquist Plugins
  3. Tutorials

Stereo Tracks Tutorial

This tutorial provides a brief introduction to using stereo tracks in Nyquist programming.

If a sound from an Audacity stereo track was given to Nyquist, the *TRACK* variable contains an array of sounds. Because all Nyquist "snd-..." low-level functions only can process mono signals, to use such a function, the *TRACK* array first must be split into single mono signals and afterwards be re-combined into an array before it is given back to Audacity.

In Sal, one could write:

if arrayp(*track*) then
 return vector(snd-function(*track*[0]), snd-function(*track*[1]))
else
 return snd-function(*track*)

Or in LISP, one could write:

(if (arrayp *track*)
    (vector
        (snd-function (aref *track* 0))   ; left stereo channel
        (snd-function (aref *track* 1)))  ; right stereo channel
    (snd-function *track*))               ; mono signal
  • (arrayp *track*) - tests if '*track*' is an array

  • (vector ... ) - re-combines the two mono signals into a stereo signal. A "vector" is an one-dimensional array

  • (aref *track* 0) - the left stereo channel [the 0-th slot of the array]

  • (aref *track* 1) - the right stereo channel [the 1-st slot of the array]

Important: The Nyquist interface within Audacity can handle a maximum of two channels simultaneously [Audacity stereo tracks]. If in Audacity more than one audio track were selected, each of the selected tracks will be given sequentially, one after the other, with a maximum of two channels simultaneously [stereo] to Nyquist for processing. It is not possible with Nyquist in Audacity e.g. to copy audio signals from one Audacity track into another track.

multichan-expand

In the "nyquist.lsp" file in the Audacity "nyquist" sub-directory, there is a function "multichan-expand" defined, which simplifies the handling of multi-channel sounds [e.g. stereo tracks]:

(multichan-expand function &rest arguments)

So the "arrayp" constuct from above can also be written:

 return multichan-expand(quote(snd-function), *track*) ;; in SAL
 (multichan-expand #'snd-function *track*) ;; in LISP

This may look a bit more cryptic at first, but it can help to avoid long-winded audio processing functions.

PreviousProperty List TutorialNextThe *SCRATCH* Symbol Tutorial

Last updated 2 years ago