;; pwl-pat-fm.sal -- pattern modulation controlled by pwl functions ;; (c) 2008 by Roger B. Dannenberg ;; pat-ctrl is copied from pat-ctrl.sal ;; It creates a control function from a pattern define function pat-ctrl(durpat, valpat) return seq(const(next(valpat), next(durpat)), pat-ctrl(durpat, valpat)) ;; pat-fm is copied from pat-fm.sal ;; It creates a tone with duration and frequency controlled by patterns define function pat-fm(durpat, valpat, pitch, dur) begin with hz = step-to-hz( pitch + pat-ctrl(durpat, valpat)) return pwl(0.01, 1, dur - 0.1, 1, dur) * hzosc(hz + 4.0 * hz * hzosc(hz)) end ;; these pwl functions control the evolution of the pattern data define variable pitch-contour = pwl(10, 25, 15, 10, 20, 10, 22, 25, 22) define function get-pitch() return sref(pitch-contour, 0) define function pwl-pat-fm() begin with durpat = make-product( make-copier( make-random( {0.005 0.01 0.02 0.0025}, for: 1), repeat: 10), 1), valpat = make-sum( make-copier( ; long-term changes make-eval({get-pitch}), repeat: make-product( make-random({1 2 3}), 20)), ; short-term changes for make-sum make-heap({0 3 5 6 7})) return pat-fm(durpat, valpat, c4, 22) end ;; plot the contour so we can see it while we listen exec s-plot(pitch-contour, 1000, 22) play pwl-pat-fm()