audacity-plugins/NOISEMODULATION.ny

66 lines
2.0 KiB
Plaintext
Raw Normal View History

2024-05-03 02:00:39 +00:00
;nyquist plug-in
;version 4
;type process
;preview linear
;name "Noise Modulation..."
;action "Modulating..."
;author "dm"
;control mixes-str "Wet-Dry Mix List" string "" "0.5 0 1"
;control width-str "Passband Width" string "" "100 300 0"
;control lp-iterations "Stopband Attenuation" int "" 5 0 15
;--- GLOBAL VARIABLES
;--- PREPARE INPUT
(defun cast-nonnegative-float (element)
(cond
((floatp element) (abs element))
((integerp element) (float (abs element)))
(T 0.0)))
(defun list-to-floats (input-list)
(mapcar #'cast-nonnegative-float input-list))
;;;stole this one from David R. Sky's Sequencer 2.
(defun string-to-list (string)
(read (make-string-input-stream (format nil "(~a)" string))))
;;;add some validation to these functions at some point
(defun process-string (string)
(list-to-floats (string-to-list string)))
;;; COMPUTE SOUND
;;;this should be written better
(defun gen-envelope (inlist &optional (cutoff (/ *control-srate* 2.1)))
(if (= 1 (length inlist))
(const (car inlist) 1.0)
(lowpass6 (pwlvr-list (reverse (cdr
(do* ((ylist inlist (cdr ylist))
(height (car ylist) (car ylist))
(interval (/ (- (length ylist) 1.0)))
(bp-list (list interval height)
(cons interval (cons height bp-list))))
((null (cdr ylist)) bp-list)))))
cutoff)))
(defun iterate-lp (signal cutoff iterations)
(if (zerop iterations) signal
(iterate-lp (lp signal cutoff) cutoff (- iterations 1))))
(defun gen-noise (widths)
(let ((cutoff (gen-envelope widths)))
(iterate-lp (noise 1) cutoff lp-iterations)))
(defun normalize (signal)
(let ((x (/ 0.95 (peak signal ny:all))))
(setq signal (scale x signal))))
(let* ((modulator (gen-noise (process-string width-str)))
(wet-env (gen-envelope (process-string mixes-str)))
(dry-env (diff 1.0 wet-env))
(raw (normalize *TRACK*))
(dry (mult dry-env raw))
(wet (mult wet-env modulator raw)))
(normalize (sum dry wet)))