2015-05-21 15:56:34 +00:00
|
|
|
;nyquist plug-in
|
2014-11-21 20:12:30 +00:00
|
|
|
;version 4
|
2015-12-26 19:26:39 +00:00
|
|
|
;type process spectral
|
2015-05-29 21:07:36 +00:00
|
|
|
;preview linear
|
2018-03-02 05:19:56 +00:00
|
|
|
$name (_"Spectral edit shelves")
|
2017-05-19 19:43:55 +00:00
|
|
|
;manpage "Spectral_edit_shelves"
|
2018-03-01 19:37:59 +00:00
|
|
|
$action (_"Filtering...")
|
2018-03-01 19:39:44 +00:00
|
|
|
$author (_"Paul Licameli")
|
2018-03-01 19:40:31 +00:00
|
|
|
$copyright (_"Released under terms of the GNU General Public License version 2")
|
2014-11-21 20:12:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
;; SpectralEditShelves.ny by Paul Licameli, November 2014.
|
2015-12-26 19:26:39 +00:00
|
|
|
;; Updated by Steve Daulton 2014 / 2015.
|
2014-11-21 20:12:30 +00:00
|
|
|
;; Released under terms of the GNU General Public License version 2:
|
|
|
|
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2014-10-18 14:19:38 +00:00
|
|
|
|
2018-03-01 19:44:39 +00:00
|
|
|
$control control-gain (_"Gain (dB)") real "" 0 -24 24
|
2014-10-18 14:19:38 +00:00
|
|
|
|
2015-02-02 01:46:34 +00:00
|
|
|
(defmacro validate (hz)
|
2015-12-26 19:26:39 +00:00
|
|
|
"If frequency is above Nyquist, don't use it"
|
|
|
|
`(if (or (>= ,hz (/ *sound-srate* 2.0))
|
|
|
|
(<= ,hz 0))
|
|
|
|
(setf ,hz nil)))
|
2015-02-02 01:46:34 +00:00
|
|
|
|
2014-10-18 14:19:38 +00:00
|
|
|
(defun mid-shelf (sig lf hf gain)
|
|
|
|
"Combines high shelf and low shelf filters"
|
2015-12-26 19:26:39 +00:00
|
|
|
(let ((invg (- gain)))
|
2014-10-18 14:19:38 +00:00
|
|
|
(scale (db-to-linear gain)
|
|
|
|
(eq-highshelf (eq-lowshelf sig lf invg)
|
|
|
|
hf invg))))
|
|
|
|
|
2015-02-02 01:46:34 +00:00
|
|
|
(defun wet (sig gain f0 f1)
|
2015-12-26 19:26:39 +00:00
|
|
|
"Apply appropriate filter"
|
2015-02-02 01:46:34 +00:00
|
|
|
(cond
|
2015-12-26 19:26:39 +00:00
|
|
|
((not f0) (eq-lowshelf sig f1 gain))
|
|
|
|
((not f1) (eq-highshelf sig f0 gain))
|
|
|
|
(t (mid-shelf sig f0 f1 gain))))
|
2014-10-18 14:19:38 +00:00
|
|
|
|
|
|
|
(defun result (sig)
|
|
|
|
(let*
|
2015-02-02 01:46:34 +00:00
|
|
|
((f0 (get '*selection* 'low-hz))
|
|
|
|
(f1 (get '*selection* 'high-hz))
|
|
|
|
(tn (truncate len))
|
2014-10-18 14:19:38 +00:00
|
|
|
(rate (snd-srate sig))
|
2014-11-21 20:12:30 +00:00
|
|
|
(transition (truncate (* 0.01 rate))) ; 10 ms
|
|
|
|
(t1 (min transition (/ tn 2))) ; fade in length (samples)
|
|
|
|
(t2 (max (- tn transition) (/ tn 2))) ; length before fade out (samples)
|
2014-10-18 14:19:38 +00:00
|
|
|
(breakpoints (list t1 1.0 t2 1.0 tn))
|
|
|
|
(env (snd-pwl 0.0 rate breakpoints)))
|
2015-02-02 01:46:34 +00:00
|
|
|
(cond
|
2015-12-26 19:26:39 +00:00
|
|
|
((not (or f0 f1)) ; This should never happen for a 'spectral' effect.
|
2018-03-01 19:52:26 +00:00
|
|
|
(throw 'error-message (format nil (_"~aPlease select frequencies.") p-err)))
|
2015-12-26 19:26:39 +00:00
|
|
|
((and f0 (>= f0 (/ *sound-srate* 2.0)))
|
|
|
|
; Shelf is above Nyquist frequency so do nothing.
|
|
|
|
nil)
|
|
|
|
((and f0 f1 (= f0 f1))
|
|
|
|
(throw 'error-message
|
2018-03-01 19:52:26 +00:00
|
|
|
(format nil (_"~aBandwidth is zero (the upper and lower~%~
|
2015-12-26 19:26:39 +00:00
|
|
|
frequencies are both ~a Hz).~%~
|
2018-03-01 19:52:26 +00:00
|
|
|
Please select a frequency range.")
|
2015-12-26 19:26:39 +00:00
|
|
|
p-err f0)))
|
|
|
|
(T (if f0 (validate f0))
|
|
|
|
(if f1 (validate f1))
|
|
|
|
(if (not (or f0 f1)) ; 'validate' may return nil
|
|
|
|
nil ; Do nothing
|
|
|
|
(sum (prod env (wet sig control-gain f0 f1))
|
|
|
|
(prod (diff 1.0 env) sig)))))))
|
2015-06-19 13:15:59 +00:00
|
|
|
|
2015-07-25 16:30:42 +00:00
|
|
|
(catch 'error-message
|
2018-03-02 13:59:13 +00:00
|
|
|
(setf p-err (format nil (_"Error.~%")))
|
2015-12-26 19:26:39 +00:00
|
|
|
(if (= control-gain 0)
|
|
|
|
nil ; Do nothing
|
|
|
|
(multichan-expand #'result *track*)))
|