Plaster

commonlisp
(defun normalize-wave-spec (wave) (etypecase wave (list wave) (number (list :frequency wave)) (function (list :function wave)))) (defun generate-wave (waves array sample-rate) (loop with div = (/ (length waves)) for spec in waves for wave = (normalize-wave-spec spec) for frequency = (getf wave :frequency 440) for function = (getf wave :function #'sine-wave) for amplitude = (min 1.0s0 (max 0.0s0 (getf wave :amplitude 1.0s0))) do (dotimes (i (length array)) (incf (aref array i) (* div amplitude (funcall function i frequency sample-rate))))))