Generate Custom Rhythmic Patterns in Audacity

Audacity includes Nyquist, a powerful Lisp-based audio programming language, which allows producers and sound designers to synthesize procedural audio and algorithmic rhythms directly on the timeline. While Audacity features a default "Rhythm Track" generator, using custom Nyquist scripts through the Nyquist Prompt enables you to create complex polyrhythms, step-sequenced triggers, and irregular Euclidean beat structures. This guide covers how to implement and run functional Nyquist scripts to generate custom rhythmic patterns.

How to Run Nyquist Scripts

To execute these scripts in Audacity:

  1. Open Audacity and create a new project.
  2. Navigate to Tools (or Effect in older versions) > Nyquist Prompt.
  3. Paste the chosen Nyquist code into the text field.
  4. Click Apply or OK to generate the audio pattern onto a new track.

1. List-Based Step Sequencer Script

This script operates like a classic 8-step sequencer. You define a binary pattern using 1 (trigger click) and 0 (rest). The script iterates through the list and places high-frequency, envelope-shaped pulses at precise intervals.

;; Simple Step Sequencer Pulse Generator
(defun make-pulse (freq dur)
  (mult (osc-pulse freq dur)
        (pwl 0.001 1 0.01 0.5 0.04 0 dur)))

;; Configuration: 1 = Hit, 0 = Rest
(setf pattern '(1 0 1 1 0 1 0 0))
(setf step-dur 0.125) ; 120 BPM sixteenth note (in seconds)
(setf out (s-rest 0))

;; Iterate through the sequence
(dotimes (step (length pattern))
  (when (= (nth step pattern) 1)
    (setf out (sim out 
                   (at (* step step-dur) 
                       (cue (make-pulse 1200 0.04)))))))
out

Customization: Adjust step-dur to change tempo (e.g., 0.15 for slower, 0.1 for faster) or alter the list in (setf pattern ...) to introduce custom syncopations.


2. Polyrhythmic Cross-Pulse Generator

Polyrhythms involve playing two contrasting rhythmic subdivisions simultaneously over the same total duration (such as 3 against 4). This Nyquist script calculates mathematically exact subdivisions across a fixed measure length.

;; Polyrhythm Generator (e.g., 3 against 4)
(defun click (pitch dur)
  (mult (hzosc pitch)
        (pwlv 1 dur 0)))

(setf measure-len 2.0) ; Total duration of the measure in seconds
(setf div-a 3)         ; 3-beat rhythm (Low tone)
(setf div-b 4)         ; 4-beat rhythm (High tone)

(setf layer-a (s-rest 0))
(setf layer-b (s-rest 0))

;; Generate First Subdivision
(dotimes (i div-a)
  (setf time (* i (/ measure-len div-a)))
  (setf layer-a (sim layer-a (at time (cue (click 440 0.03))))))

;; Generate Second Subdivision
(dotimes (i div-b)
  (setf time (* i (/ measure-len div-b)))
  (setf layer-b (sim layer-b (at time (cue (click 880 0.03))))))

;; Combine both layers
(sim layer-a layer-b)

Customization: Change div-a and div-b to any desired integers (such as 5 and 4 or 7 and 3) to produce complex metric overlays.


3. Accented Dynamic Beat Generator

To make synthetic patterns feel less robotic, dynamic volume envelopes and accented beats can be scripted. This Nyquist snippet generates a repeating four-bar grid with automated velocity variation on downbeats.

;; Accented 16th-Note Grid
(defun accented-click (freq amp)
  (mult amp 
        (hzosc freq)
        (pwlv 1 0.03 0)))

(setf total-steps 16)
(setf tempo-bpm 130.0)
(setf step-time (/ 60.0 (* tempo-bpm 4))) ; Sixteenth note duration
(setf output (s-rest 0))

(dotimes (i total-steps)
  (let ((t-pos (* i step-time)))
    (cond 
      ;; Downbeat (Beat 1, 5, 9, 13) gets a lower, louder click
      ((= (rem i 4) 0) 
       (setf output (sim output (at t-pos (cue (accented-click 300 0.9))))))
      ;; Off-beats get a quiet, higher frequency tick
      (t 
       (setf output (sim output (at t-pos (cue (accented-click 1500 0.25)))))))))

output

Customization: Change the conditions inside the cond block to place accents on specific subdivisions, such as swing patterns or backbeats on beats 2 and 4.