anchor.diff:    (:export #:sound-card
              #:register-sound-card
              #:sound-card-run
  +           #:master-volume
              #:make-sound-output-sink
  -           #:output-sound))
  +           #:sink-volume
  +           #:output-sound
  +           #:flush-sink))
   
   (in-package :mezzano.driver.sound)
   
  
positive.code:   (push device *cards*)
    (mezzano.supervisor:make-thread
     (lambda () (sound-worker device))
     :name (format nil "Sound worker for ~S" device)))
  
  (defun make-sound-output-sink (&key (buffer-duration 0.1) (volume 1.0))
    (make-instance 'sound-output-sink
                   :volume volume
                   ;; 100ms at 44.1khz, 2 channels.
                   :buffer (make-array (* (truncate (* 44100 buffer-duration)) 2)
                                       :element-type 'single-float)
                   :buffer-empty t
  
negative.code:    (%buffer-empty :initarg :buffer-empty :accessor buffer-empty)
     (%buffer-head :initarg :buffer-head :accessor buffer-head)
     (%buffer-tail :initarg :buffer-tail :accessor buffer-tail)
     (%format :initarg :format :accessor sink-format)
     (%volume :initarg :volume :accessor sink-volume)))
  
  (defmethod (setf sink-volume) :around (value (sink sound-output-sink))
    (check-type value single-float)
    (call-next-method))
  
  (defvar *cards* '())
  
  