Audacity Rocks!

April 28, 2014

Disclaimer: I’m no music producer (or audio engineer). But I’ve seen software wars for a lifetime. If your needs are more demanding, you can always go for Adobe Audition. Or Pro Tools. Or (the amazing) Reaper. I just happen to like open/free software, and Audacity is more than enough to fulfill my (simple) needs.

Last week, I needed to create some audio tracks for a very particular project, employing Amplitude Modulation (AM).

AM is fairly simple subject (despite the fact that I’m not a DSP expert). In my case, DSB-FC/DSB-WC was necessary to emulate classic/old radio broadcasting, using carrier signals in the kHz range. And sound in place of radio (former is mechanical, the latter is electromagnetic).

I won’t discuss the DSP specifics. There’s excellent material on Internet (make sure you check out Xiph.Org Foundation). I wanna talk about Audacity - a really good audio editor/recorder, portable, feature-rich, and free as in freedom (licensed under GPL).

Even though Audacity supports lots of effects (natively or from 3d-parties), I was not able to find an “AM” one that fitted. As a programmer, when facing situations like this, I always look for ways to improve/customize my software.

Audacity has scripting capabilities through Nyquist (a CMU Computer Music Project Software). This language is a superset of a Lisp dialect called XLISP. An imperative syntax (SAL) is also available, but I find it less attractive. The scripts can be deployed as menu options, and known effects are plugins of this nature.

What could be more cool than mixing Lisp, DSP, and plugin programming?! For those that enjoy Emacs (myself included), this is the geeky way to talk about software extensibility.

If you copy the trivial code below to a text file named DSBFC.ny, and place it in Audacity plugin folder, a new DSBFC entry will appear under Effect menu (its GUI is pretty minimal).

;nyquist plug-in
;version 3
;type process
;name "DSBFC..."
;action "Performing Amplitude Modulation..."
;control carrier "Carrier" real "Hz" 16000 150 27000

(defun dsbfc (sig)
  (mult 0.5 (sum 1 sig)(hzosc carrier)))

(multichan-expand #'dsbfc s)

alt effect menu

The code almost speaks for itself: single tone sinusoidal carrier wave has its amplitude modulated by the track.

I believe the first time I saw Nyquist multichan-expand technique (line 11) was in Audacity Forum (really recommended). It simplifies programming, cause a function is applied to each track channel, regardless of input type (stereo or mono).

DSBFC results have this “look”:

alt DSBFC result

Feel free to use the script, and tweak it to fit your needs. But watch out: there’s no error handling or hardening. And don’t forget the sampling theorem. Or aliasing. It’s not hard to neglect them, and work with inadequate parameters (e.g., incompatible sample-rates and carrier frequencies).