much work on the player and hunting for a bug, which first seemed to be in ffmpeg-decoder, but eventually was found in a race condition in audio-placed-player.rkt and an allocation problem in libao-async-ffi-racket.rkt

This commit is contained in:
2026-05-15 22:11:25 +02:00
parent 3c18e75cf6
commit c9a91bf2be
11 changed files with 534 additions and 340 deletions
+46 -10
View File
@@ -16,8 +16,17 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (ok? r)
(not (= r 0)))
(> r 0))
(define (decode-ok? r)
(= r 1))
(define (decode-eof? r)
(= r 0))
(define (decode-error? r)
(< r 0))
(define (filename->string filename)
(cond
[(path? filename) (path->string filename)]
@@ -149,18 +158,45 @@
(reset!)
#t))
#|
(define (read cb format-cb)
(when (= current-pcm-pos 0)
(ffmpeg-format format-cb))
(if (ok? (fmpg-decode-next! fh))
(let-values ([(buffer size) (copy-current-buffer fh)])
(cond
[(or (eq? buffer #f) (<= size 0)) (read cb format-cb)]
[else
(let ((pcm-pos (fmpg-buffer-start-sample fh)))
(set! current-pcm-pos (fmpg-buffer-end-sample fh))
(cb 'data pcm-pos buffer size))]))
(cb 'done -1 #f 0))
(let ((dec-val (fmpg-decode-next! fh)))
(unless (ok? dec-val)
(err-sound "return value of fmpg-decode-next = ~a" dec-val))
(if (ok? dec-val)
(let-values ([(buffer size) (copy-current-buffer fh)])
(cond
[(or (eq? buffer #f) (<= size 0)) (read cb format-cb)]
[else
(let ((pcm-pos (fmpg-buffer-start-sample fh)))
(set! current-pcm-pos (fmpg-buffer-end-sample fh))
(cb 'data pcm-pos buffer size))]))
(cb 'done -1 #f 0))
#t))
|#
(define (read cb format-cb)
(when (= current-pcm-pos 0)
(ffmpeg-format format-cb))
(let ((dec-val (fmpg-decode-next! fh)))
(cond
[(decode-ok? dec-val)
(let-values ([(buffer size) (copy-current-buffer fh)])
(cond
[(or (eq? buffer #f) (<= size 0))
(read cb format-cb)]
[else
(let ((pcm-pos (fmpg-buffer-start-sample fh)))
(set! current-pcm-pos (fmpg-buffer-end-sample fh))
(cb 'data pcm-pos buffer size))]))]
[(decode-eof? dec-val)
(cb 'done -1 #f 0)]
[else
(err-sound "fmpg-decode-next failed: ~a" dec-val)
(cb 'done -1 #f 0)]))
#t)
(define (seek pcm-pos)