;Jesse Fox / Music 220a, HW#5 / 11/23/04 ;Recreation of the THX "Deep Note" ;Usage: ;snd -l cm-session.scm & ;(load "deepnote.scm") ;-------------------------------------- (definstrument (partial start dur frequency freqskew amplitude freq-envelope amp-envelope) (let* ((gls-env (make-env :envelope freq-envelope :scaler (hz->radians freqskew) :duration dur)) (os (make-oscil :frequency frequency)) (amp-env (make-env :envelope amp-envelope :scaler amplitude :duration dur)) (len (inexact->exact (round (* (mus-srate) dur)))) (beg (inexact->exact (round (* (mus-srate) start)))) (end (+ beg len))) (ws-interrupt?) ;; catch g interrupt from user ;; see http://ccrma.stanford.edu/software/snd/snd/sndscm.html (run (lambda () (do ((j beg (1+ j))) ((= j end)) (outa j (* (env amp-env) (oscil os (env gls-env))) *output* )))))) ;define a frequency envelope that follows a pseudo-'hyperbolic tangent' path (define freq_env '(.00 1.00 0.09 0.98 0.12 0.97 0.15 0.96 0.18 0.94 0.21 0.91 0.24 0.88 0.27 0.83 0.3 0.76 0.33 0.69 0.36 0.59 0.39 0.5 0.42 0.4 0.45 0.31 0.48 0.23 0.51 0.16 0.54 0.11 0.57 0.08 0.6 0.05 0.63 0.03 0.69 0.02 0.72 0.01 0.75 .0 1.0 .0)) ;define an amplitude envelope that fades in and out at beginning and end (define amp_env '(.00 .00 .01 .5 .5 .7 .75 .9 0.95 0.9 1.0 .0)) (defobject simp () ((ins :initform 'partial :accessor object-name) (beg :accessor object-time) (dur :initform 1) (freq :initform 440) (skew :initform 10) (amp :initform .5) (freq_envelope :initform freq_env) (amp_envelope :initform amp_env) ) (:parameters beg dur freq skew amp freq_envelope amp_envelope)) (define (deepnote num) (process repeat num ;generate a random starting pitch between MIDI notes 20 and 107 for startfreq = (hertz (between 20 107 )) ;generate a random number between 0 and 25 as a multiplier for endfreqs for fund = (random 25.0) ;calculate ending pitches for endfreq = (cond ;generate the base triad of ending pitches (F Maj) ((< fund 1)(hertz 'f1)) ((< fund 2)(hertz 'a1)) ((< fund 3)(hertz 'c1)) ;generate upper triads ((< fund 4)(hertz 'f2)) ((< fund 5)(hertz 'f3)) ((< fund 6)(hertz 'f4)) ((< fund 7)(hertz 'f5)) ((< fund 8)(hertz 'f6)) ((< fund 9)(hertz 'f7)) ((< fund 10)(hertz 'f8)) ((< fund 11)(hertz 'f9)) ((< fund 12)(hertz 'a2)) ((< fund 12)(hertz 'a3)) ((< fund 13)(hertz 'a4)) ((< fund 14)(hertz 'a5)) ((< fund 15)(hertz 'a6)) ((< fund 16)(hertz 'a7)) ((< fund 17)(hertz 'a8)) ((< fund 18)(hertz 'a9)) ((< fund 19)(hertz 'c2)) ((< fund 20)(hertz 'c3)) ((< fund 21)(hertz 'c4)) ((< fund 22)(hertz 'c5)) ((< fund 23)(hertz 'c6)) ((< fund 24)(hertz 'c7)) ((< fund 25)(hertz 'c8)) (else (hertz 'c9))) ;"turn down" the volume relative to pitch (apply a 1/f amplitude rule) for amps = (cond ((< fund 1)(/ 1.0 (hertz 'f1))) ((< fund 2)(/ 1.0 (hertz 'a1))) ((< fund 3)(/ 1.0 (hertz 'c1))) ((< fund 4)(/ 1.0 (hertz 'f2))) ((< fund 5)(/ 1.0 (hertz 'f3))) ((< fund 6)(/ 1.0 (hertz 'f4))) ((< fund 7)(/ 1.0 (hertz 'f5))) ((< fund 8)(/ 1.0 (hertz 'f6))) ((< fund 9)(/ 1.0 (hertz 'f7))) ((< fund 10)(/ 1.0 (hertz 'f8))) ((< fund 11)(/ 1.0 (hertz 'f9))) ((< fund 12)(/ 1.0 (hertz 'a2))) ((< fund 12)(/ 1.0 (hertz 'a3))) ((< fund 13)(/ 1.0 (hertz 'a4))) ((< fund 14)(/ 1.0 (hertz 'a5))) ((< fund 15)(/ 1.0 (hertz 'a6))) ((< fund 16)(/ 1.0 (hertz 'a7))) ((< fund 17)(/ 1.0 (hertz 'a8))) ((< fund 18)(/ 1.0 (hertz 'a9))) ((< fund 19)(/ 1.0 (hertz 'c2))) ((< fund 20)(/ 1.0 (hertz 'c3))) ((< fund 21)(/ 1.0 (hertz 'c4))) ((< fund 22)(/ 1.0 (hertz 'c5))) ((< fund 23)(/ 1.0 (hertz 'c6))) ((< fund 24)(/ 1.0 (hertz 'c7))) ((< fund 25)(/ 1.0 (hertz 'c8))) (else (/ 1.0 (hertz 'c9)))) output(new simp :beg 0 :dur 17 :freq endfreq :skew (- startfreq endfreq) :amp amps))) ;set number of oscillators as second arg here (synth (deepnote 500))