-
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
(require "libao-ffi.rkt"
|
||||
(prefix-in fin: finalizer)
|
||||
ffi/unsafe)
|
||||
ffi/unsafe
|
||||
data/queue
|
||||
)
|
||||
|
||||
(provide ao-open-live
|
||||
ao-play
|
||||
@@ -21,6 +23,8 @@
|
||||
[byte-format #:auto #:mutable]
|
||||
[channels #:auto #:mutable]
|
||||
[rate #:auto #:mutable]
|
||||
[buffer #:auto #:mutable]
|
||||
[player #:auto #:mutable]
|
||||
)
|
||||
#:auto-value #f
|
||||
)
|
||||
@@ -80,6 +84,36 @@
|
||||
(set-ao-handle-byte-format! handle endianness)
|
||||
(set-ao-handle-rate! handle rate)
|
||||
(set-ao-handle-channels! handle channels)
|
||||
(let ((buf (make-queue)))
|
||||
(set-ao-handle-buffer! handle buf)
|
||||
(set-ao-handle-player! handle
|
||||
(thread (λ ()
|
||||
(let ((samples-per-time 10)
|
||||
(sample 0)
|
||||
)
|
||||
(define (play)
|
||||
(displayln (format "Queue-length: ~a" (queue-length buf)))
|
||||
(if (queue-empty? buf)
|
||||
(begin
|
||||
(sleep 0.1)
|
||||
(play))
|
||||
(let ((front (dequeue! buf)))
|
||||
(if (eq? (car front) 'close)
|
||||
'closed
|
||||
(let ((audio (cadr front))
|
||||
(audio-buf-len (caddr front)))
|
||||
(ao_play ao-device audio audio-buf-len)
|
||||
(play))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(play))
|
||||
)
|
||||
#:pool 'own
|
||||
)
|
||||
)
|
||||
)
|
||||
(hash-set! devices handle-num ao-device)
|
||||
(fin:register-finalizer handle
|
||||
(lambda (handle)
|
||||
@@ -97,6 +131,15 @@
|
||||
(printf "Unexpected: cannot close ao-device"))))
|
||||
'internally-closed)
|
||||
(let ((handle-num (ao-handle-handle-num handle)))
|
||||
(let ((q (ao-handle-buffer handle)))
|
||||
(letrec ((emptier (λ () (if (queue-empty? q)
|
||||
'done
|
||||
(begin
|
||||
(dequeue! q)
|
||||
(emptier))))))
|
||||
(emptier)
|
||||
(enqueue! q (list 'close #f #f))
|
||||
))
|
||||
(let ((ao-device (hash-ref devices handle-num #f)))
|
||||
(if (eq? ao-device #f)
|
||||
'error-ao-device-non-existent
|
||||
@@ -152,11 +195,16 @@
|
||||
'filled))
|
||||
))
|
||||
(fill 0 0)
|
||||
(let* ((handle-num (ao-handle-handle-num handle))
|
||||
(ao-device (hash-ref devices handle-num #f)))
|
||||
(if (eq? ao-device #f)
|
||||
(error "No device for this handle")
|
||||
(ao_play ao-device audio audio-buf-len))))))
|
||||
(enqueue! (ao-handle-buffer handle) (list 'play-buf audio audio-buf-len))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;(let* ((handle-num (ao-handle-handle-num handle))
|
||||
; (ao-device (hash-ref devices handle-num #f)))
|
||||
; (if (eq? ao-device #f)
|
||||
; (error "No device for this handle")
|
||||
; (ao_play ao-device audio audio-buf-len))))))
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user