(new) (defun midi2hz (x) (* 440 (expt 2 (/ (- x 69) 12)))) (defvar my-plate) (setq my-plate (make-object 'rect-plate (thickness 0.3) (modes 160) (density 9000) (young 1.04e11) (freq-loss 0.8) (const-loss 0.5))) (set-pitch my-plate 'size (midi2hz 48)) (defvar my-membrane) (setq my-membrane (make-object 'rect-membrane (modes 400) (length0 .25) (length1 .25) (tension 5000) (freq-loss .1) (const-loss .1))) (set-pitch my-membrane 'tension (midi2hz 60)) (defvar my-plate-hit) (setq my-plate-hit (make-access my-plate (const .4 .4) 'normal)) (defvar my-membrane-hit) (setq my-membrane-hit (make-access my-membrane (const .2 .3) 'normal)) (defvar my-plate-out) (setq my-plate-out (make-access my-plate (const .9 .7) 'normal)) (defvar my-membrane-out) (setq my-membrane-out (make-access my-membrane (const .8 .9) 'normal)) (defvar hybrid-env) (setq hybrid-env (make-controller 'envelope 1 (list (list 0.0 0.0) (list 1.0 0.9)))) (defvar my-hybrid) (setq my-hybrid (make-object 'melt-hybrid my-plate my-membrane hybrid-env)) (defvar my-hammer) (setq my-hammer (make-object 'bi-two-mass (stiffness0 200000) (stiffness1 200000))) (defvar my-hybrid-hit) (setq my-hybrid-hit (make-access-hybrid my-hybrid my-plate-hit my-membrane-hit)) (defvar my-hammer-hit) (setq my-hammer-hit (make-access my-hammer (const 0) 'trans0)) (make-connection 'strike my-hammer-hit 0.001 my-hybrid-hit 0) (defvar heavyside) (setq heavyside (make-controller 'dynamic 1 -1 0 "step")) (defvar dt) (setq dt (const (get-info 'sample-period))) (defvar force) (setq force (make-controller 'arithmetic 1 '- (list heavyside (make-controller 'delay 1 dt heavyside)))) (defvar my-hammer-drive) (setq my-hammer-drive (make-access my-hammer (const 1) 'trans0)) (make-connection 'force my-hammer-drive force) (defvar strike-count) (setq strike-count 10) (defvar strike-speed) (setq strike-speed (make-controller 'envelope 1 (list (list 0.0 .1) (list 1.6 1)))) (defvar striker) (setq striker (make-controller 'foreign-call 0 .2 (lambda (ins out) (declare (ignore out)) (if (> strike-count 0) (let ((m (get-info 'mass my-hammer)) (dt (vget ins 2 0))) (format t "Starting another strike...~%") (reset-objects-dynamics my-hammer) (send-message "step" (- (vget ins 0 0) (* m (vget ins 1 0) (/ 1 dt)))) (decf strike-count)))) (list heavyside strike-speed dt))) (defvar my-hybrid-out) (setq my-hybrid-out (make-access-hybrid my-hybrid my-plate-out my-membrane-out)) (make-point-output my-hybrid-out 0 (make-controller 'envelope 1 '((0 1)(4.5 1)(5 0)))) (run 5) (play)