;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;

;; 3D SOUND

;;

;; This example moves a sound around a 3d space.

;;

;; You will need to make sure you have enabled 

;; the multi-channel option in preferences before

;; you can try this example.

;; [also you need to restart after enabling multi-channel]                                         

;;

;; Use the "Apple MIDI Setup" application to configure

;; the speaker arrangement.  At this stage the 3d mixer

;; only supports stereo, quad or 5.0.  This needs to be

;; setup before you start Impromptu.  Also you need to make

;; sure that your multi-channel device is set as the

;; default output device.

;;

;; NOTE: once multi-channel is enabled

;; *au:output-node* represents the 3d mixer

;; instead of the usual HAL output audiounit. Look at the 

;; graph printout in the Log View for more detail.

;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(au:clear-graph)


(define inst0 (au:make-node "aumu" "dls " "appl"))

(define inst1 (au:make-node "aumu" "dls " "appl"))

(au:connect-node inst0 0 *au:output-node* 0)

(au:connect-node inst1 0 *au:output-node* 1)

(au:update-graph)

(au:print-graph)


(define ping

   (lambda (inst pitch)

      (play-note (now) inst pitch 80 4000)

      (callback (+ (now) 5000) 'ping inst pitch)))


(define move

   (lambda (azimath elevation distance channel)

      (let ((a (if (< azimath -180) 180 azimath))

            (e (if (< elevation -90) 90 elevation))

            (d (if (< distance -20.0) 20.0 distance)))

         (au:set-param (now) *au:output-node* 0 1 channel a)

         (au:set-param (now) *au:output-node* 1 1 channel e)

         (au:set-param (now) *au:output-node* 2 1 channel 2)

         (callback (+ (now) 2000) 'move (- a 1) (- e 1) (- d 0.05) channel))))


(move 180 90 20 0)

(move 0 0 5 1)

(ping inst0 78)

(ping inst1 79)


; For interests sake - too see the the parameters for the 3d mixer

; evaluate the line below.Notice that it uses *au:input-scope*

; rather than the more common *au:global-scope* argument. This is

; because all params for the 3d mixer are concerned with input, whereas

; most synthesizers and effects have global parmeters.

(au:print-params *au:output-node* *au:input-scope*)