; function to make a table (defun mkwave () (setf *mytable* (simrep (i 30) (scale (/ 0.5 (+ i 1)) (build-harmonic (+ i 1) 2048)))) (setf *mytable* (list *mytable* (hz-to-step 1) T))) ; create the table now (mkwave) ; take a look at it: (defun plot-table (table) (setf table (car table)) (s-plot (force-srate (/ 600 (/ (snd-length table 100000) (snd-srate table))) table))) ; try it out (play (osc c3 2.0 *mytable*)) ; try a more sustained envelope: (defun sus-tone () (mult (pwl .05 1 .8 .7 1) (osc c3 1 *mytable*))) ; play it (play (sus-tone)) ; try same thing with a lp filter: (defun lp-tone () (lp (sus-tone) (pwl 0.1 5000 0.2 1000 0.5 500 1))) (play (stretch 2 (lp-tone))) ; resonating filter: (defun res-tone () (reson (sus-tone) (pwl 0.1 5000 0.2 1000 0.5 500 1) ;center 500 ; bandwidth 1)) ; normalization (defun res-tone () (reson (noise) (pwl 0.1 5000 0.2 1000 0.5 500 1) ;center 500 ; bandwidth 1)) ; normalization ;; FM examples ; modulator envelope (corresponds to I(t)) (defun mod-env () (pwl .2 500 1)) ; the modulator (corresponds to I(t)sin(fm*t), where ; fm is the modulator frequency) (defun fm-mod (p) (mult (mod-env) (osc p))) ; the carrier envelope (corresponds to A(t)) (defun car-env () (pwl .1 1 1)) ; the FM sound: A(t)sin(fc + I(t)sin(fm*t)) (defun fm1 (p) (mult (car-env) (fmosc p (fm-mod p)))) (play (fm1 c4)) (play (stretch 5 (fm1 c4))) ;; try higher index of modulation: (defun mod-env () (pwl .2 2000 1)) (play (stretch 5 (fm1 c4))) ;; try non-integer carrier/modulation ratio (defun fm-mod (p) (mult (mod-env) (osc (+ p 3.1)))) ;; try odd modulation/carrier ratio (defun up3 (p) (hz-to-step (* 3.0 (step-to-hz p)))) (defun mod-env () (pwl .2 1300 1)) (defun fm-mod (p) (mult (mod-env) (osc (up3 p)))) (play (stretch 2 (fm1 c4))) ; homework ; create a plucked string-like sound with FM ; make a cool sound with FM