From c96dbb11b09684db4e657b230549e1aba6d3ce3e Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Tue, 24 Feb 2026 14:57:29 +0100 Subject: [PATCH] - --- libao/libao.rkt | 68 +++++++++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/libao/libao.rkt b/libao/libao.rkt index 2925a3a..afe4a90 100644 --- a/libao/libao.rkt +++ b/libao/libao.rkt @@ -99,32 +99,50 @@ ))) (define (ao-close handle) - (displayln handle)(sleep 1.0) - (if (number? handle) - (let ((ao-device (hash-ref devices handle #f))) - (unless (eq? ao-device #f) - (let ((r (ao_close ao-device))) - (when (= r 0) - (printf "Unexpected: cannot close ao-device")))) - 'internally-closed) - (let ((handle-num (ao-handle-handle-num handle))) - (displayln (ao-handle-closed handle))(sleep 1.0) - (unless (ao-handle-closed handle) - (set-ao-handle-closed! handle #t) - (displayln "clear-async")(sleep 1.0) - (ao_clear_async (ao-handle-async-player handle)) - (displayln "stop-async")(sleep 1.0) - (ao_stop_async (ao-handle-async-player handle)) - (displayln "closing")(sleep 1.0) + + (define (close-device handle ao-device) + (if (eq? handle #f) + (begin + (if (eq? ao-device #f) + 'error-ao-device-non-existent + (let ((r (ao_close ao-device))) + (if (= r 0) + 'error-closing-ao-device + 'ok + ) + ) + ) + ) + (if (ao-handle-closed handle) + 'warning-ao-device-already-closed + (begin + (set-ao-handle-closed! handle #t) + ;(displayln "clear-async")(sleep 1.0) + (ao_clear_async (ao-handle-async-player handle)) + ;(displayln "stop-async")(sleep 1.0) + (ao_stop_async (ao-handle-async-player handle)) + ;(displayln "closing")(sleep 1.0) + (if (eq? ao-device #f) + 'error-ao-device-non-existent + (let ((r (ao_close ao-device))) + (if (= r 0) + 'error-closing-ao-device + 'ok))) + ) + ) + )) + + ;(displayln handle)(sleep 1.0) + (if (number? handle) + (let ((ao-device (hash-ref devices handle #f))) + (close-device #f ao-device)) + (let ((handle-num (ao-handle-handle-num handle))) + ;(displayln (ao-handle-closed handle))(sleep 1.0) (let ((ao-device (hash-ref devices handle-num #f))) - (if (eq? ao-device #f) - 'error-ao-device-non-existent - (let ((r (ao_close ao-device))) - (displayln "closed")(sleep 1.0) - (hash-remove! devices handle-num) - (if (= r 0) - 'error-closing-ao-device - 'ok)))))))) + (close-device handle ao-device)) + ) + ) + ) (define count 0)