more defensive constructs with early-return & let-assert

This commit is contained in:
2026-05-12 11:34:56 +02:00
parent 61d87ba543
commit 89592ddea9
6 changed files with 406 additions and 302 deletions
+13 -5
View File
@@ -33,6 +33,8 @@
ao_sample_queue_len
make-buffer-info
make-BufferInfo_t
ao-playback-buf-ms
ao-set-playback-buf-ms!
)
;; -------------------------------------------------------------------------
@@ -194,7 +196,13 @@
;; Playback buffer to send to libao in milliseconds
;; -------------------------------------------------------------------------
(define ao-buf-ms 1000) ;; Playback buffer of 0.25s
(define ao-buf-ms 350) ;; Playback buffer of 0.35s
(define (ao-playback-buf-ms)
ao-buf-ms)
(define (ao-set-playback-buf-ms! ms)
(set! ao-buf-ms ms))
;; -------------------------------------------------------------------------
;; Sample queue handling
@@ -272,7 +280,7 @@
(reuse-buf h (queue-elem-buf elem))
(when (= (ao-handle-bytes-left h) 0)
(async-channel-put (ao-handle-queue h) cb)
(set-ao-handle-in-queue! h (+ ao-handle-in-queue h) 1)
(set-ao-handle-in-queue! h (+ (ao-handle-in-queue h) 1))
(set-ao-handle-current-elem! h #f))
)
)
@@ -423,8 +431,8 @@
(define (planar-to-interleaved h in-buf info)
;; mem: bytes
;; result: (list bytes output-size)
;; in-buf: mem
;; result: mem
(let* ([in-bytes (mem-bytes in-buf)]
[buf-size (mem-size in-buf)]
@@ -456,7 +464,7 @@
bytes)])
(bytes-copy! out-bytes out-pos in-bytes in-pos (+ in-pos bytes)))))
out out-size)))
out)))
;;; requested bits to device bits