(define-macro new-22k-mono               ; convenience macro for new soundfile
  (lambda (filename)
    `(new-sound ,filename mus-riff mus-lshort 22050 1))); backquote comma ex.

(define-macro new-22k-stereo               ; convenience macro for new soundfile
  (lambda (filename)
    `(new-sound ,filename mus-riff mus-lshort 22050 2))); backquote comma ex.

(begin
  (define 16bits (expt 2 16)) ; need to define some constants for dynamic range
  (define 15bits (expt 2 15))
  (define one-over-15bits (/ 1.0 15bits))

  (define random-sample ; procedure that returns properly scaled random number
    (lambda ()
      (* (- (random 16bits) 15bits) one-over-15bits)))
  (define noise         ; procedure to spew random samples
    (lambda* (beg dur #&optional (amp 1.0))
      (let* ((start (floor (* beg (srate))))
      (len (floor (* dur (srate))))
      (out-data (make-vct len)))
        (vct-map! out-data (lambda ()
        (* amp (random-sample))
        ))
        (vct->samples start len out-data))))
  )
(define click
  (lambda* (beg dur #&optional (i2 #f) (amp 1) (i1 900))
    (let* ((start (floor (* beg (srate))))
    (len (floor (* dur (srate))))
    (t2 (if (number? i2) (+ i1 i2) #f))
    (out-data (make-vct len)))
      (vct-do! out-data (lambda (i)
     (if (= i i1) amp (if (and t2 (= i t2)) (- 0.0 amp) 0.0))
     ))
      (vct->samples start len out-data))))
(new-22k-stereo "/zap/test.wav")                        ; new soundfile
(load "/usr/ccrma/lisp/src/snd/loop.scm")