;; pat-fm-complex.sal -- more advanced example of pattern-based modulation ;; (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 ;; fast modulation creates a complex sound set durpat = make-product( make-copier( make-random({0.005 0.01 0.02 0.0025}, for: 1), repeat: 10), 1.0) set valpat = make-sum( make-copier( ; long-term changes make-accumulate( make-random( {-4 0 1 2 3 {-24 weight: 0.06}}), for: 1, min: -20, max: 20), repeat: make-product( make-random({1 2 3}), 20)), ; short-term changes for make-sum: make-heap({0 3 5 6 7 9})) play pat-fm(durpat, valpat, c4, 40)