;nyquist plug-in
;version 1
;type process
;categories "http://lv2plug.in/ns/lv2core/#DynamicsPlugin"
;name "Peak Processor v.0.2..."
;action "processing peaks..."
;info "By Steve Daulton (www.easyspacepro.com). Released under GPL v2.\nNon-linear expansion/compression of peaks.\nPositive values are NOT the inverse of negative values.\n"
;control thresh "Threshold" real "linear" 0.5 0 1.0
;control ratio "Ratio [Compress]" real "[Expand]" 0 -10 10
;; peakprocess.ny by Steve Daulton, January 2011
;; Released under terms of the GNU General Public License version 2
;; http://www.gnu.org/copyleft/gpl.html
(setq ratio (if (> ratio 0)(mult 2.0 ratio)(float ratio)))
(defun expansion (s-in val)
(let ((pos (s-max 0 s-in))
(neg (mult -1 (s-min 0 s-in))))
(sim
(mult (/ val)(sum -1 (s-exp (mult val pos))))
(mult (/ -1 val)(sum -1 (snd-exp (mult val neg)))))))
(let* ((nthresh (* -1 thresh))
(tops (s-max s thresh))
(mids (s-max (s-min s thresh) nthresh))
(bottoms (s-min s nthresh)))
(sim mids
(expansion (sum (mult -1 thresh) tops) ratio)
(expansion (sum thresh bottoms) ratio)))