diff --git a/nyquist/dspprims.lsp b/nyquist/dspprims.lsp index 4015c8e59..c6750ee5a 100644 --- a/nyquist/dspprims.lsp +++ b/nyquist/dspprims.lsp @@ -306,13 +306,20 @@ ; remember that snd-biquad uses the opposite sign convention for a_i's ; than Matlab does. +; convenient biquad: normalize a0, and use zero initial conditions. ; convenient biquad: normalize a0, and use zero initial conditions. (defun nyq:biquad (x b0 b1 b2 a0 a1 a2) - (if (< a0 1.0) - (error (format t "a0 < 1 (unstable parameter) in biquad~%"))) + (if (<= a0 0.0) + (error (format nil "a0 < 0 (unstable parameter a0 = ~A) in biquad~%" a0))) (let ((a0r (/ 1.0 a0))) - (snd-biquad x (* a0r b0) (* a0r b1) (* a0r b2) - (* a0r a1) (* a0r a2) 0 0))) + (setf a1 (* a0r a1) + a2 (* a0r a2)) + (if (or (<= a2 -1.0) (<= (- 1.0 a2) (abs a1))) + (error (format nil + "(a2 <= -1) or (1 - a2 <= |a1|) (~A a1 = ~A, a2 = ~A) in biquad~%" + "unstable parameters" a1 a2))) + (snd-biquad x (* a0r b0) (* a0r b1) (* a0r b2) + a1 a2 0 0))) (defun biquad (x b0 b1 b2 a0 a1 a2) diff --git a/plug-ins/SpectralEditShelves.ny b/plug-ins/SpectralEditShelves.ny index 62b8ce6c3..ff6c4060a 100644 --- a/plug-ins/SpectralEditShelves.ny +++ b/plug-ins/SpectralEditShelves.ny @@ -30,12 +30,9 @@ (defun wet (sig gain f0 f1) (cond - ((not f0) ;low-shelf - (if (< f1 (/ *sound-srate* 2.0)) - (eq-lowshelf sig f1 gain) - (mult sig gain))) ;frequency above Nyquist so amplify full spectrum - ((not f1) (eq-highshelf sig f0 gain)) - (t (mid-shelf sig f0 (validate f1) gain)))) + ((not f0) (eq-lowshelf sig f1 gain)) + ((not f1) (eq-highshelf sig f0 gain)) + (t (mid-shelf sig f0 (validate f1) gain)))) (defun result (sig) (let* @@ -58,14 +55,23 @@ (T (sum (prod env (wet sig control-gain f0 f1)) (prod (diff 1.0 env) sig)))))) +;; Frequency selection must be between 0 Hz and Nyquist. +(if (and (get '*selection* 'low-hz) + (<= (get '*selection* 'low-hz) 0)) + (remprop '*selection* 'low-hz)) +(if (and (get '*selection* 'high-hz) + (>= (get '*selection* 'high-hz)(/ *sound-srate* 2))) + (remprop '*selection* 'high-hz)) + (cond ((not (get '*TRACK* 'VIEW)) ; 'View is NIL during Preview (setf p-err (format nil "This effect requires a frequency selection in the~%~ - 'Spectrogram' or 'Spectrogram (log f)' track view.~%~%")) + 'Spectral Selection' or 'Spectral Selection log(f)'~%~ + track view.~%~%")) (catch 'error-message (multichan-expand #'result *track*))) ((string-not-equal (get '*TRACK* 'VIEW) "spectral" :end1 8 :end2 8) - "Use this effect in the 'Spectral Selection'\nor 'Spectral Selection log(f)' view.") + "Use this effect in the 'Spectral Selection'\nor 'Spectral Selection log(f)' view.") (T (setf p-err "") (if (= control-gain 0) ; Allow dry preview "Gain is zero. Nothing to do."