Seemingly OK Code Not Applying To Audio

So I’m actually a programmer by trade, and I’ve dabbled in lisp about a year back. I had no idea Audacity had a Lisp flavor for me to play with. So I actually have a VLF antenna that I built that I eventually want to get around to using C and FFTW to live process the signal to remove mains hum. But I figured for now trying to do simple post dsp in audacity is good enough. It’s a simple matter of applying a notch filter across all the harmonics of 60hz, which should be as simple as running notch in a for loop. Now my lisp is really rusty since I never did get to play with lisp before, but I think this should be right?

;nyquist plug-in
;version 4
;type process
;name "Harmonics Removal"
(setq a 60)
(loop
	(notch2 *track* a 0.5)
	(setq a (+ a 60))
	(when (> a 20000) (return a)))

When I compile it, it runs without error (I hit the debug button and get no output, but as a C programmer I know well and good no compiler errors doesn’t mean no bugs) but nothing happens to my audio. Am I missing a step? Why is nothing happening to my audio? And yes before you ask I DO have audio selected. Nothing seems to work or be applied to my selected audio.

I tried Googling for what could be wrong and can’t find anything.
Any help is appreciated, thanks!

Your code “works” for me, but the result is probably not what you are expecting.

“a” in your code is an integer value.
When I run the code, it returns the integer value 20040. When Audacity receives a number or a string from Nyquist, Audacity creates a message window to display the value. In this case, the first multiple of 60 that is greater than 20000:

Nyquist returned the value: 20040

In order to filter the track, you need to return the filtered sound, not the value of “a”. The filtering is not performed as a “side effect”.

The other issue is that if you apply a notch filter every 60 Hz, there will not be much left.

I’ve modified your code to return the filtered audio. Note that the sound represented by the variable track is modified on every loop, and the result is returned.

;nyquist plug-in
;version 4
;type process
;name "Harmonics Removal"

(setq a 60)

(loop
  (setq *track* (notch2 *track* a 0.5))
  (setq a (+ a 60))
  (when (> a 20000)
    (return *track*)))

and the result when applied to white noise:

First Track000.png
If we use a very much higher “q”, and zoom in on the high frequency range (using the maximum window size in Spectrogram settings), we can see that the code is working correctly:

(setq a 60)

(loop
  (setq *track* (notch2 *track* a 80.0))
  (setq a (+ a 60))
  (when (> a 20000)
    (return *track*)))

First Track001.png
Not really important, but I’d use a DO loop rather than LOOP:

(do ((hz 60 (+ hz 60)))
    ((> hz 20000) *track*)
  (setf *track* (notch2 *track* hz 80.0)))

(and use spaces rather than tabs)