;nyquist plug-in
;version 3
;type process
;categories "http://lv2plug.in/ns/lv2core#HighpassPlugin"
;name "Filter..."
;action "Applying Filter..."
;info "by Steve Daulton. Released under GPL v2.\n\nHigh-pass and Low-pass filters have just one filter frequency.\nHigh-pass filters attenuate frequencies below the specified frequency.\nLow-pass filters attenuate frequencies above the specified frequency.\n\nBand-pass and band-stop filters have two filter frequencies.\nBand-pass filters attenuate frequencies outside of the range of these two frequencies.\nBand-stop filters attenuate frequencies between these two frequencies.\n\nHigher roll-off values give a sharper attenuation of the cut frequencies.\nFilter frequencies must be less than 1/2 of the track sample rate."
;; hlbfilter.ny by Steve Daulton, June 2011.
;; Released under terms of the GNU General Public License version 2:
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html .
;; Minimum Audacity version 1.3.8
;control type "Filter type" choice "High-pass,Low-pass,Band-pass,Band-stop" 0
;control rolloff "Roll-off" choice " 6 dB per octave,12 dB per octave,24 dB per octave,36 dB per octave,48 dB per octave" 0
;control freq1 "First filter frequency (Hz)" real "" 1000 1 20000
;control freq2 "Second filter frequency (Hz)\n(only used with band filters)" real "" 1000 1 20000
(defun err ()
(format nil "Error.~%The track sample rate is ~a Hz.~%The filter frequency must be less than 1/2 the sample rate.~%" *sound-srate*))
(defun f1-err (Hz)
(format nil "The first filter frequency (~a Hz) is too high.~%" (truncate Hz)))
(defun f2-err (Hz)
(format nil "The second filter frequency (~a Hz) is too high.~%" (truncate Hz)))
(defun highpass (s-in Hz ro)
(if (>= Hz (/ *sound-srate* 2.0))
(strcat (err)(f1-err Hz))
(case ro
(0 (hp s-in Hz))
(1 (highpass2 s-in Hz))
(2 (highpass4 s-in Hz))
(3 (highpass6 s-in Hz))
(4 (highpass8 s-in Hz)))))
(defun lowpass (s-in Hz ro)
(if (>= Hz (/ *sound-srate* 2.0))
(strcat (err)(f1-err Hz))
(case ro
(0 (lp s-in Hz))
(1 (lowpass2 s-in Hz))
(2 (lowpass4 s-in Hz))
(3 (lowpass6 s-in Hz))
(4 (lowpass8 s-in Hz)))))
(defun bandpass (s-in Hz1 Hz2 ro)
(cond
((>= (max Hz1 Hz2)(/ *sound-srate* 2.0))
(strcat (err)
(if (>= Hz1 (/ *sound-srate* 2.0))(f1-err Hz1))
(if (>= Hz2 (/ *sound-srate* 2.0))(f2-err Hz2))))
(T (highpass(lowpass s-in(max Hz1 Hz2)ro)(min Hz1 Hz2)ro))))
(defun bandstop (s-in Hz1 Hz2 ro)
(cond
((>= (max Hz1 Hz2)(/ *sound-srate* 2.0))
(strcat (err)
(if (>= Hz1 (/ *sound-srate* 2.0))(f1-err Hz1))
(if (>= Hz2 (/ *sound-srate* 2.0))(f2-err Hz2))))
(T (sim (highpass s-in(max Hz1 Hz2)ro)(lowpass s-in(min Hz1 Hz2)ro)))))
(case type
(0 (highpass s freq1 rolloff))
(1 (lowpass s freq1 rolloff))
(2 (bandpass s freq1 freq2 rolloff))
(3 (bandstop s freq1 freq2 rolloff)))