From b14e6e3fca8903a2e06b46a593378cf8ed78b8fd Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Wed, 25 Feb 2026 00:43:00 +0100 Subject: [PATCH] - --- lib/dll/ao-play-async.dll | Bin 11776 -> 11776 bytes libao/libao-async.rkt | 16 +++++++-- libao/libao.rkt | 66 ++++++++++++++++++++++++++++---------- 3 files changed, 63 insertions(+), 19 deletions(-) diff --git a/lib/dll/ao-play-async.dll b/lib/dll/ao-play-async.dll index 00a6fbc9cf4a6442cc218db289940e467def4d99..d352bd47a813bbb0150c0108e9937e669e040531 100644 GIT binary patch delta 25 dcmZpOX^7dt!N{z}IBzpI<45dd&V2( (queue-length q) 0) + (let* ((elem (dequeue! q)) + (buf (cadddr elem))) + (free buf)))) + (set-ao-shm-queue! shm (make-queue)) + (set-ao-shm-bufsize! shm 0) + ) + diff --git a/libao/libao.rkt b/libao/libao.rkt index 3fe56b1..2ccaf7d 100644 --- a/libao/libao.rkt +++ b/libao/libao.rkt @@ -1,9 +1,11 @@ #lang racket/base +(define libao-async-mode 'ffi) ; 'ffi or 'scheme + (require "libao-ffi.rkt" - "libao-async-ffi.rkt" - ;"libao-async.rkt" (prefix-in fin: finalizer) + (prefix-in ffi: "libao-async-ffi.rkt") + (prefix-in scm: "libao-async.rkt") ffi/unsafe data/queue ) @@ -16,11 +18,21 @@ ao-at-second ao-bufsize-async ao-clear-async + ao-set-async-mode! + ao-async-mode ) (define devices (make-hash)) (define device-number 1) +(define (ao-set-async-mode! mode) + (if (or (eq? mode 'ffi) (eq? mode 'scheme)) + (set! libao-async-mode mode) + (error "mode must be 'ffi or 'scheme")) + mode) + +(define (ao-async-mode) + libao-async-mode) (define-struct ao-handle (handle-num [bits #:auto #:mutable] @@ -89,7 +101,9 @@ (set-ao-handle-byte-format! handle endianness) (set-ao-handle-rate! handle rate) (set-ao-handle-channels! handle channels) - (set-ao-handle-async-player! handle (ao_create_async ao-device ao_play_ptr)) + (if (eq? libao-async-mode 'ffi) + (set-ao-handle-async-player! handle (ffi:ao_create_async ao-device ao_play_ptr)) + (set-ao-handle-async-player! handle (scm:ao_create_async ao-device))) (hash-set! devices handle-num ao-device) (fin:register-finalizer handle (lambda (handle) @@ -117,11 +131,15 @@ '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? libao-async-mode 'ffi) + (begin + (ffi:ao_clear_async (ao-handle-async-player handle)) + (ffi:ao_stop_async (ao-handle-async-player handle)) + ) + (begin + (scm:ao_clear_async (ao-handle-async-player handle)) + (scm:ao_stop_async (ao-handle-async-player handle)) + )) (if (eq? ao-device #f) 'error-ao-device-non-existent (let ((r (ao_close ao-device))) @@ -132,12 +150,10 @@ ) )) - ;(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))) (close-device handle ao-device)) ) @@ -166,7 +182,9 @@ (endianess (ao-handle-byte-format handle)) (buf-len (vector-length (car buffer))) (audio-buf-len (* channels bytes-per-sample buf-len)) - (audio (malloc 'atomic audio-buf-len)) + (audio (if (eq? libao-async-mode 'ffi) + (malloc 'atomic audio-buf-len) + (malloc 'raw audio-buf-len))) (get-sample (lambda (k channel) (let ((chan-buf (list-ref buffer channel))) (vector-ref chan-buf k)))) @@ -190,9 +208,16 @@ 'filled)) )) (fill 0 0) - (ao_play_async (ao-handle-async-player handle) (exact->inexact at-time-in-s) - audio-buf-len - audio) + (if (eq? libao-async-mode 'ffi) + (ffi:ao_play_async (ao-handle-async-player handle) + (exact->inexact at-time-in-s) + audio-buf-len + audio) + (scm:ao_play_async (ao-handle-async-player handle) + (exact->inexact at-time-in-s) + audio-buf-len + audio) + ) ) ;(let* ((handle-num (ao-handle-handle-num handle)) ; (ao-device (hash-ref devices handle-num #f))) @@ -203,13 +228,20 @@ ) (define (ao-at-second handle) - (ao_is_at_second_async (ao-handle-async-player handle))) + (if (eq? libao-async-mode 'ffi) + (ffi:ao_is_at_second_async (ao-handle-async-player handle)) + (scm:ao_is_at_second_async (ao-handle-async-player handle)))) (define (ao-bufsize-async handle) - (ao_bufsize_async (ao-handle-async-player handle))) + (if (eq? libao-async-mode 'ffi) + (ffi:ao_bufsize_async (ao-handle-async-player handle)) + (scm:ao_bufsize_async (ao-handle-async-player handle)))) (define (ao-clear-async handle) - (ao_clear_async (ao-handle-async-player handle))) + (if (eq? libao-async-mode 'ffi) + (ffi:ao_clear_async (ao-handle-async-player handle)) + (scm:ao_clear_async (ao-handle-async-player handle)))) + ;(let* ((handle-num (ao-handle-handle-num handle)) ; (ao-device (hash-ref devices handle-num #f)))