Modernizing an old plugin

Hi all,

Anyone got any ideas on how to modernize this old plugin that seems to have been forgotten about over the years?

;nyquist plug-in
;version 3
;type process
;name "Median Filter..."
;action "Filtering..."
;info "by Robert J. Haenggi.\nReleased under GPL v2.\n"
;; rjh-median.ny by Robert Haenggi October   2013
;; Released under terms of the GNU General Public License version 2:
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
;; Plug-in version 1.0
;; requires Audacity 1.3.12 or later, developed under Audacity 2.0.5
;;
;control width "Window Size (Samples)" int "" 5 1 199
;control p% "Percentile (50 = Median)" int "Percent" 50 1 100

;;
(setf filter-class (send class :new '(s1 win percentile) '(histo)))
(send filter-class :answer :next '()
  '((let ((val (nth (truncate (* percentile 0.01 win))
                    (sort (remove "" histo) '>)))
         (val-new (snd-fetch s1))) 
   (cond (val-new
             (pop histo)
             (setf histo (append histo (list val-new)))
             val)
          (t nil)))))
(send filter-class :answer :isnew '(snd w p) 
  '((setf s1 (let ((sr (snd-srate snd))) (seq snd (snd-const  0 0 sr (/ 1 sr 2)))))
    (setf win w)
    (setf percentile (min 100 (abs p))) 
    (setf histo (let ((n0 (snd-fetch s1))) 
              (dotimes (i win h) (setf h (cons n0 h)))))))
(defun snd-median (s-in win &optional (percentile 50))
  (let (obj)
   (setf obj (send filter-class :new s-in win percentile))
   (snd-fromobject (snd-t0 s-in) (snd-srate s-in) obj)))
(multichan-expand #'snd-median s width p%)

I can make it “compatible” by changing line 2 to ;version 4 and the “s” in the last line to track
However, it gives a warning and does nothing:
warning.png

What does it do?

Koz

If you post to the page where you found that plug-in, Robert may be subscribed to the page and see your post. (Robert is still around, but doesn’t visit the forum very frequently).

Try applying the un-modified code to white noise. You will still get the warning, but should be able to see that it is doing something. Use “Plot Spectrum” to see what it is doing.


To fix the warning, change the “:isnew” method to:

(send filter-class :answer :isnew '(snd w p) 
  '((setf s1
        (let ((sr (snd-srate snd)))
          (seq snd (cue (snd-const  0 0 sr (/ 1 sr 2))))))
    (setf win w)
    (setf percentile (min 100 (abs p))) 
    (setf histo (let ((n0 (snd-fetch s1)))
              (dotimes (i win h) (setf h (cons n0 h)))))))

Hi Steve and Koz,

Sorry that I took so long to respond, had to find the link to that post.
What I do to learn Nyquist, I collect whatever plugins people have written and then go through them, try them out and edit them to better understand.
I normally also keep the url, but in this case, must have forgotten.

Anyways, here it is:

The direct link to the plugin:

http://forum.audacityteam.org/download/file.php?id=8679

Steve, thanks for the suggested change, will try it out.

I think that technically there’s another error in the :isnew method. It does not affect how the code runs, but “h” has not been defined when it is first used, so it defaults to the value 2.0 (See: https://www.cs.cmu.edu/~rbd/doc/nyquist/part2.html#index59).

To be technically correct, I think “h” should be initialised as an empty list (or NIL), as here:

(send filter-class :answer :isnew '(snd w p) 
  '((setf s1
        (let ((sr (snd-srate snd)))
          (seq snd (cue (snd-const  0 0 sr (/ 1 sr 2))))))
    (setf win w)
    (setf percentile (min 100 (abs p))) 
    (setf histo (let ((n0 (snd-fetch s1))
                      (h ()))
              (dotimes (i win h)
                (setf h (cons n0 h)))))))

Haa, that new mod is perfect, many thanks Steve.

There should be a book to teach people about Nyquist and Xlisp.
It could be titled:
“Learn Nyquist & Xlisp in 21 years”. :smiley:

That’s how long it feels like it’s going to take me.

Seriously though, have you ever though about making Youtube videos about this stuff?
Maybe something along the lines of, DSP theory and examples using Audacity and Xlisp.

I did have blog for Audacity/Nyquist stuff, but the perpetual problem of too little time got in the way. I may resurrect it if I can find the time.

Fair enough.
Please do post on this forum if you find some free time again to continue.