code_1.sal -- for in-class demonstration, week 1, day 2 Roger Dannenberg and Tom Cortina, 2009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; PART 1 -- Using the SAL Interpreter ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Show how to get from XLISP prompt to SAL prompt ;; (Click on SAL or Lisp button in IDE) ;; type these by hand into the SAL input window: print "hello world" ; this is a comment ;; enter these directly to SAL (select and ^U) print 123 print 123.45 print #t ; #t is SAL-speak for "true", #f is false print a-lisp-symbol set a = 1, b = 2 print a + b ; note spaces around "+" print a+b ; a+b is an unbound variable(!) ;; things to show in class... ;; - Visit Nyquist's Manual on the web or a local copy. ;; - Find the index. ;; - Figure out how to concatenate two strings. ;; - Figure out how to compute a random number in [0...99] ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; PART 2 -- SAL Examples ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; call some functions (evaluate these by selecting and ^U) print numberp(10) print "step", a4, "hz", step-to-hz(a4) print "1000hz in steps", hz-to-step(1000.0), "b5", b5 define function simple-fn(a) begin display "simple-fn", a return a + 1 end print simple-fn(20) play pluck(c3) play pluck(c3) ~ 3 define function pluck-chord(pitch, interval, n) begin with s = pluck(pitch) loop for i from 1 below n set s += pluck(pitch + interval * i) end return s end play pluck-chord(c3, 5, 2) play pluck-chord(d3, 7, 4) ~ 3 play pluck-chord(c2, 10, 7) ~ 8 load "pianosyn" ; load piano synthesizer code play piano-note(5, fs1, 100) play osc(c4) play noise() play lp(noise(), 1000.0) play lp(noise(), env(0.1, 0.1, 0.1, 100.0, 200.0, 2000.0, 1.0)) play reson(0.005 * noise(), 500.0, 20.0) play reson(0.05 * noise(), env(0.1, 0.1, 0.1, 100, 200, 1000, 1.0), 20.0) play osc(c4) * osc(d3) play noise() * env(0.05, 0.1, 0.5, 1.0, 0.5, 0.4)