audacity-plugins/RANDOM-TONES.ny

39 lines
1.2 KiB
Common Lisp

;nyquist plug-in
;name "Random Tones..."
;type generate
;version 4
;author "dm"
;action "Generating Random Tones..."
;control seed "Random Seed" int "" 12532 1 134455
;control duration "Length (Seconds)" float "" 3 0 10
;control num-tones "Number of tones" int "" 15 1 100
;control middle "Center Frequency (Hz)" float-text "" 1000 0 20000
;control width "Width" float-text "" 1 0 20000
;control table-type "Table" choice "Sine,Saw,Square,Triangle" 0
;;;generate pseudorandom int between 1 and 134456
(defun rnd ()
(setq seed (rem (sum (mult 8121 seed) 28411) 134456)))
;;;generate pseudrandom float between 0 and 1
(defun rnd-scale ()
(/ (float (rnd)) 134456.0))
;;;generate pseudorandom (uniformly distributed) frequency within width of middle
(defun rnd-freq ()
(print (min (/ *sound-srate* 2.1)
(+ middle (* (- (rnd-scale) 0.5) width 2.0)))))
(defun gen-tone (hz-freq tbl)
(case tbl
(0 (sine (hz-to-step hz-freq)))
(1 (osc-saw hz-freq))
(2 (osc-pulse hz-freq 0.0))
(3 (osc-tri hz-freq))))
(stretch-abs duration
(do* ((tone 0 (incf tone))
(pch 1.0 (rnd-freq))
(result 0 (sum result (scale (rnd-scale) (gen-tone pch table-type)))))
((= tone num-tones) (scale (/ (float num-tones)) result))))